Add a framework target from the existing code, deleting or commenting out code that needs to be removed or updated until it compiles. Nothing works at this stage.

This commit is contained in:
Michael Buckley 2019-07-13 20:42:21 -07:00
parent 931ba0a601
commit 4bd6f30dc8
69 changed files with 10934 additions and 13858 deletions

BIN
macosx/.DS_Store vendored

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
{"guid":"39754f5c7639f1405cb8f271288abde4","name":"snes9x","path":"/Users/buckley/Projects/snes9x/macosx/snes9x.xcodeproj/project.xcworkspace","projects":["PROJECT@v8_mod=1558799895_hash=f7b7d36057c831b92014210ca4e1513f"]}

View File

@ -1 +0,0 @@
{"guid":"39754f5c7639f1405cb8f271288abde4","name":"snes9x","path":"/Users/buckley/Projects/snes9x/macosx/snes9x.xcodeproj/project.xcworkspace","projects":["PROJECT@v8_mod=1558799884_hash=f7b7d36057c831b92014210ca4e1513f"]}

View File

@ -1 +0,0 @@
{"guid":"39754f5c7639f1405cb8f271288abde4","name":"snes9x","path":"/Users/buckley/Projects/snes9x/macosx/snes9x.xcodeproj/project.xcworkspace","projects":["PROJECT@v8_mod=1561939424_hash=f7b7d36057c831b92014210ca4e1513f"]}

View File

@ -1 +0,0 @@
{"guid":"39754f5c7639f1405cb8f271288abde4","name":"snes9x","path":"/Users/buckley/Projects/snes9x/macosx/snes9x.xcodeproj/project.xcworkspace","projects":["PROJECT@v8_mod=1558799815_hash=f7b7d36057c831b92014210ca4e1513f"]}

View File

@ -1 +0,0 @@
{"guid":"39754f5c7639f1405cb8f271288abde4","name":"snes9x","path":"/Users/buckley/Projects/snes9x/macosx/snes9x.xcodeproj/project.xcworkspace","projects":["PROJECT@v8_mod=1558208804_hash=f7b7d36057c831b92014210ca4e1513f"]}

View File

@ -1 +0,0 @@
{"guid":"39754f5c7639f1405cb8f271288abde4","name":"snes9x","path":"/Users/buckley/Projects/snes9x/macosx/snes9x.xcodeproj/project.xcworkspace","projects":["PROJECT@v8_mod=1561940191_hash=f7b7d36057c831b92014210ca4e1513f"]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -44,7 +44,7 @@ static OSErr AEoapp (const AppleEvent *theEvent, AppleEvent *theReply, long refC
if (SNES9X_OpenCart(NULL))
{
SNES9X_Go();
QuitApplicationEventLoop();
//QuitApplicationEventLoop();
}
else
AdjustMenus();
@ -65,7 +65,7 @@ static OSErr AErapp (const AppleEvent *theEvent, AppleEvent *theReply, long refC
if (SNES9X_OpenCart(NULL))
{
SNES9X_Go();
QuitApplicationEventLoop();
//QuitApplicationEventLoop();
}
else
AdjustMenus();
@ -74,7 +74,7 @@ static OSErr AErapp (const AppleEvent *theEvent, AppleEvent *theReply, long refC
else
{
SNES9X_Go();
QuitApplicationEventLoop();
//QuitApplicationEventLoop();
}
return (noErr);
@ -91,70 +91,71 @@ static OSErr AEquit (const AppleEvent *theEvent, AppleEvent *theReply, long refC
return (noErr);
SNES9X_Quit();
QuitApplicationEventLoop();
//QuitApplicationEventLoop();
return (noErr);
}
static OSErr AEodoc (const AppleEvent *theEvent, AppleEvent *theReply, long refCon)
{
OSErr err;
FSRef ref;
AEDescList docList;
AEKeyword keywd;
DescType rtype;
Size acsize;
long count;
if (running)
return (noErr);
err = AEGetParamDesc(theEvent, keyDirectObject, typeAEList, &docList);
if (err)
return (noErr);
err = AECountItems(&docList, &count);
if (err || (count != 1))
{
err = AEDisposeDesc(&docList);
return (noErr);
}
err = AEGetNthPtr(&docList, 1, typeFSRef, &keywd, &rtype, &ref, sizeof(FSRef), &acsize);
if (err == noErr)
{
if (SNES9X_OpenCart(&ref))
{
SNES9X_Go();
QuitApplicationEventLoop();
}
else
AdjustMenus();
}
err = AEDisposeDesc(&docList);
return (noErr);
// OSErr err;
// FSRef ref;
// AEDescList docList;
// AEKeyword keywd;
// DescType rtype;
// Size acsize;
// long count;
//
// if (running)
// return (noErr);
//
// err = AEGetParamDesc(theEvent, keyDirectObject, typeAEList, &docList);
// if (err)
// return (noErr);
//
// err = AECountItems(&docList, &count);
// if (err || (count != 1))
// {
// err = AEDisposeDesc(&docList);
// return (noErr);
// }
//
// err = AEGetNthPtr(&docList, 1, typeFSRef, &keywd, &rtype, &ref, sizeof(FSRef), &acsize);
// if (err == noErr)
// {
// if (SNES9X_OpenCart(&ref))
// {
// SNES9X_Go();
// //QuitApplicationEventLoop();
// }
// else
// AdjustMenus();
// }
//
// err = AEDisposeDesc(&docList);
//
// return (noErr);
return 0;
}
void InitAppleEvents (void)
{
OSErr err;
oappUPP = NewAEEventHandlerUPP(AEoapp);
err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, oappUPP, 0L, false);
odocUPP = NewAEEventHandlerUPP(AEodoc);
err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, odocUPP, 0L, false);
pdocUPP = NewAEEventHandlerUPP(AEpdoc);
err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, pdocUPP, 0L, false);
quitUPP = NewAEEventHandlerUPP(AEquit);
err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, quitUPP, 0L, false);
rappUPP = NewAEEventHandlerUPP(AErapp);
err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, rappUPP, 0L, false);
// OSErr err;
//
// oappUPP = NewAEEventHandlerUPP(AEoapp);
// err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, oappUPP, 0L, false);
//
// odocUPP = NewAEEventHandlerUPP(AEodoc);
// err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, odocUPP, 0L, false);
//
// pdocUPP = NewAEEventHandlerUPP(AEpdoc);
// err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, pdocUPP, 0L, false);
//
// quitUPP = NewAEEventHandlerUPP(AEquit);
// err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, quitUPP, 0L, false);
//
// rappUPP = NewAEEventHandlerUPP(AErapp);
// err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, rappUPP, 0L, false);
}
void DeinitAppleEvents (void)

View File

@ -28,6 +28,5 @@ void DeinitMacSound (void);
void MacStartSound (void);
void MacStopSound (void);
void ConfigureSoundEffects (void);
void PlayAlertSound (void);
#endif

View File

@ -63,12 +63,8 @@ static void SetAudioUnitSoundFormat (void);
static void SetAudioUnitVolume (void);
static void StoreBufferFrameSize (void);
static void ChangeBufferFrameSize (void);
static void ReplaceAudioUnitCarbonView (void);
static void ResizeSoundEffectsDialog (HIViewRef);
static void MacSamplesAvailableCallBack (void *);
static OSStatus MacAURenderCallBack (void *, AudioUnitRenderActionFlags *, const AudioTimeStamp *, UInt32, UInt32, AudioBufferList *);
static OSStatus SoundEffectsEventHandler (EventHandlerCallRef, EventRef, void *);
static OSStatus SoundEffectsCarbonViewEventHandler (EventHandlerCallRef, EventRef, void *);
void InitMacSound (void)
@ -291,12 +287,7 @@ static void ConnectAudioUnits (void)
callback.inputProc = MacAURenderCallBack;
callback.inputProcRefCon = NULL;
if (systemVersion >= 0x1050)
err = AUGraphSetNodeInputCallback(agraph, aueffect ? cnvNode : outNode, 0, &callback);
#ifdef MAC_TIGER_PANTHER_SUPPORT
else
err = AudioUnitSetProperty(aueffect ? cnvAU : outAU, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &callback, sizeof(callback));
#endif
err = AUGraphSetNodeInputCallback(agraph, aueffect ? cnvNode : outNode, 0, &callback);
if ((aueffect & kAUReverb) && (aueffect & kAUGraphEQ))
{
@ -510,445 +501,157 @@ bool8 S9xOpenSoundDevice (void)
return (true);
}
void PlayAlertSound (void)
{
if (systemVersion >= 0x1050)
AudioServicesPlayAlertSound(kUserPreferredAlert);
#ifdef MAC_TIGER_PANTHER_SUPPORT
else
SysBeep(10);
#endif
}
static void ReplaceAudioUnitCarbonView (void)
{
OSStatus err;
AudioUnit editau;
Component cmp;
ComponentDescription desc;
HIViewRef pane, contentview, ctl;
HIViewID cid;
Float32Point location, size;
Rect rct;
UInt32 psize;
if (carbonView)
{
err = RemoveEventHandler(carbonViewEventRef);
DisposeEventHandlerUPP(carbonViewEventUPP);
carbonViewEventRef = NULL;
carbonViewEventUPP = NULL;
CloseComponent(carbonView);
carbonView = NULL;
}
switch (cureffect)
{
case kAUGraphEQ:
editau = eqlAU;
break;
case kAUReverb:
default:
editau = revAU;
break;
}
desc.componentType = kAudioUnitCarbonViewComponentType;
desc.componentSubType = kAUCarbonViewSubType_Generic;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
err = AudioUnitGetPropertyInfo(editau, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global, 0, &psize, NULL);
if (err == noErr)
{
ComponentDescription *editors;
int nEditors;
nEditors = psize / sizeof(ComponentDescription);
editors = new ComponentDescription[nEditors];
err = AudioUnitGetProperty(editau, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global, 0, editors, &psize);
if (err == noErr)
desc = editors[0];
delete [] editors;
}
HIViewFindByID(HIViewGetRoot(effectWRef), kHIViewWindowContentID, &contentview);
cmp = FindNextComponent(NULL, &desc);
if (cmp)
{
err = OpenAComponent(cmp, &carbonView);
if (err == noErr)
{
EventTypeSpec event[] = { { kEventClassControl, kEventControlBoundsChanged } };
GetWindowBounds(effectWRef, kWindowContentRgn, &rct);
location.x = 20;
location.y = 96;
size.x = rct.right - rct.left;
size.y = rct.bottom - rct.top;
err = AudioUnitCarbonViewCreate(carbonView, editau, effectWRef, contentview, &location, &size, &pane);
carbonViewEventUPP = NewEventHandlerUPP(SoundEffectsCarbonViewEventHandler);
err = InstallControlEventHandler(pane, carbonViewEventUPP, GetEventTypeCount(event), event, (void *) effectWRef, &carbonViewEventRef);
ResizeSoundEffectsDialog(pane);
}
else
carbonView = NULL;
}
else
carbonView = NULL;
cid.id = 0;
cid.signature = 'Enab';
HIViewFindByID(contentview, cid, &ctl);
SetControl32BitValue(ctl, (aueffect & cureffect) ? 1 : 0);
}
static void ResizeSoundEffectsDialog (HIViewRef view)
{
OSStatus err;
HIViewRef ctl, root;
HIViewID cid;
HIRect bounds;
Rect rv;
int w, h;
root = HIViewGetRoot(effectWRef);
cid.id = 0;
cid.signature = 'Enab';
HIViewFindByID(root, cid, &ctl);
err = HIViewSetVisible(ctl, false);
err = HIViewSetVisible(view, false);
HIViewGetBounds(view, &bounds);
w = ((int) bounds.size.width + 30 > (int) effectWSize.width) ? ((int) bounds.size.width + 30) : (int) effectWSize.width;
h = (int) bounds.size.height + 122;
#ifdef MAC_PANTHER_SUPPORT
if (systemVersion < 0x1040)
h += 16;
#endif
GetWindowBounds(effectWRef, kWindowStructureRgn, &rv);
rv.right = rv.left + w;
rv.bottom = rv.top + h;
err = TransitionWindow(effectWRef, kWindowSlideTransitionEffect, kWindowResizeTransitionAction, &rv);
err = HIViewSetVisible(ctl, true);
err = HIViewSetVisible(view, true);
#ifdef MAC_PANTHER_SUPPORT
if (systemVersion < 0x1040)
{
HIRect frame;
Rect rct;
GetWindowBounds(effectWRef, kWindowContentRgn, &rv);
cid.signature = 'SfUI';
HIViewFindByID(root, cid, &ctl);
HIViewGetFrame(ctl, &frame);
frame.size.width = (float) (rv.right - rv.left);
HIViewSetFrame(ctl, &frame);
cid.signature = 'LINE';
HIViewFindByID(root, cid, &ctl);
HIViewGetFrame(ctl, &frame);
frame.size.width = (float) (rv.right - rv.left - 24);
HIViewSetFrame(ctl, &frame);
rct.top = 0;
rct.left = 0;
rct.bottom = rv.bottom - rv.top;
rct.right = rv.right - rv.left;
err = InvalWindowRect(effectWRef, &rct);
}
#endif
}
void ConfigureSoundEffects (void)
{
OSStatus err;
IBNibRef nibRef;
err = CreateNibReference(kMacS9XCFString, &nibRef);
if (err == noErr)
{
WindowRef uiparts;
err = CreateWindowFromNib(nibRef, CFSTR("SoundEffect"), &uiparts);
if (err == noErr)
{
EventHandlerUPP eventUPP;
EventHandlerRef eventHandler;
EventTypeSpec event[] = { { kEventClassWindow, kEventWindowClose },
{ kEventClassCommand, kEventCommandProcess },
{ kEventClassCommand, kEventCommandUpdateStatus } };
HIViewRef ctl, userpane, contentview;
HIViewID cid;
CFStringRef str;
Rect rct;
WindowAttributes metal = 0;
cid.id = 0;
cid.signature = 'SfUI';
HIViewFindByID(HIViewGetRoot(uiparts), cid, &userpane);
GetWindowBounds(uiparts, kWindowContentRgn, &rct);
if (systemVersion >= 0x1040) // AUs support compositing
{
HIRect frame;
str = CFCopyLocalizedString(CFSTR("CreateMetalDlg"), "NO");
if (str)
{
if (CFStringCompare(str, CFSTR("YES"), 0) == kCFCompareEqualTo)
metal = kWindowMetalAttribute;
CFRelease(str);
}
frame = CGRectMake(0.0f, 0.0f, (float) (rct.right - rct.left), (float) (rct.bottom - rct.top));
err = CreateNewWindow(kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute | kWindowCompositingAttribute | metal, &rct, &effectWRef);
err = HIViewFindByID(HIViewGetRoot(effectWRef), kHIViewWindowContentID, &contentview);
err = HIViewAddSubview(contentview, userpane);
err = HIViewSetFrame(userpane, &frame);
}
#ifdef MAC_PANTHER_SUPPORT
else
{
err = CreateNewWindow(kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute, &rct, &effectWRef);
err = CreateRootControl(effectWRef, &contentview);
err = EmbedControl(userpane, contentview);
MoveControl(userpane, 0, 0);
}
#endif
CFRelease(uiparts);
if (!metal)
err = SetThemeWindowBackground(effectWRef, kThemeBrushDialogBackgroundActive, false);
str = CFCopyLocalizedString(CFSTR("SoundEffectDlg"), "SoundEffect");
if (str)
{
err = SetWindowTitleWithCFString(effectWRef, str);
CFRelease(str);
}
if (systemVersion >= 0x1040) // AUs support compositing
{
HILayoutInfo layoutinfo;
HIViewRef separator;
cid.signature = 'LINE';
err = HIViewFindByID(userpane, cid, &separator);
layoutinfo.version = kHILayoutInfoVersionZero;
err = HIViewGetLayoutInfo(userpane, &layoutinfo);
layoutinfo.binding.top.toView = contentview;
layoutinfo.binding.top.kind = kHILayoutBindNone;
layoutinfo.binding.bottom.toView = contentview;
layoutinfo.binding.bottom.kind = kHILayoutBindNone;
layoutinfo.binding.left.toView = contentview;
layoutinfo.binding.left.kind = kHILayoutBindLeft;
layoutinfo.binding.right.toView = contentview;
layoutinfo.binding.right.kind = kHILayoutBindRight;
err = HIViewSetLayoutInfo(userpane, &layoutinfo);
layoutinfo.version = kHILayoutInfoVersionZero;
err = HIViewGetLayoutInfo(separator, &layoutinfo);
layoutinfo.binding.top.toView = userpane;
layoutinfo.binding.top.kind = kHILayoutBindNone;
layoutinfo.binding.bottom.toView = userpane;
layoutinfo.binding.bottom.kind = kHILayoutBindNone;
layoutinfo.binding.left.toView = userpane;
layoutinfo.binding.left.kind = kHILayoutBindLeft;
layoutinfo.binding.right.toView = userpane;
layoutinfo.binding.right.kind = kHILayoutBindRight;
err = HIViewSetLayoutInfo(separator, &layoutinfo);
}
eventUPP = NewEventHandlerUPP(SoundEffectsEventHandler);
err = InstallWindowEventHandler(effectWRef, eventUPP, GetEventTypeCount(event), event, (void *) effectWRef, &eventHandler);
GetWindowBounds(effectWRef, kWindowContentRgn, &rct);
effectWSize.width = (float) (rct.right - rct.left);
effectWSize.height = (float) (rct.bottom - rct.top );
carbonView = NULL;
ReplaceAudioUnitCarbonView();
cid.signature = 'Epop';
HIViewFindByID(userpane, cid, &ctl);
switch (cureffect)
{
case kAUReverb:
SetControl32BitValue(ctl, 1);
break;
case kAUGraphEQ:
SetControl32BitValue(ctl, 2);
break;
}
MoveWindowPosition(effectWRef, kWindowSoundEffect, false);
ShowWindow(effectWRef);
err = RunAppModalLoopForWindow(effectWRef);
HideWindow(effectWRef);
SaveWindowPosition(effectWRef, kWindowSoundEffect);
if (carbonView)
{
err = RemoveEventHandler(carbonViewEventRef);
DisposeEventHandlerUPP(carbonViewEventUPP);
carbonViewEventRef = NULL;
carbonViewEventUPP = NULL;
CloseComponent(carbonView);
carbonView = NULL;
}
err = RemoveEventHandler(eventHandler);
DisposeEventHandlerUPP(eventUPP);
CFRelease(effectWRef);
}
DisposeNibReference(nibRef);
}
}
static OSStatus SoundEffectsCarbonViewEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
OSStatus err, result = eventNotHandledErr;
HIViewRef ctl;
HIRect bounds;
switch (GetEventClass(inEvent))
{
case kEventClassControl:
switch (GetEventKind(inEvent))
{
case kEventControlBoundsChanged:
err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &ctl);
if (err == noErr)
{
err = GetEventParameter(inEvent, kEventParamCurrentBounds, typeHIRect, NULL, sizeof(HIRect), NULL, &bounds);
if (err == noErr)
{
if ((bounds.size.width > 0) && (bounds.size.height > 0))
ResizeSoundEffectsDialog(ctl);
}
}
result = noErr;
break;
}
break;
}
return (result);
}
static OSStatus SoundEffectsEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
OSStatus err, result = eventNotHandledErr;
WindowRef tWindowRef = (WindowRef) inUserData;
switch (GetEventClass(inEvent))
{
case kEventClassWindow:
switch (GetEventKind(inEvent))
{
case kEventWindowClose:
QuitAppModalLoopForWindow(tWindowRef);
result = noErr;
break;
}
break;
case kEventClassCommand:
switch (GetEventKind(inEvent))
{
HICommand tHICommand;
case kEventCommandUpdateStatus:
err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
if (err == noErr && tHICommand.commandID == 'clos')
{
UpdateMenuCommandStatus(true);
result = noErr;
}
break;
case kEventCommandProcess:
err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
if (err == noErr)
{
switch (tHICommand.commandID)
{
case 'Enab':
{
Boolean r = false;
mboxPause = true;
err = AUGraphIsRunning(agraph, &r);
if (err == noErr && r)
err = AUGraphStop(agraph);
DisconnectAudioUnits();
err = AUGraphUninitialize(agraph);
aueffect ^= cureffect;
SetAudioUnitSoundFormat();
ChangeBufferFrameSize();
err = AUGraphInitialize(agraph);
ConnectAudioUnits();
if (r)
err = AUGraphStart(agraph);
mboxPause = false;
result = noErr;
break;
}
case 'Revb':
cureffect = kAUReverb;
ReplaceAudioUnitCarbonView();
break;
case 'GrEQ':
cureffect = kAUGraphEQ;
ReplaceAudioUnitCarbonView();
break;
}
}
break;
}
break;
}
return (result);
// OSStatus err;
// IBNibRef nibRef;
//
// err = CreateNibReference(kMacS9XCFString, &nibRef);
// if (err == noErr)
// {
// WindowRef uiparts;
//
// err = CreateWindowFromNib(nibRef, CFSTR("SoundEffect"), &uiparts);
// if (err == noErr)
// {
// EventHandlerUPP eventUPP;
// EventHandlerRef eventHandler;
// EventTypeSpec event[] = { { kEventClassWindow, kEventWindowClose },
// { kEventClassCommand, kEventCommandProcess },
// { kEventClassCommand, kEventCommandUpdateStatus } };
// HIViewRef ctl, userpane, contentview;
// HIViewID cid;
// CFStringRef str;
// Rect rct;
// WindowAttributes metal = 0;
//
// cid.id = 0;
// cid.signature = 'SfUI';
// HIViewFindByID(HIViewGetRoot(uiparts), cid, &userpane);
// GetWindowBounds(uiparts, kWindowContentRgn, &rct);
//
// if (systemVersion >= 0x1040) // AUs support compositing
// {
// HIRect frame;
//
// str = CFCopyLocalizedString(CFSTR("CreateMetalDlg"), "NO");
// if (str)
// {
// if (CFStringCompare(str, CFSTR("YES"), 0) == kCFCompareEqualTo)
// metal = kWindowMetalAttribute;
//
// CFRelease(str);
// }
//
// frame = CGRectMake(0.0f, 0.0f, (float) (rct.right - rct.left), (float) (rct.bottom - rct.top));
// err = CreateNewWindow(kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute | kWindowCompositingAttribute | metal, &rct, &effectWRef);
// err = HIViewFindByID(HIViewGetRoot(effectWRef), kHIViewWindowContentID, &contentview);
// err = HIViewAddSubview(contentview, userpane);
// err = HIViewSetFrame(userpane, &frame);
// }
// #ifdef MAC_PANTHER_SUPPORT
// else
// {
// err = CreateNewWindow(kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute, &rct, &effectWRef);
// err = CreateRootControl(effectWRef, &contentview);
// err = EmbedControl(userpane, contentview);
// MoveControl(userpane, 0, 0);
// }
// #endif
//
// CFRelease(uiparts);
//
// if (!metal)
// err = SetThemeWindowBackground(effectWRef, kThemeBrushDialogBackgroundActive, false);
//
// str = CFCopyLocalizedString(CFSTR("SoundEffectDlg"), "SoundEffect");
// if (str)
// {
// err = SetWindowTitleWithCFString(effectWRef, str);
// CFRelease(str);
// }
//
// if (systemVersion >= 0x1040) // AUs support compositing
// {
// HILayoutInfo layoutinfo;
// HIViewRef separator;
//
// cid.signature = 'LINE';
// err = HIViewFindByID(userpane, cid, &separator);
//
// layoutinfo.version = kHILayoutInfoVersionZero;
// err = HIViewGetLayoutInfo(userpane, &layoutinfo);
//
// layoutinfo.binding.top.toView = contentview;
// layoutinfo.binding.top.kind = kHILayoutBindNone;
// layoutinfo.binding.bottom.toView = contentview;
// layoutinfo.binding.bottom.kind = kHILayoutBindNone;
// layoutinfo.binding.left.toView = contentview;
// layoutinfo.binding.left.kind = kHILayoutBindLeft;
// layoutinfo.binding.right.toView = contentview;
// layoutinfo.binding.right.kind = kHILayoutBindRight;
// err = HIViewSetLayoutInfo(userpane, &layoutinfo);
//
// layoutinfo.version = kHILayoutInfoVersionZero;
// err = HIViewGetLayoutInfo(separator, &layoutinfo);
//
// layoutinfo.binding.top.toView = userpane;
// layoutinfo.binding.top.kind = kHILayoutBindNone;
// layoutinfo.binding.bottom.toView = userpane;
// layoutinfo.binding.bottom.kind = kHILayoutBindNone;
// layoutinfo.binding.left.toView = userpane;
// layoutinfo.binding.left.kind = kHILayoutBindLeft;
// layoutinfo.binding.right.toView = userpane;
// layoutinfo.binding.right.kind = kHILayoutBindRight;
// err = HIViewSetLayoutInfo(separator, &layoutinfo);
// }
//
// eventUPP = NewEventHandlerUPP(SoundEffectsEventHandler);
// err = InstallWindowEventHandler(effectWRef, eventUPP, GetEventTypeCount(event), event, (void *) effectWRef, &eventHandler);
//
// GetWindowBounds(effectWRef, kWindowContentRgn, &rct);
// effectWSize.width = (float) (rct.right - rct.left);
// effectWSize.height = (float) (rct.bottom - rct.top );
//
// carbonView = NULL;
// ReplaceAudioUnitCarbonView();
//
// cid.signature = 'Epop';
// HIViewFindByID(userpane, cid, &ctl);
// switch (cureffect)
// {
// case kAUReverb:
// SetControl32BitValue(ctl, 1);
// break;
//
// case kAUGraphEQ:
// SetControl32BitValue(ctl, 2);
// break;
// }
//
// MoveWindowPosition(effectWRef, kWindowSoundEffect, false);
// ShowWindow(effectWRef);
// err = RunAppModalLoopForWindow(effectWRef);
// HideWindow(effectWRef);
// SaveWindowPosition(effectWRef, kWindowSoundEffect);
//
// if (carbonView)
// {
// err = RemoveEventHandler(carbonViewEventRef);
// DisposeEventHandlerUPP(carbonViewEventUPP);
// carbonViewEventRef = NULL;
// carbonViewEventUPP = NULL;
//
// CloseComponent(carbonView);
// carbonView = NULL;
// }
//
// err = RemoveEventHandler(eventHandler);
// DisposeEventHandlerUPP(eventUPP);
//
// CFRelease(effectWRef);
// }
//
// DisposeNibReference(nibRef);
// }
}

View File

@ -21,15 +21,14 @@
#ifndef _mac_cart_h_
#define _mac_cart_h_
bool8 NavOpenROMImage (FSRef *);
bool8 NavBeginOpenROMImageSheet (WindowRef, CFStringRef);
bool8 NavEndOpenROMImageSheet (FSRef *);
bool8 NavBeginChooseFolderSheet (WindowRef);
bool8 NavEndChooseFolderSheet (FSRef *);
bool8 NavFreezeTo (char *);
bool8 NavDefrostFrom (char *);
bool8 NavRecordMovieTo (char *);
bool8 NavPlayMovieFrom (char *);
bool8 NavQTMovieRecordTo (char *);
#import <Cocoa/Cocoa.h>
NSURL *NavOpenROMImage ();
NSURL *NavChooseFolderSheet (NSWindow *);
NSURL *NavFreezeTo ();
NSURL *NavDefrostFrom ();
NSURL *NavRecordMovieTo ();
NSURL *NavPlayMovieFrom ();
NSURL *NavQTMovieRecordTo ();
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,594 +0,0 @@
/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
/***********************************************************************************
SNES9X for Mac OS (c) Copyright John Stiles
Snes9x for Mac OS X
(c) Copyright 2001 - 2011 zones
(c) Copyright 2002 - 2005 107
(c) Copyright 2002 PB1400c
(c) Copyright 2004 Alexander and Sander
(c) Copyright 2004 - 2005 Steven Seeger
(c) Copyright 2005 Ryan Vogt
***********************************************************************************/
#include "port.h"
#include "cheats.h"
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include "mac-prefix.h"
#include "mac-dialog.h"
#include "mac-os.h"
#include "mac-stringtools.h"
#include "mac-cheat.h"
#define kDataBrowser 'BRSR'
#define kCmCheckBox 'CHK_'
#define kCmAddress 'ADDR'
#define kCmValue 'VALU'
#define kCmDescription 'DESC'
#define kNewButton 'NEW_'
#define kDelButton 'DEL_'
#define kAllButton 'ALL_'
extern SCheatData Cheat;
typedef struct
{
uint32 id;
uint32 address;
uint8 value;
bool8 valid;
bool8 enabled;
char description[22];
} CheatItem;
static WindowRef wRef;
static HIViewRef dbRef;
static CheatItem citem[MAC_MAX_CHEATS];
static uint32 numofcheats;
static void InitCheatItems (void);
static void ImportCheatItems (void);
static void DetachCheatItems (void);
static void AddCheatItem (void);
static void DeleteCheatItem (void);
static void EnableAllCheatItems (void);
static void DBItemNotificationCallBack (HIViewRef, DataBrowserItemID, DataBrowserItemNotification);
static Boolean DBCompareCallBack (HIViewRef, DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID);
static OSStatus DBClientDataCallback (HIViewRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean);
static OSStatus CheatEventHandler (EventHandlerCallRef, EventRef, void *);
static void InitCheatItems (void)
{
for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++)
{
citem[i].id = i + 1;
citem[i].valid = false;
citem[i].enabled = false;
citem[i].address = 0;
citem[i].value = 0;
sprintf(citem[i].description, "Cheat %03" PRIu32, citem[i].id);
}
}
static void ImportCheatItems (void)
{
int cheat_num = std::min((int)Cheat.g.size(), MAC_MAX_CHEATS);
for (unsigned int i = 0; i < cheat_num; i++)
{
citem[i].valid = true;
citem[i].enabled = Cheat.g[i].enabled;
citem[i].address = Cheat.g[i].c[0].address; // mac dialog only supports one cheat per group at the moment
citem[i].value = Cheat.g[i].c[0].byte;
strncpy(citem[i].description, Cheat.g[i].name, 21);
citem[i].description[21] = '\0';
}
}
static void DetachCheatItems (void)
{
S9xDeleteCheats();
for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++)
{
if (citem[i].valid)
{
char code[10];
snprintf(code, 10, "%x=%x", citem[i].address, citem[i].value);
int index = S9xAddCheatGroup(citem[i].description, code);
if(citem[i].enabled && index >= 0)
S9xEnableCheatGroup(index);
}
}
}
void ConfigureCheat (void)
{
if (!cartOpen)
return;
OSStatus err;
IBNibRef nibRef;
err = CreateNibReference(kMacS9XCFString, &nibRef);
if (err == noErr)
{
err = CreateWindowFromNib(nibRef, CFSTR("CheatEntry"), &wRef);
if (err == noErr)
{
DataBrowserCallbacks callbacks;
EventHandlerRef eref;
EventHandlerUPP eUPP;
EventTypeSpec events[] = { { kEventClassCommand, kEventCommandProcess },
{ kEventClassCommand, kEventCommandUpdateStatus },
{ kEventClassWindow, kEventWindowClose } };
HIViewRef ctl, root;
HIViewID cid;
root = HIViewGetRoot(wRef);
cid.id = 0;
cid.signature = kDataBrowser;
HIViewFindByID(root, cid, &dbRef);
#ifdef MAC_PANTHER_SUPPORT
if (systemVersion < 0x1040)
{
HISize minSize;
Rect rct;
GetWindowBounds(wRef, kWindowContentRgn, &rct);
minSize.width = (float) (rct.right - rct.left);
minSize.height = (float) (rct.bottom - rct.top );
err = SetWindowResizeLimits(wRef, &minSize, NULL);
}
#endif
callbacks.version = kDataBrowserLatestCallbacks;
err = InitDataBrowserCallbacks(&callbacks);
callbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP(DBClientDataCallback);
callbacks.u.v1.itemCompareCallback = NewDataBrowserItemCompareUPP(DBCompareCallBack);
callbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP(DBItemNotificationCallBack);
err = SetDataBrowserCallbacks(dbRef, &callbacks);
if (systemVersion >= 0x1040)
err = DataBrowserChangeAttributes(dbRef, kDataBrowserAttributeListViewAlternatingRowColors, kDataBrowserAttributeNone);
InitCheatItems();
ImportCheatItems();
DataBrowserItemID *id;
id = new DataBrowserItemID[MAC_MAX_CHEATS];
if (!id)
QuitWithFatalError(0, "cheat 01");
numofcheats = 0;
for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++)
{
if (citem[i].valid)
{
id[numofcheats] = citem[i].id;
numofcheats++;
}
}
if (numofcheats)
err = AddDataBrowserItems(dbRef, kDataBrowserNoItem, numofcheats, id, kDataBrowserItemNoProperty);
delete [] id;
cid.signature = kNewButton;
HIViewFindByID(root, cid, &ctl);
if (numofcheats == MAC_MAX_CHEATS)
err = DeactivateControl(ctl);
else
err = ActivateControl(ctl);
cid.signature = kAllButton;
HIViewFindByID(root, cid, &ctl);
if (numofcheats == 0)
err = DeactivateControl(ctl);
else
err = ActivateControl(ctl);
cid.signature = kDelButton;
HIViewFindByID(root, cid, &ctl);
err = DeactivateControl(ctl);
eUPP = NewEventHandlerUPP(CheatEventHandler);
err = InstallWindowEventHandler(wRef, eUPP, GetEventTypeCount(events), events, (void *) wRef, &eref);
err = SetKeyboardFocus(wRef, dbRef, kControlFocusNextPart);
MoveWindowPosition(wRef, kWindowCheatEntry, true);
ShowWindow(wRef);
err = RunAppModalLoopForWindow(wRef);
HideWindow(wRef);
SaveWindowPosition(wRef, kWindowCheatEntry);
err = RemoveEventHandler(eref);
DisposeEventHandlerUPP(eUPP);
DisposeDataBrowserItemNotificationUPP(callbacks.u.v1.itemNotificationCallback);
DisposeDataBrowserItemCompareUPP(callbacks.u.v1.itemCompareCallback);
DisposeDataBrowserItemDataUPP(callbacks.u.v1.itemDataCallback);
CFRelease(wRef);
DetachCheatItems();
}
DisposeNibReference(nibRef);
}
}
static void AddCheatItem (void)
{
OSStatus err;
HIViewRef ctl, root;
HIViewID cid;
DataBrowserItemID id[1];
unsigned int i;
if (numofcheats == MAC_MAX_CHEATS)
return;
for (i = 0; i < MAC_MAX_CHEATS; i++)
if (citem[i].valid == false)
break;
if (i == MAC_MAX_CHEATS)
return;
numofcheats++;
citem[i].valid = true;
citem[i].enabled = false;
citem[i].address = 0;
citem[i].value = 0;
sprintf(citem[i].description, "Cheat %03" PRIu32, citem[i].id);
id[0] = citem[i].id;
err = AddDataBrowserItems(dbRef, kDataBrowserNoItem, 1, id, kDataBrowserItemNoProperty);
err = RevealDataBrowserItem(dbRef, id[0], kCmAddress, true);
root = HIViewGetRoot(wRef);
cid.id = 0;
if (numofcheats == MAC_MAX_CHEATS)
{
cid.signature = kNewButton;
HIViewFindByID(root, cid, &ctl);
err = DeactivateControl(ctl);
}
if (numofcheats)
{
cid.signature = kAllButton;
HIViewFindByID(root, cid, &ctl);
err = ActivateControl(ctl);
}
}
static void DeleteCheatItem (void)
{
OSStatus err;
HIViewRef ctl, root;
HIViewID cid;
Handle selectedItems;
ItemCount selectionCount;
selectedItems = NewHandle(0);
if (!selectedItems)
return;
err = GetDataBrowserItems(dbRef, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, selectedItems);
selectionCount = (GetHandleSize(selectedItems) / sizeof(DataBrowserItemID));
if (selectionCount == 0)
{
DisposeHandle(selectedItems);
return;
}
err = RemoveDataBrowserItems(dbRef, kDataBrowserNoItem, selectionCount, (DataBrowserItemID *) *selectedItems, kDataBrowserItemNoProperty);
for (unsigned int i = 0; i < selectionCount; i++)
{
citem[((DataBrowserItemID *) (*selectedItems))[i] - 1].valid = false;
citem[((DataBrowserItemID *) (*selectedItems))[i] - 1].enabled = false;
numofcheats--;
}
DisposeHandle(selectedItems);
root = HIViewGetRoot(wRef);
cid.id = 0;
if (numofcheats < MAC_MAX_CHEATS)
{
cid.signature = kNewButton;
HIViewFindByID(root, cid, &ctl);
err = ActivateControl(ctl);
}
if (numofcheats == 0)
{
cid.signature = kAllButton;
HIViewFindByID(root, cid, &ctl);
err = DeactivateControl(ctl);
}
}
static void EnableAllCheatItems (void)
{
OSStatus err;
for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++)
if (citem[i].valid)
citem[i].enabled = true;
err = UpdateDataBrowserItems(dbRef, kDataBrowserNoItem, kDataBrowserNoItem, NULL, kDataBrowserItemNoProperty, kCmCheckBox);
}
static OSStatus DBClientDataCallback (HIViewRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean changeValue)
{
OSStatus err, result;
CFStringRef str;
Boolean r;
uint32 address;
uint8 value;
char code[256];
result = noErr;
switch (property)
{
case kCmCheckBox:
ThemeButtonValue buttonValue;
if (changeValue)
{
err = GetDataBrowserItemDataButtonValue(itemData, &buttonValue);
citem[itemID - 1].enabled = (buttonValue == kThemeButtonOn) ? true : false;
}
else
err = SetDataBrowserItemDataButtonValue(itemData, citem[itemID - 1].enabled ? kThemeButtonOn : kThemeButtonOff);
break;
case kCmAddress:
if (changeValue)
{
err = GetDataBrowserItemDataText(itemData, &str);
r = CFStringGetCString(str, code, 256, CFStringGetSystemEncoding());
CFRelease(str);
if (r)
{
Boolean translated;
if (S9xProActionReplayToRaw(code, address, value) == NULL)
translated = true;
else
if (S9xGameGenieToRaw(code, address, value) == NULL)
translated = true;
else
{
translated = false;
if (sscanf(code, "%" SCNx32, &address) != 1)
address = 0;
else
address &= 0xFFFFFF;
}
citem[itemID - 1].address = address;
sprintf(code, "%06" PRIX32, address);
str = CFStringCreateWithCString(kCFAllocatorDefault, code, CFStringGetSystemEncoding());
err = SetDataBrowserItemDataText(itemData, str);
CFRelease(str);
if (translated)
{
DataBrowserItemID id[1];
citem[itemID - 1].value = value;
id[0] = itemID;
err = UpdateDataBrowserItems(browser, kDataBrowserNoItem, 1, id, kDataBrowserItemNoProperty, kCmValue);
}
}
}
else
{
sprintf(code, "%06" PRIX32, citem[itemID - 1].address);
str = CFStringCreateWithCString(kCFAllocatorDefault, code, CFStringGetSystemEncoding());
err = SetDataBrowserItemDataText(itemData, str);
CFRelease(str);
}
break;
case kCmValue:
if (changeValue)
{
err = GetDataBrowserItemDataText(itemData, &str);
r = CFStringGetCString(str, code, 256, CFStringGetSystemEncoding());
CFRelease(str);
if (r)
{
uint32 byte;
if (sscanf(code, "%" SCNx32, &byte) == 1)
citem[itemID - 1].value = (uint8) byte;
else
{
citem[itemID - 1].value = 0;
err = SetDataBrowserItemDataText(itemData, CFSTR("00"));
}
}
}
else
{
sprintf(code, "%02" PRIX8, citem[itemID - 1].value);
str = CFStringCreateWithCString(kCFAllocatorDefault, code, CFStringGetSystemEncoding());
err = SetDataBrowserItemDataText(itemData, str);
CFRelease(str);
}
break;
case kCmDescription:
if (changeValue)
{
code[0] = 0;
err = GetDataBrowserItemDataText(itemData, &str);
strcpy(code, GetMultiByteCharacters(str, 19));
CFRelease(str);
if (code[0] == 0)
{
code[0] = ' ';
code[1] = 0;
}
strcpy(citem[itemID - 1].description, code);
}
else
{
str = CFStringCreateWithCString(kCFAllocatorDefault, citem[itemID - 1].description, CFStringGetSystemEncoding());
err = SetDataBrowserItemDataText(itemData, str);
CFRelease(str);
}
break;
case kDataBrowserItemIsActiveProperty:
err = SetDataBrowserItemDataBooleanValue(itemData, true);
break;
case kDataBrowserItemIsEditableProperty:
err = SetDataBrowserItemDataBooleanValue(itemData, true);
break;
default:
result = errDataBrowserPropertyNotSupported;
}
return (result);
}
static Boolean DBCompareCallBack (HIViewRef browser, DataBrowserItemID itemOne, DataBrowserItemID itemTwo, DataBrowserPropertyID sortProperty)
{
Boolean result = false;
switch (sortProperty)
{
case kCmCheckBox:
result = (citem[itemOne - 1].enabled && !(citem[itemTwo - 1].enabled)) ? true : false;
break;
case kCmAddress:
result = (citem[itemOne - 1].address < citem[itemTwo - 1].address) ? true : false;
break;
case kCmValue:
result = (citem[itemOne - 1].value < citem[itemTwo - 1].value) ? true : false;
break;
case kCmDescription:
result = (strcmp(citem[itemOne - 1].description, citem[itemTwo - 1].description) < 0) ? true : false;
}
return (result);
}
static void DBItemNotificationCallBack (HIViewRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message)
{
OSStatus err;
HIViewRef ctl;
HIViewID cid = { kDelButton, 0 };
ItemCount selectionCount;
switch (message)
{
case kDataBrowserSelectionSetChanged:
HIViewFindByID(HIViewGetRoot(wRef), cid, &ctl);
err = GetDataBrowserItemCount(browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, &selectionCount);
if (selectionCount == 0)
err = DeactivateControl(ctl);
else
err = ActivateControl(ctl);
}
}
static OSStatus CheatEventHandler (EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
{
OSStatus err, result = eventNotHandledErr;
WindowRef tWindowRef;
tWindowRef = (WindowRef) inUserData;
switch (GetEventClass(inEvent))
{
case kEventClassWindow:
switch (GetEventKind(inEvent))
{
case kEventWindowClose:
QuitAppModalLoopForWindow(tWindowRef);
result = noErr;
break;
}
break;
case kEventClassCommand:
switch (GetEventKind(inEvent))
{
HICommand tHICommand;
case kEventCommandUpdateStatus:
err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
if (err == noErr && tHICommand.commandID == 'clos')
{
UpdateMenuCommandStatus(true);
result = noErr;
}
break;
case kEventCommandProcess:
err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
if (err == noErr)
{
switch (tHICommand.commandID)
{
case kNewButton:
AddCheatItem();
result = noErr;
break;
case kDelButton:
DeleteCheatItem();
result = noErr;
break;
case kAllButton:
EnableAllCheatItems();
result = noErr;
}
}
}
}
return (result);
}

550
macosx/mac-cheat.mm Executable file
View File

@ -0,0 +1,550 @@
/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
/***********************************************************************************
SNES9X for Mac OS (c) Copyright John Stiles
Snes9x for Mac OS X
(c) Copyright 2001 - 2011 zones
(c) Copyright 2002 - 2005 107
(c) Copyright 2002 PB1400c
(c) Copyright 2004 Alexander and Sander
(c) Copyright 2004 - 2005 Steven Seeger
(c) Copyright 2005 Ryan Vogt
***********************************************************************************/
#include "port.h"
#include "cheats.h"
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include "mac-prefix.h"
#include "mac-dialog.h"
#include "mac-os.h"
#include "mac-stringtools.h"
#include "mac-cheat.h"
#define kDataBrowser 'BRSR'
#define kCmCheckBox 'CHK_'
#define kCmAddress 'ADDR'
#define kCmValue 'VALU'
#define kCmDescription 'DESC'
#define kNewButton 'NEW_'
#define kDelButton 'DEL_'
#define kAllButton 'ALL_'
extern SCheatData Cheat;
typedef struct
{
uint32 id;
uint32 address;
uint8 value;
bool8 valid;
bool8 enabled;
char description[22];
} CheatItem;
static WindowRef wRef;
static HIViewRef dbRef;
static CheatItem citem[MAC_MAX_CHEATS];
static uint32 numofcheats;
static void InitCheatItems (void);
static void ImportCheatItems (void);
static void DetachCheatItems (void);
static void AddCheatItem (void);
static void DeleteCheatItem (void);
static void EnableAllCheatItems (void);
static void DBItemNotificationCallBack (HIViewRef, DataBrowserItemID, DataBrowserItemNotification);
static OSStatus CheatEventHandler (EventHandlerCallRef, EventRef, void *);
static void InitCheatItems (void)
{
for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++)
{
citem[i].id = i + 1;
citem[i].valid = false;
citem[i].enabled = false;
citem[i].address = 0;
citem[i].value = 0;
sprintf(citem[i].description, "Cheat %03" PRIu32, citem[i].id);
}
}
static void ImportCheatItems (void)
{
int cheat_num = std::min((int)Cheat.g.size(), MAC_MAX_CHEATS);
for (unsigned int i = 0; i < cheat_num; i++)
{
citem[i].valid = true;
citem[i].enabled = Cheat.g[i].enabled;
citem[i].address = Cheat.g[i].c[0].address; // mac dialog only supports one cheat per group at the moment
citem[i].value = Cheat.g[i].c[0].byte;
strncpy(citem[i].description, Cheat.g[i].name, 21);
citem[i].description[21] = '\0';
}
}
static void DetachCheatItems (void)
{
S9xDeleteCheats();
for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++)
{
if (citem[i].valid)
{
char code[10];
snprintf(code, 10, "%x=%x", citem[i].address, citem[i].value);
int index = S9xAddCheatGroup(citem[i].description, code);
if(citem[i].enabled && index >= 0)
S9xEnableCheatGroup(index);
}
}
}
void ConfigureCheat (void)
{
if (!cartOpen)
return;
// OSStatus err;
// IBNibRef nibRef;
//
// err = CreateNibReference(kMacS9XCFString, &nibRef);
// if (err == noErr)
// {
// err = CreateWindowFromNib(nibRef, CFSTR("CheatEntry"), &wRef);
// if (err == noErr)
// {
// DataBrowserCallbacks callbacks;
// EventHandlerRef eref;
// EventHandlerUPP eUPP;
// EventTypeSpec events[] = { { kEventClassCommand, kEventCommandProcess },
// { kEventClassCommand, kEventCommandUpdateStatus },
// { kEventClassWindow, kEventWindowClose } };
// HIViewRef ctl, root;
// HIViewID cid;
//
// root = HIViewGetRoot(wRef);
// cid.id = 0;
// cid.signature = kDataBrowser;
// HIViewFindByID(root, cid, &dbRef);
//
// #ifdef MAC_PANTHER_SUPPORT
// if (systemVersion < 0x1040)
// {
// HISize minSize;
// Rect rct;
//
// GetWindowBounds(wRef, kWindowContentRgn, &rct);
// minSize.width = (float) (rct.right - rct.left);
// minSize.height = (float) (rct.bottom - rct.top );
// err = SetWindowResizeLimits(wRef, &minSize, NULL);
// }
// #endif
//
// callbacks.version = kDataBrowserLatestCallbacks;
// err = InitDataBrowserCallbacks(&callbacks);
// callbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP(DBClientDataCallback);
// callbacks.u.v1.itemCompareCallback = NewDataBrowserItemCompareUPP(DBCompareCallBack);
// callbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP(DBItemNotificationCallBack);
// err = SetDataBrowserCallbacks(dbRef, &callbacks);
//
// if (systemVersion >= 0x1040)
// err = DataBrowserChangeAttributes(dbRef, kDataBrowserAttributeListViewAlternatingRowColors, kDataBrowserAttributeNone);
//
// InitCheatItems();
// ImportCheatItems();
//
// DataBrowserItemID *id;
//
// id = new DataBrowserItemID[MAC_MAX_CHEATS];
// if (!id)
// QuitWithFatalError(@"cheat 01");
//
// numofcheats = 0;
//
// for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++)
// {
// if (citem[i].valid)
// {
// id[numofcheats] = citem[i].id;
// numofcheats++;
// }
// }
//
// if (numofcheats)
// err = AddDataBrowserItems(dbRef, kDataBrowserNoItem, numofcheats, id, kDataBrowserItemNoProperty);
//
// delete [] id;
//
// cid.signature = kNewButton;
// HIViewFindByID(root, cid, &ctl);
// if (numofcheats == MAC_MAX_CHEATS)
// err = DeactivateControl(ctl);
// else
// err = ActivateControl(ctl);
//
// cid.signature = kAllButton;
// HIViewFindByID(root, cid, &ctl);
// if (numofcheats == 0)
// err = DeactivateControl(ctl);
// else
// err = ActivateControl(ctl);
//
// cid.signature = kDelButton;
// HIViewFindByID(root, cid, &ctl);
// err = DeactivateControl(ctl);
//
// eUPP = NewEventHandlerUPP(CheatEventHandler);
// err = InstallWindowEventHandler(wRef, eUPP, GetEventTypeCount(events), events, (void *) wRef, &eref);
//
// err = SetKeyboardFocus(wRef, dbRef, kControlFocusNextPart);
//
// MoveWindowPosition(wRef, kWindowCheatEntry, true);
// ShowWindow(wRef);
// err = RunAppModalLoopForWindow(wRef);
// HideWindow(wRef);
// SaveWindowPosition(wRef, kWindowCheatEntry);
//
// err = RemoveEventHandler(eref);
// DisposeEventHandlerUPP(eUPP);
//
// DisposeDataBrowserItemNotificationUPP(callbacks.u.v1.itemNotificationCallback);
// DisposeDataBrowserItemCompareUPP(callbacks.u.v1.itemCompareCallback);
// DisposeDataBrowserItemDataUPP(callbacks.u.v1.itemDataCallback);
//
// CFRelease(wRef);
//
// DetachCheatItems();
// }
//
// DisposeNibReference(nibRef);
// }
}
static void AddCheatItem (void)
{
// OSStatus err;
// HIViewRef ctl, root;
// HIViewID cid;
// DataBrowserItemID id[1];
// unsigned int i;
//
// if (numofcheats == MAC_MAX_CHEATS)
// return;
//
// for (i = 0; i < MAC_MAX_CHEATS; i++)
// if (citem[i].valid == false)
// break;
//
// if (i == MAC_MAX_CHEATS)
// return;
//
// numofcheats++;
// citem[i].valid = true;
// citem[i].enabled = false;
// citem[i].address = 0;
// citem[i].value = 0;
// sprintf(citem[i].description, "Cheat %03" PRIu32, citem[i].id);
//
// id[0] = citem[i].id;
// err = AddDataBrowserItems(dbRef, kDataBrowserNoItem, 1, id, kDataBrowserItemNoProperty);
// err = RevealDataBrowserItem(dbRef, id[0], kCmAddress, true);
//
// root = HIViewGetRoot(wRef);
// cid.id = 0;
//
// if (numofcheats == MAC_MAX_CHEATS)
// {
// cid.signature = kNewButton;
// HIViewFindByID(root, cid, &ctl);
// err = DeactivateControl(ctl);
// }
//
// if (numofcheats)
// {
// cid.signature = kAllButton;
// HIViewFindByID(root, cid, &ctl);
// err = ActivateControl(ctl);
// }
}
static void DeleteCheatItem (void)
{
// OSStatus err;
// HIViewRef ctl, root;
// HIViewID cid;
// Handle selectedItems;
// ItemCount selectionCount;
//
// selectedItems = NewHandle(0);
// if (!selectedItems)
// return;
//
// err = GetDataBrowserItems(dbRef, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, selectedItems);
// selectionCount = (GetHandleSize(selectedItems) / sizeof(DataBrowserItemID));
//
// if (selectionCount == 0)
// {
// DisposeHandle(selectedItems);
// return;
// }
//
// err = RemoveDataBrowserItems(dbRef, kDataBrowserNoItem, selectionCount, (DataBrowserItemID *) *selectedItems, kDataBrowserItemNoProperty);
//
// for (unsigned int i = 0; i < selectionCount; i++)
// {
// citem[((DataBrowserItemID *) (*selectedItems))[i] - 1].valid = false;
// citem[((DataBrowserItemID *) (*selectedItems))[i] - 1].enabled = false;
// numofcheats--;
// }
//
// DisposeHandle(selectedItems);
//
// root = HIViewGetRoot(wRef);
// cid.id = 0;
//
// if (numofcheats < MAC_MAX_CHEATS)
// {
// cid.signature = kNewButton;
// HIViewFindByID(root, cid, &ctl);
// err = ActivateControl(ctl);
// }
//
// if (numofcheats == 0)
// {
// cid.signature = kAllButton;
// HIViewFindByID(root, cid, &ctl);
// err = DeactivateControl(ctl);
// }
}
static void EnableAllCheatItems (void)
{
// OSStatus err;
//
// for (unsigned int i = 0; i < MAC_MAX_CHEATS; i++)
// if (citem[i].valid)
// citem[i].enabled = true;
//
// err = UpdateDataBrowserItems(dbRef, kDataBrowserNoItem, kDataBrowserNoItem, NULL, kDataBrowserItemNoProperty, kCmCheckBox);
}
static OSStatus DBClientDataCallback (HIViewRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean changeValue)
{
// OSStatus err, result;
// CFStringRef str;
// Boolean r;
// uint32 address;
// uint8 value;
// char code[256];
//
// result = noErr;
//
// switch (property)
// {
// case kCmCheckBox:
// ThemeButtonValue buttonValue;
//
// if (changeValue)
// {
// err = GetDataBrowserItemDataButtonValue(itemData, &buttonValue);
// citem[itemID - 1].enabled = (buttonValue == kThemeButtonOn) ? true : false;
// }
// else
// err = SetDataBrowserItemDataButtonValue(itemData, citem[itemID - 1].enabled ? kThemeButtonOn : kThemeButtonOff);
//
// break;
//
// case kCmAddress:
// if (changeValue)
// {
// err = GetDataBrowserItemDataText(itemData, &str);
// r = CFStringGetCString(str, code, 256, CFStringGetSystemEncoding());
// CFRelease(str);
// if (r)
// {
// Boolean translated;
//
// if (S9xProActionReplayToRaw(code, address, value) == NULL)
// translated = true;
// else
// if (S9xGameGenieToRaw(code, address, value) == NULL)
// translated = true;
// else
// {
// translated = false;
// if (sscanf(code, "%" SCNx32, &address) != 1)
// address = 0;
// else
// address &= 0xFFFFFF;
// }
//
// citem[itemID - 1].address = address;
// sprintf(code, "%06" PRIX32, address);
// str = CFStringCreateWithCString(kCFAllocatorDefault, code, CFStringGetSystemEncoding());
// err = SetDataBrowserItemDataText(itemData, str);
// CFRelease(str);
//
// if (translated)
// {
// DataBrowserItemID id[1];
//
// citem[itemID - 1].value = value;
// id[0] = itemID;
// err = UpdateDataBrowserItems(browser, kDataBrowserNoItem, 1, id, kDataBrowserItemNoProperty, kCmValue);
// }
// }
// }
// else
// {
// sprintf(code, "%06" PRIX32, citem[itemID - 1].address);
// str = CFStringCreateWithCString(kCFAllocatorDefault, code, CFStringGetSystemEncoding());
// err = SetDataBrowserItemDataText(itemData, str);
// CFRelease(str);
// }
//
// break;
//
// case kCmValue:
// if (changeValue)
// {
// err = GetDataBrowserItemDataText(itemData, &str);
// r = CFStringGetCString(str, code, 256, CFStringGetSystemEncoding());
// CFRelease(str);
// if (r)
// {
// uint32 byte;
//
// if (sscanf(code, "%" SCNx32, &byte) == 1)
// citem[itemID - 1].value = (uint8) byte;
// else
// {
// citem[itemID - 1].value = 0;
// err = SetDataBrowserItemDataText(itemData, CFSTR("00"));
// }
// }
// }
// else
// {
// sprintf(code, "%02" PRIX8, citem[itemID - 1].value);
// str = CFStringCreateWithCString(kCFAllocatorDefault, code, CFStringGetSystemEncoding());
// err = SetDataBrowserItemDataText(itemData, str);
// CFRelease(str);
// }
//
// break;
//
// case kCmDescription:
// if (changeValue)
// {
// code[0] = 0;
// err = GetDataBrowserItemDataText(itemData, &str);
// strcpy(code, GetMultiByteCharacters(str, 19));
// CFRelease(str);
//
// if (code[0] == 0)
// {
// code[0] = ' ';
// code[1] = 0;
// }
//
// strcpy(citem[itemID - 1].description, code);
// }
// else
// {
// str = CFStringCreateWithCString(kCFAllocatorDefault, citem[itemID - 1].description, CFStringGetSystemEncoding());
// err = SetDataBrowserItemDataText(itemData, str);
// CFRelease(str);
// }
//
// break;
//
// case kDataBrowserItemIsActiveProperty:
// err = SetDataBrowserItemDataBooleanValue(itemData, true);
// break;
//
// case kDataBrowserItemIsEditableProperty:
// err = SetDataBrowserItemDataBooleanValue(itemData, true);
// break;
//
// default:
// result = errDataBrowserPropertyNotSupported;
// }
//
// return (result);
return 0;
}
static OSStatus CheatEventHandler (EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
{
// OSStatus err, result = eventNotHandledErr;
// WindowRef tWindowRef;
//
// tWindowRef = (WindowRef) inUserData;
//
// switch (GetEventClass(inEvent))
// {
// case kEventClassWindow:
// switch (GetEventKind(inEvent))
// {
// case kEventWindowClose:
// QuitAppModalLoopForWindow(tWindowRef);
// result = noErr;
// break;
// }
//
// break;
//
// case kEventClassCommand:
// switch (GetEventKind(inEvent))
// {
// HICommand tHICommand;
//
// case kEventCommandUpdateStatus:
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
// if (err == noErr && tHICommand.commandID == 'clos')
// {
// UpdateMenuCommandStatus(true);
// result = noErr;
// }
//
// break;
//
// case kEventCommandProcess:
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
// if (err == noErr)
// {
// switch (tHICommand.commandID)
// {
// case kNewButton:
// AddCheatItem();
// result = noErr;
// break;
//
// case kDelButton:
// DeleteCheatItem();
// result = noErr;
// break;
//
// case kAllButton:
// EnableAllCheatItems();
// result = noErr;
// }
// }
// }
// }
//
// return (result);
return 0;
}

File diff suppressed because it is too large Load Diff

1236
macosx/mac-cheatfinder.mm Executable file

File diff suppressed because it is too large Load Diff

View File

@ -740,7 +740,7 @@ static bool8 NPClientBeginOpenROMImage (WindowRef window)
replaceAt = CFStringGetIntValue(numRef);
CFStringReplace(mesRef, CFRangeMake(replaceAt - 1, 1), romRef);
r = NavBeginOpenROMImageSheet(window, mesRef);
// r = NavBeginOpenROMImageSheet(window, mesRef);
CFRelease(mesRef);
CFRelease(baseRef);

View File

@ -25,37 +25,34 @@
void CocoaPlayFreezeDefrostSound (void)
{
NSAutoreleasePool *pool;
NSBundle *bundle;
NSString *path;
NSSound *sound;
BOOL r;
pool = [[NSAutoreleasePool alloc] init];
bundle = [NSBundle mainBundle];
path = [bundle pathForSoundResource: @"freeze_defrost"];
if (path)
{
sound = [[NSSound alloc] initWithContentsOfFile: path byReference: YES];
if (sound)
{
r = [sound play];
[sound release];
}
}
[pool release];
@autoreleasepool
{
bundle = [NSBundle mainBundle];
path = [bundle pathForSoundResource: @"freeze_defrost"];
if (path)
{
sound = [[NSSound alloc] initWithContentsOfFile: path byReference: YES];
if (sound)
{
r = [sound play];
}
}
}
}
void CocoaAddStatTextToView (NSView *view, NSString *label, float x, float y, float w, float h, NSTextField **out)
{
NSTextField *control;
control = [[[NSTextField alloc] init] autorelease];
control = [[NSTextField alloc] init];
[[control cell] setControlSize: NSSmallControlSize];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
[[control cell] setControlSize: NSControlSizeSmall];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSControlSizeSmall]]];
[control setStringValue: NSLocalizedString(label, @"")];
[control setBezeled: NO];
[control setDrawsBackground: NO];
@ -73,10 +70,10 @@ void CocoaAddEditTextToView (NSView *view, NSString *label, float x, float y, fl
{
NSTextField *control;
control = [[[NSTextField alloc] init] autorelease];
control = [[NSTextField alloc] init];
[[control cell] setControlSize: NSSmallControlSize];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
[[control cell] setControlSize: NSControlSizeSmall];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSControlSizeSmall]]];
[control setStringValue: NSLocalizedString(label, @"")];
[control setBezeled: YES];
[control setDrawsBackground: YES];
@ -94,13 +91,13 @@ void CocoaAddMPushBtnToView (NSView *view, NSString *label, float x, float y, fl
{
NSButton *control;
control = [[[NSButton alloc] init] autorelease];
control = [[NSButton alloc] init];
[[control cell] setControlSize: NSSmallControlSize];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
[[control cell] setControlSize: NSControlSizeSmall];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSControlSizeSmall]]];
[control setTitle: NSLocalizedString(label, @"")];
[control setBezelStyle: NSRoundedBezelStyle];
[control setButtonType: NSMomentaryPushInButton];
[control setBezelStyle: NSBezelStyleRounded];
[control setButtonType: NSButtonTypeMomentaryPushIn];
[view addSubview: control];
[control setFrame: NSMakeRect(x, y, w, h)];
@ -113,12 +110,12 @@ void CocoaAddCheckBoxToView (NSView *view, NSString *label, float x, float y, fl
{
NSButton *control;
control = [[[NSButton alloc] init] autorelease];
control = [[NSButton alloc] init];
[[control cell] setControlSize: NSSmallControlSize];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
[[control cell] setControlSize: NSControlSizeSmall];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSControlSizeSmall]]];
[control setTitle: NSLocalizedString(label, @"")];
[control setButtonType: NSSwitchButton];
[control setButtonType: NSButtonTypeSwitch];
[view addSubview: control];
[control setFrame: NSMakeRect(x, y, w, h)];
@ -133,7 +130,7 @@ void CocoaAddPopUpBtnToView (NSView *view, NSArray *array, float x, float y, flo
NSMenu *menu;
int n;
menu = [[[NSMenu alloc] init] autorelease];
menu = [[NSMenu alloc] init];
n = [array count];
for (int i = 0; i < n; i++)
@ -145,10 +142,10 @@ void CocoaAddPopUpBtnToView (NSView *view, NSArray *array, float x, float y, flo
[menu addItemWithTitle: item action: NULL keyEquivalent: @""];
}
control = [[[NSPopUpButton alloc] init] autorelease];
control = [[NSPopUpButton alloc] init];
[[control cell] setControlSize: NSSmallControlSize];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
[[control cell] setControlSize: NSControlSizeSmall];
[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSControlSizeSmall]]];
[control setPullsDown: NO];
[control setMenu: menu];

View File

@ -175,56 +175,56 @@ void S9xSetupDefaultKeymap (void)
bool S9xPollButton (uint32 id, bool *pressed)
{
#define kmControlKey 0x3B
KeyMap keys;
GetKeys(keys);
*pressed = false;
if (id & k_MO) // mouse
{
switch (id & 0xFF)
{
case 0: *pressed = ISpKeyIsPressed(kISpMouseL); break;
case 1: *pressed = ISpKeyIsPressed(kISpMouseR);
}
}
else
if (id & k_SS) // superscope
{
switch (id & 0xFF)
{
case 0: *pressed = ISpKeyIsPressed(kISpOffScreen) | KeyIsPressed(keys, keyCode[kKeyOffScreen]); break;
case 2: *pressed = ISpKeyIsPressed(kISpScopeC) | KeyIsPressed(keys, keyCode[kKeyScopeCursor]); break;
case 3: *pressed = ISpKeyIsPressed(kISpScopeT) | KeyIsPressed(keys, keyCode[kKeyScopeTurbo]); break;
case 4: *pressed = ISpKeyIsPressed(kISpScopeP) | KeyIsPressed(keys, keyCode[kKeyScopePause]); break;
case 1: *pressed = ISpKeyIsPressed(kISpMouseL);
}
}
else
if (id & k_LG) // justifier
{
if (id & k_C1)
{
switch (id & 0xFF)
{
case 0: *pressed = ISpKeyIsPressed(kISpOffScreen) | KeyIsPressed(keys, keyCode[kKeyOffScreen]); break;
case 1: *pressed = ISpKeyIsPressed(kISpMouseL); break;
case 2: *pressed = ISpKeyIsPressed(kISpMouseR);
}
}
else
{
switch (id & 0xFF)
{
case 0: *pressed = ISpKeyIsPressed(kISp2PStart) | KeyIsPressed(keys, keyCode[k2PStart]); break;
case 1: *pressed = ISpKeyIsPressed(kISp2PB) | KeyIsPressed(keys, keyCode[k2PB]); break;
case 2: *pressed = ISpKeyIsPressed(kISp2PA) | KeyIsPressed(keys, keyCode[k2PA]);
}
}
}
// #define kmControlKey 0x3B
//
// KeyMap keys;
//
// GetKeys(keys);
//
// *pressed = false;
//
// if (id & k_MO) // mouse
// {
// switch (id & 0xFF)
// {
// case 0: *pressed = ISpKeyIsPressed(kISpMouseL); break;
// case 1: *pressed = ISpKeyIsPressed(kISpMouseR);
// }
// }
// else
// if (id & k_SS) // superscope
// {
// switch (id & 0xFF)
// {
// case 0: *pressed = ISpKeyIsPressed(kISpOffScreen) | KeyIsPressed(keys, keyCode[kKeyOffScreen]); break;
// case 2: *pressed = ISpKeyIsPressed(kISpScopeC) | KeyIsPressed(keys, keyCode[kKeyScopeCursor]); break;
// case 3: *pressed = ISpKeyIsPressed(kISpScopeT) | KeyIsPressed(keys, keyCode[kKeyScopeTurbo]); break;
// case 4: *pressed = ISpKeyIsPressed(kISpScopeP) | KeyIsPressed(keys, keyCode[kKeyScopePause]); break;
// case 1: *pressed = ISpKeyIsPressed(kISpMouseL);
// }
// }
// else
// if (id & k_LG) // justifier
// {
// if (id & k_C1)
// {
// switch (id & 0xFF)
// {
// case 0: *pressed = ISpKeyIsPressed(kISpOffScreen) | KeyIsPressed(keys, keyCode[kKeyOffScreen]); break;
// case 1: *pressed = ISpKeyIsPressed(kISpMouseL); break;
// case 2: *pressed = ISpKeyIsPressed(kISpMouseR);
// }
// }
// else
// {
// switch (id & 0xFF)
// {
// case 0: *pressed = ISpKeyIsPressed(kISp2PStart) | KeyIsPressed(keys, keyCode[k2PStart]); break;
// case 1: *pressed = ISpKeyIsPressed(kISp2PB) | KeyIsPressed(keys, keyCode[k2PB]); break;
// case 2: *pressed = ISpKeyIsPressed(kISp2PA) | KeyIsPressed(keys, keyCode[k2PA]);
// }
// }
// }
return (true);
}

File diff suppressed because it is too large Load Diff

View File

@ -25,8 +25,8 @@ enum
{
kS9xMacAlertFolderNotFound = 1,
kS9xMacAlertFolderNotFoundHint,
kS9xMacAlertFolderFailToCreate,
kS9xMacAlertFolderFailToCreateHint,
kS9xMacAlertFolderNotWritable,
kS9xMacAlertFolderNotWritableHint,
kS9xMacAlertkBadRom,
kS9xMacAlertkBadRomHint,
kS9xMacAlertCFCantAddEntry,

View File

@ -253,7 +253,7 @@ void AppearanceAlert (AlertType type, int stringID1, int stringID2)
if (key1) mes1 = CFCopyLocalizedString(key1, "mes1"); else mes1 = NULL;
if (key2) mes2 = CFCopyLocalizedString(key2, "mes2"); else mes2 = NULL;
PlayAlertSound();
NSBeep();
err = CreateStandardAlert(type, mes1, mes2, NULL, &dialog);
err = RunStandardAlert(dialog, NULL, &outItemHit);

View File

@ -1,619 +0,0 @@
/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
/***********************************************************************************
SNES9X for Mac OS (c) Copyright John Stiles
Snes9x for Mac OS X
(c) Copyright 2001 - 2011 zones
(c) Copyright 2002 - 2005 107
(c) Copyright 2002 PB1400c
(c) Copyright 2004 Alexander and Sander
(c) Copyright 2004 - 2005 Steven Seeger
(c) Copyright 2005 Ryan Vogt
***********************************************************************************/
#include "snes9x.h"
#include "memmap.h"
#include "movie.h"
#include "display.h"
#include <libgen.h>
#include "mac-prefix.h"
#include "mac-dialog.h"
#include "mac-os.h"
#include "mac-stringtools.h"
#include "mac-file.h"
static void AddFolderIcon (FSRef *, const char *);
static OSStatus FindSNESFolder (FSRef *, char *, const char *);
static OSStatus FindApplicationSupportFolder (FSRef *, char *, const char *);
static OSStatus FindCustomFolder (FSRef *, char *, const char *);
void CheckSaveFolder (FSRef *cartRef)
{
OSStatus err;
Boolean r;
FSCatalogInfo finfo;
FSVolumeInfo vinfo;
FSRef ref;
CFURLRef burl, purl;
char s[PATH_MAX + 1];
switch (saveInROMFolder)
{
case 0: // Snes9x folder
burl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
purl = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, burl);
r = CFURLGetFSRef(purl, &ref);
CFRelease(purl);
CFRelease(burl);
break;
case 1: // ROM folder
err = FSGetCatalogInfo(cartRef, kFSCatInfoNone, NULL, NULL, NULL, &ref);
break;
case 2: // Application Support folder
return;
case 4: // Custom folder
if (saveFolderPath == NULL)
{
saveInROMFolder = 2;
return;
}
r = CFStringGetCString(saveFolderPath, s, PATH_MAX, kCFStringEncodingUTF8);
err = FSPathMakeRef((unsigned char *) s, &ref, NULL);
if (err)
{
AppearanceAlert(kAlertCautionAlert, kS9xMacAlertFolderNotFound, kS9xMacAlertFolderNotFoundHint);
saveInROMFolder = 2;
return;
}
break;
}
err = FSGetCatalogInfo(&ref, kFSCatInfoUserPrivs | kFSCatInfoVolume, &finfo, NULL, NULL, NULL);
if (err == noErr)
{
if (finfo.userPrivileges & kioACUserNoMakeChangesMask)
{
AppearanceAlert(kAlertCautionAlert, kS9xMacAlertFolderFailToCreate, kS9xMacAlertFolderFailToCreateHint);
saveInROMFolder = 2;
return;
}
err = FSGetVolumeInfo(finfo.volume, 0, NULL, kFSVolInfoFlags, &vinfo, NULL, NULL);
if (err == noErr)
{
if ((vinfo.flags & kFSVolFlagHardwareLockedMask) || (vinfo.flags & kFSVolFlagSoftwareLockedMask))
{
AppearanceAlert(kAlertCautionAlert, kS9xMacAlertFolderFailToCreate, kS9xMacAlertFolderFailToCreateHint);
saveInROMFolder = 2;
return;
}
}
}
if (err)
saveInROMFolder = 2;
}
static OSStatus FindSNESFolder (FSRef *folderRef, char *folderPath, const char *folderName)
{
OSStatus err;
CFURLRef burl, purl;
CFStringRef fstr;
FSRef pref;
UniChar buffer[PATH_MAX + 1];
Boolean r;
fstr = CFStringCreateWithCString(kCFAllocatorDefault, folderName, CFStringGetSystemEncoding());
CFStringGetCharacters(fstr, CFRangeMake(0, CFStringGetLength(fstr)), buffer);
burl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
purl = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, burl);
r = CFURLGetFSRef(purl, &pref);
err = FSMakeFSRefUnicode(&pref, CFStringGetLength(fstr), buffer, kTextEncodingUnicodeDefault, folderRef);
if (err == dirNFErr || err == fnfErr)
{
err = FSCreateDirectoryUnicode(&pref, CFStringGetLength(fstr), buffer, kFSCatInfoNone, NULL, folderRef, NULL, NULL);
if (err == noErr)
AddFolderIcon(folderRef, folderName);
}
if (err == noErr)
err = FSRefMakePath(folderRef, (unsigned char *) folderPath, PATH_MAX);
CFRelease(purl);
CFRelease(burl);
CFRelease(fstr);
return (err);
}
static OSStatus FindApplicationSupportFolder (FSRef *folderRef, char *folderPath, const char *folderName)
{
OSStatus err;
FSRef p2ref, p1ref;
CFStringRef fstr;
UniChar buffer[PATH_MAX + 1];
UniChar s9xfolder[6] = { 'S', 'n', 'e', 's', '9', 'x' },
oldfolder[6] = { 'S', 'N', 'E', 'S', '9', 'X' };
err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &p2ref);
if (err)
return (err);
err = FSMakeFSRefUnicode(&p2ref, 6, s9xfolder, kTextEncodingUnicodeDefault, &p1ref);
if (err == dirNFErr || err == fnfErr)
{
err = FSMakeFSRefUnicode(&p2ref, 6, oldfolder, kTextEncodingUnicodeDefault, &p1ref);
if (err == dirNFErr || err == fnfErr)
err = FSCreateDirectoryUnicode(&p2ref, 6, s9xfolder, kFSCatInfoNone, NULL, &p1ref, NULL, NULL);
}
if (err)
return (err);
fstr = CFStringCreateWithCString(kCFAllocatorDefault, folderName, CFStringGetSystemEncoding());
CFStringGetCharacters(fstr, CFRangeMake(0, CFStringGetLength(fstr)), buffer);
err = FSMakeFSRefUnicode(&p1ref, CFStringGetLength(fstr), buffer, kTextEncodingUnicodeDefault, folderRef);
if (err == dirNFErr || err == fnfErr)
{
err = FSCreateDirectoryUnicode(&p1ref, CFStringGetLength(fstr), buffer, kFSCatInfoNone, NULL, folderRef, NULL, NULL);
if (err == noErr)
AddFolderIcon(folderRef, folderName);
}
if (err == noErr)
err = FSRefMakePath(folderRef, (unsigned char *) folderPath, PATH_MAX);
CFRelease(fstr);
return (err);
}
static OSStatus FindCustomFolder (FSRef *folderRef, char *folderPath, const char *folderName)
{
OSStatus err;
CFStringRef fstr;
FSRef pref;
UniChar buffer[PATH_MAX + 1];
char s[PATH_MAX + 1];
if (saveFolderPath == NULL)
return (-1);
err = CFStringGetCString(saveFolderPath, s, PATH_MAX, kCFStringEncodingUTF8) ? noErr : -1;
if (err == noErr)
err = FSPathMakeRef((unsigned char *) s, &pref, NULL);
if (err)
return (err);
fstr = CFStringCreateWithCString(kCFAllocatorDefault, folderName, CFStringGetSystemEncoding());
CFStringGetCharacters(fstr, CFRangeMake(0, CFStringGetLength(fstr)), buffer);
err = FSMakeFSRefUnicode(&pref, CFStringGetLength(fstr), buffer, kTextEncodingUnicodeDefault, folderRef);
if (err == dirNFErr || err == fnfErr)
{
err = FSCreateDirectoryUnicode(&pref, CFStringGetLength(fstr), buffer, kFSCatInfoNone, NULL, folderRef, NULL, NULL);
if (err == noErr)
AddFolderIcon(folderRef, folderName);
}
if (err == noErr)
err = FSRefMakePath(folderRef, (unsigned char *) folderPath, PATH_MAX);
CFRelease(fstr);
return (err);
}
void ChangeTypeAndCreator (const char *path, OSType type, OSType creator)
{
OSStatus err;
FSRef ref;
err = FSPathMakeRef((unsigned char *) path, &ref, NULL);
if (err == noErr)
{
FSCatalogInfo catinfo;
err = FSGetCatalogInfo(&ref, kFSCatInfoFinderInfo, &catinfo, NULL, NULL, NULL);
if (err == noErr)
{
((FileInfo *) &catinfo.finderInfo)->fileCreator = creator;
((FileInfo *) &catinfo.finderInfo)->fileType = type;
err = FSSetCatalogInfo(&ref, kFSCatInfoFinderInfo, &catinfo);
}
}
}
static void AddFolderIcon (FSRef *fref, const char *folderName)
{
OSStatus err;
FSCatalogInfo fcat, icat;
FSRef bref, iref;
CFStringRef str;
CFURLRef url;
IconFamilyHandle family;
IconRef icon;
HFSUniStr255 fork;
Boolean r;
SInt16 resf;
char name[64];
UniChar iconName[5] = { 'I', 'c', 'o', 'n', '\r' };
strcpy(name, "folder_");
strcat(name, folderName);
str = CFStringCreateWithCString(kCFAllocatorDefault, name, CFStringGetSystemEncoding());
if (str)
{
url = CFBundleCopyResourceURL(CFBundleGetMainBundle(), str, CFSTR("icns"), NULL);
if (url)
{
r = CFURLGetFSRef(url, &bref);
if (r)
{
err = RegisterIconRefFromFSRef('~9X~', 'TEMP', &bref, &icon);
if (err == noErr)
{
err = FSGetResourceForkName(&fork);
if (err == noErr)
{
err = FSCreateResourceFile(fref, 5, iconName, kFSCatInfoNone, NULL, fork.length, fork.unicode, &iref, NULL);
if (err == noErr)
{
err = FSOpenResourceFile(&iref, fork.length, fork.unicode, fsWrPerm, &resf);
if (err == noErr)
{
err = IconRefToIconFamily(icon, kSelectorAllAvailableData, &family);
if (err == noErr)
{
AddResource((Handle) family, 'icns', -16455, "\p");
WriteResource((Handle) family);
ReleaseResource((Handle) family);
err = FSGetCatalogInfo(&iref, kFSCatInfoFinderInfo, &icat, NULL, NULL, NULL);
((FileInfo *) &icat.finderInfo)->finderFlags |= kIsInvisible;
((FileInfo *) &icat.finderInfo)->fileCreator = 'MACS';
((FileInfo *) &icat.finderInfo)->fileType = 'icon';
err = FSSetCatalogInfo(&iref, kFSCatInfoFinderInfo, &icat);
err = FSGetCatalogInfo(fref, kFSCatInfoFinderInfo, &fcat, NULL, NULL, NULL);
((FolderInfo *) &fcat.finderInfo)->finderFlags |= kHasCustomIcon;
((FolderInfo *) &fcat.finderInfo)->finderFlags &= ~kHasBeenInited;
err = FSSetCatalogInfo(fref, kFSCatInfoFinderInfo, &fcat);
}
CloseResFile(resf);
}
}
}
err = UnregisterIconRef('~9X~', 'TEMP');
}
}
CFRelease(url);
}
CFRelease(str);
}
}
const char * S9xGetFilename (const char *inExt, enum s9x_getdirtype dirtype)
{
static int index = 0;
static char filePath[4][PATH_MAX + 1];
OSStatus err;
FSRef ref;
uint32 type;
char folderName[16];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
const char *p;
index++;
if (index > 3)
index = 0;
folderName[0] = filePath[index][0] = 0;
if (strlen(inExt) < 4)
return (filePath[index]);
p = inExt + strlen(inExt) - 4;
type = ((uint32) p[0] << 24) + ((uint32) p[1] << 16) + ((uint32) p[2] << 8) + (uint32) p[3];
switch (type)
{
case '.srm':
case '.rtc':
strcpy(folderName, "SRAMs");
break;
case '.frz':
strcpy(folderName, "Freezes");
break;
case '.spc':
strcpy(folderName, "SPCs");
break;
case '.cht':
strcpy(folderName, "Cheats");
break;
case '.ups':
case '.ips':
strcpy(folderName, "Patches");
break;
case '.png':
strcpy(folderName, "Screenshots");
break;
case '.dat':
case '.out':
case '.log':
strcpy(folderName, "Logs");
break;
case '.bio': // dummy
strcpy(folderName, "BIOSes");
break;
}
if (folderName[0] && (saveInROMFolder != 1))
{
char s[PATH_MAX + 1];
s[0] = 0;
err = -1;
if (saveInROMFolder == 0)
{
err = FindSNESFolder(&ref, s, folderName);
if (err)
saveInROMFolder = 2;
}
if (saveInROMFolder == 4)
{
err = FindCustomFolder(&ref, s, folderName);
if (err)
saveInROMFolder = 2;
}
if (saveInROMFolder == 2)
err = FindApplicationSupportFolder(&ref, s, folderName);
if (err == noErr)
{
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
snprintf(filePath[index], PATH_MAX + 1, "%s%s%s%s", s, MAC_PATH_SEPARATOR, fname, inExt);
}
else
{
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
_makepath(filePath[index], drive, dir, fname, inExt);
}
}
else
{
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
_makepath(filePath[index], drive, dir, fname, inExt);
}
return (filePath[index]);
}
const char * S9xGetSPCFilename (void)
{
char spcExt[16];
sprintf(spcExt, ".%03d.spc", (int) spcFileCount);
spcFileCount++;
if (spcFileCount == 1000)
spcFileCount = 0;
return (S9xGetFilename(spcExt, SPC_DIR));
}
const char * S9xGetPNGFilename (void)
{
char pngExt[16];
sprintf(pngExt, ".%03d.png", (int) pngFileCount);
pngFileCount++;
if (pngFileCount == 1000)
pngFileCount = 0;
return (S9xGetFilename(pngExt, SCREENSHOT_DIR));
}
const char * S9xGetFreezeFilename (int which)
{
char frzExt[16];
sprintf(frzExt, ".%03d.frz", which);
return (S9xGetFilename(frzExt, SNAPSHOT_DIR));
}
const char * S9xGetFilenameInc (const char *inExt, enum s9x_getdirtype dirtype)
{
uint32 type;
const char *p;
if (strlen(inExt) < 4)
return (NULL);
p = inExt + strlen(inExt) - 4;
type = ((uint32) p[0] << 24) + ((uint32) p[1] << 16) + ((uint32) p[2] << 8) + (uint32) p[3];
switch (type)
{
case '.spc':
return (S9xGetSPCFilename());
case '.png':
return (S9xGetPNGFilename());
}
return (NULL);
}
const char * S9xChooseFilename (bool8 read_only)
{
return (NULL);
}
const char * S9xChooseMovieFilename (bool8 read_only)
{
return (NULL);
}
bool8 S9xOpenSnapshotFile (const char *fname, bool8 read_only, STREAM *file)
{
if (read_only)
{
if (0 != (*file = OPEN_STREAM(fname, "rb")))
return (true);
}
else
{
if (0 != (*file = OPEN_STREAM(fname, "wb")))
return (true);
}
return (false);
}
void S9xCloseSnapshotFile (STREAM file)
{
CLOSE_STREAM(file);
}
const char * S9xBasename (const char *in)
{
static char s[PATH_MAX + 1];
strncpy(s, in, PATH_MAX + 1);
s[PATH_MAX] = 0;
size_t l = strlen(s);
for (unsigned int i = 0; i < l; i++)
{
if (s[i] < 32 || s[i] >= 127)
s[i] = '_';
}
return (basename(s));
}
const char * S9xGetDirectory (enum s9x_getdirtype dirtype)
{
static int index = 0;
static char path[4][PATH_MAX + 1];
char inExt[16];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
index++;
if (index > 3)
index = 0;
switch (dirtype)
{
case SNAPSHOT_DIR: strcpy(inExt, ".frz"); break;
case SRAM_DIR: strcpy(inExt, ".srm"); break;
case SCREENSHOT_DIR: strcpy(inExt, ".png"); break;
case SPC_DIR: strcpy(inExt, ".spc"); break;
case CHEAT_DIR: strcpy(inExt, ".cht"); break;
case BIOS_DIR: strcpy(inExt, ".bio"); break;
case LOG_DIR: strcpy(inExt, ".log"); break;
default: strcpy(inExt, ".xxx"); break;
}
_splitpath(S9xGetFilename(inExt, dirtype), drive, dir, fname, ext);
_makepath(path[index], drive, dir, "", "");
int l = strlen(path[index]);
if (l > 1)
path[index][l - 1] = 0;
return (path[index]);
}
void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
{
drive[0] = 0;
fname[0] = 0;
ext[0] = 0;
dir[0] = 0;
int x;
x = strlen(path) - 1;
if (x < 0)
return;
while (x && (path[x] != MAC_PATH_SEP_CHAR))
x--;
if (x)
{
strcpy(dir, path);
dir[x + 1] = 0;
strcpy(fname, path + x + 1);
}
else
strcpy(fname, path);
x = strlen(fname);
while (x && (fname[x] != '.'))
x--;
if (x)
{
strcpy(ext, fname + x);
fname[x] = 0;
}
}
void _makepath (char *path, const char *drive, const char *dir, const char *fname, const char *ext)
{
static const char emp[] = "", dot[] = ".";
const char *d, *f, *e, *p;
d = dir ? dir : emp;
f = fname ? fname : emp;
e = ext ? ext : emp;
p = (e[0] && e[0] != '.') ? dot : emp;
snprintf(path, PATH_MAX + 1, "%s%s%s%s", d, f, p, e);
}

View File

@ -21,7 +21,7 @@
#ifndef _mac_file_h_
#define _mac_file_h_
void CheckSaveFolder (FSRef *);
void CheckSaveFolder (NSURL *);
void ChangeTypeAndCreator (const char *, OSType, OSType);
const char * S9xGetSPCFilename (void);
const char * S9xGetPNGFilename (void);

504
macosx/mac-file.mm Normal file
View File

@ -0,0 +1,504 @@
/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
/***********************************************************************************
SNES9X for Mac OS (c) Copyright John Stiles
Snes9x for Mac OS X
(c) Copyright 2001 - 2011 zones
(c) Copyright 2002 - 2005 107
(c) Copyright 2002 PB1400c
(c) Copyright 2004 Alexander and Sander
(c) Copyright 2004 - 2005 Steven Seeger
(c) Copyright 2005 Ryan Vogt
***********************************************************************************/
#import <Cocoa/Cocoa.h>
#include "snes9x.h"
#include "memmap.h"
#include "movie.h"
#include "display.h"
#include <libgen.h>
#include "mac-prefix.h"
#include "mac-dialog.h"
#include "mac-os.h"
#include "mac-stringtools.h"
#include "mac-file.h"
static void AddFolderIcon (NSURL *, const char *);
static NSURL *FindSNESFolder (const char *);
static NSURL *FindApplicationSupportFolder (NSURL *, const char *);
static NSURL *FindCustomFolder (NSURL *, const char *);
void CheckSaveFolder (NSURL *cartURL)
{
NSString *folderPath = nil;
switch (saveInROMFolder)
{
case 1: // ROM folder
folderPath = cartURL.URLByDeletingLastPathComponent.path;
break;
case 2: // Application Support folder
return;
case 4: // Custom folder
if (saveFolderPath == NULL)
{
saveInROMFolder = 2;
return;
}
BOOL isDirectory = NO;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:saveFolderPath isDirectory:&isDirectory];
if (exists && isDirectory)
{
folderPath = saveFolderPath;
}
else
{
//AppearanceAlert(kAlertCautionAlert, kS9xMacAlertFolderNotFound, kS9xMacAlertFolderNotFoundHint);
saveInROMFolder = 2;
return;
}
break;
}
BOOL writable = [[NSFileManager defaultManager] isWritableFileAtPath:folderPath];
if (!writable)
{
//AppearanceAlert(kAlertCautionAlert, kS9xMacAlertFolderNotWritable, kS9xMacAlertFolderNotWritableHint);
saveInROMFolder = 2;
return;
}
}
static NSURL *FindSNESFolder (const char *folderName)
{
NSURL *purl = nil;
NSString *fstr = [NSString stringWithUTF8String:folderName];
purl = [[[NSBundle mainBundle] bundleURL].URLByDeletingLastPathComponent URLByAppendingPathComponent:fstr];
if (![NSFileManager.defaultManager fileExistsAtPath:purl.path])
{
NSError *error = nil;
if ( [NSFileManager.defaultManager createDirectoryAtURL:purl withIntermediateDirectories:YES attributes:nil error:&error] )
{
AddFolderIcon(purl, folderName);
}
else
{
[[NSAlert alertWithError:error] runModal];
}
}
return purl;
}
static NSURL *FindApplicationSupportFolder (const char *folderName)
{
NSURL *purl = nil;
NSURL *baseURL = nil;
NSURL *s9xURL = nil;
NSURL *oldURL = nil;
NSString *fstr = [NSString stringWithUTF8String:folderName];
baseURL = [[NSFileManager.defaultManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask].firstObject URLByAppendingPathComponent:fstr];
if (!baseURL)
{
return nil;
}
s9xURL = [baseURL URLByAppendingPathComponent:@"Snes9x"];
oldURL = [baseURL URLByAppendingPathComponent:@"SNES9X"];
if ([NSFileManager.defaultManager fileExistsAtPath:s9xURL.path])
{
purl = s9xURL;
}
else
{
if ([NSFileManager.defaultManager fileExistsAtPath:oldURL.path])
{
purl = oldURL;
}
else
{
NSError *error = nil;
if ([NSFileManager.defaultManager createDirectoryAtURL:s9xURL withIntermediateDirectories:YES attributes:nil error:&error])
{
purl = s9xURL;
AddFolderIcon(purl, folderName);
}
}
}
return purl;
}
static NSURL *FindCustomFolder (const char *folderName)
{
NSURL *purl = nil;
if (saveFolderPath == NULL)
return nil;
purl = [NSURL fileURLWithPath:saveFolderPath];
if (![NSFileManager.defaultManager fileExistsAtPath:saveFolderPath])
{
NSError *error = nil;
if (![NSFileManager.defaultManager createDirectoryAtPath:saveFolderPath withIntermediateDirectories:YES attributes:nil error:&error])
{
[[NSAlert alertWithError:error] runModal];
return nil;
}
}
purl = [purl URLByAppendingPathComponent:[NSString stringWithUTF8String:folderName]];
if (![NSFileManager.defaultManager fileExistsAtPath:purl.path])
{
NSError *error = nil;
if ([NSFileManager.defaultManager createDirectoryAtPath:saveFolderPath withIntermediateDirectories:YES attributes:nil error:&error])
{
AddFolderIcon(purl, folderName);
}
{
[[NSAlert alertWithError:error] runModal];
return nil;
}
}
return purl;
}
void ChangeTypeAndCreator (const char *path, OSType type, OSType creator)
{
NSError *error = nil;
if (![NSFileManager.defaultManager setAttributes:@{NSFileHFSCreatorCode: @(creator), NSFileHFSTypeCode: @(type)} ofItemAtPath:[NSString stringWithUTF8String:path] error:&error])
{
[[NSAlert alertWithError:error] runModal];
}
}
static void AddFolderIcon (NSURL *fref, const char *folderName)
{
NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.snes9x.macos.snes9x-framework"];
NSString *filename = [@"folder_" stringByAppendingString:[NSString stringWithUTF8String:folderName]];
NSURL *imageURL = [bundle URLForResource:filename withExtension:@"icns"];
NSImage *image = [[NSImage alloc] initWithContentsOfURL:imageURL];
if ( image != nil )
{
[NSWorkspace.sharedWorkspace setIcon:image forFile:fref.path options:0];
}
}
const char * S9xGetFilename (const char *inExt, enum s9x_getdirtype dirtype)
{
static int index = 0;
static char filePath[4][PATH_MAX + 1];
uint32 type;
char folderName[16];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
const char *p;
index++;
if (index > 3)
index = 0;
folderName[0] = filePath[index][0] = 0;
if (strlen(inExt) < 4)
return (filePath[index]);
p = inExt + strlen(inExt) - 4;
type = ((uint32) p[0] << 24) + ((uint32) p[1] << 16) + ((uint32) p[2] << 8) + (uint32) p[3];
switch (type)
{
case '.srm':
case '.rtc':
strcpy(folderName, "SRAMs");
break;
case '.frz':
strcpy(folderName, "Freezes");
break;
case '.spc':
strcpy(folderName, "SPCs");
break;
case '.cht':
strcpy(folderName, "Cheats");
break;
case '.ups':
case '.ips':
strcpy(folderName, "Patches");
break;
case '.png':
strcpy(folderName, "Screenshots");
break;
case '.dat':
case '.out':
case '.log':
strcpy(folderName, "Logs");
break;
case '.bio': // dummy
strcpy(folderName, "BIOSes");
break;
}
if (folderName[0] && (saveInROMFolder != 1))
{
NSURL *folderURL = nil;
if (saveInROMFolder == 0)
{
folderURL = FindSNESFolder(folderName);
if (folderURL == nil)
saveInROMFolder = 2;
}
if (saveInROMFolder == 4)
{
folderURL = FindCustomFolder(folderName);
if (folderURL == nil)
saveInROMFolder = 2;
}
if (saveInROMFolder == 2)
folderURL = FindApplicationSupportFolder(folderName);
if (folderURL != nil)
{
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
snprintf(filePath[index], PATH_MAX + 1, "%s%s%s%s", folderURL.path.UTF8String, MAC_PATH_SEPARATOR, fname, inExt);
}
else
{
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
_makepath(filePath[index], drive, dir, fname, inExt);
}
}
else
{
_splitpath(Memory.ROMFilename, drive, dir, fname, ext);
_makepath(filePath[index], drive, dir, fname, inExt);
}
return (filePath[index]);
}
const char * S9xGetSPCFilename (void)
{
char spcExt[16];
sprintf(spcExt, ".%03d.spc", (int) spcFileCount);
spcFileCount++;
if (spcFileCount == 1000)
spcFileCount = 0;
return (S9xGetFilename(spcExt, SPC_DIR));
}
const char * S9xGetPNGFilename (void)
{
char pngExt[16];
sprintf(pngExt, ".%03d.png", (int) pngFileCount);
pngFileCount++;
if (pngFileCount == 1000)
pngFileCount = 0;
return (S9xGetFilename(pngExt, SCREENSHOT_DIR));
}
const char * S9xGetFreezeFilename (int which)
{
char frzExt[16];
sprintf(frzExt, ".%03d.frz", which);
return (S9xGetFilename(frzExt, SNAPSHOT_DIR));
}
const char * S9xGetFilenameInc (const char *inExt, enum s9x_getdirtype dirtype)
{
uint32 type;
const char *p;
if (strlen(inExt) < 4)
return (NULL);
p = inExt + strlen(inExt) - 4;
type = ((uint32) p[0] << 24) + ((uint32) p[1] << 16) + ((uint32) p[2] << 8) + (uint32) p[3];
switch (type)
{
case '.spc':
return (S9xGetSPCFilename());
case '.png':
return (S9xGetPNGFilename());
}
return (NULL);
}
const char * S9xChooseFilename (bool8 read_only)
{
return (NULL);
}
const char * S9xChooseMovieFilename (bool8 read_only)
{
return (NULL);
}
bool8 S9xOpenSnapshotFile (const char *fname, bool8 read_only, STREAM *file)
{
if (read_only)
{
if (0 != (*file = OPEN_STREAM(fname, "rb")))
return (true);
}
else
{
if (0 != (*file = OPEN_STREAM(fname, "wb")))
return (true);
}
return (false);
}
void S9xCloseSnapshotFile (STREAM file)
{
CLOSE_STREAM(file);
}
const char * S9xBasename (const char *in)
{
static char s[PATH_MAX + 1];
strncpy(s, in, PATH_MAX + 1);
s[PATH_MAX] = 0;
size_t l = strlen(s);
for (unsigned int i = 0; i < l; i++)
{
if (s[i] < 32 || s[i] >= 127)
s[i] = '_';
}
return (basename(s));
}
const char * S9xGetDirectory (enum s9x_getdirtype dirtype)
{
static int index = 0;
static char path[4][PATH_MAX + 1];
char inExt[16];
char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], fname[_MAX_FNAME + 1], ext[_MAX_EXT + 1];
index++;
if (index > 3)
index = 0;
switch (dirtype)
{
case SNAPSHOT_DIR: strcpy(inExt, ".frz"); break;
case SRAM_DIR: strcpy(inExt, ".srm"); break;
case SCREENSHOT_DIR: strcpy(inExt, ".png"); break;
case SPC_DIR: strcpy(inExt, ".spc"); break;
case CHEAT_DIR: strcpy(inExt, ".cht"); break;
case BIOS_DIR: strcpy(inExt, ".bio"); break;
case LOG_DIR: strcpy(inExt, ".log"); break;
default: strcpy(inExt, ".xxx"); break;
}
_splitpath(S9xGetFilename(inExt, dirtype), drive, dir, fname, ext);
_makepath(path[index], drive, dir, "", "");
size_t l = strlen(path[index]);
if (l > 1)
path[index][l - 1] = 0;
return (path[index]);
}
void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
{
drive[0] = 0;
fname[0] = 0;
ext[0] = 0;
dir[0] = 0;
size_t x;
x = strlen(path) - 1;
if (x < 0)
return;
while (x && (path[x] != MAC_PATH_SEP_CHAR))
x--;
if (x)
{
strcpy(dir, path);
dir[x + 1] = 0;
strcpy(fname, path + x + 1);
}
else
strcpy(fname, path);
x = strlen(fname);
while (x && (fname[x] != '.'))
x--;
if (x)
{
strcpy(ext, fname + x);
fname[x] = 0;
}
}
void _makepath (char *path, const char *drive, const char *dir, const char *fname, const char *ext)
{
static const char emp[] = "", dot[] = ".";
const char *d, *f, *e, *p;
d = dir ? dir : emp;
f = fname ? fname : emp;
e = ext ? ext : emp;
p = (e[0] && e[0] != '.') ? dot : emp;
snprintf(path, PATH_MAX + 1, "%s%s%s%s", d, f, p, e);
}

View File

@ -57,12 +57,7 @@ void DrawSubCGImage (CGContextRef ctx, CGImageRef image, CGRect src, CGRect dst)
static void SetIconImage (CGImageRef image, CGRect rct, int n)
{
if (systemVersion >= 0x1040)
macIconImage[n] = CGImageCreateWithImageInRect(image, rct);
#ifdef MAC_PANTHER_SUPPORT
else
macIconRef[n] = CreateIconRefFromImage(image, rct);
#endif
macIconImage[n] = CGImageCreateWithImageInRect(image, rct);
}
void CreateIconImages (void)
@ -160,18 +155,8 @@ void ReleaseIconImages (void)
{
for (int i = 0; i < 118; i++)
{
if (systemVersion >= 0x1040)
{
if (macIconImage[i])
CGImageRelease(macIconImage[i]);
}
#ifdef MAC_PANTHER_SUPPORT
else
{
if (macIconRef[i])
ReleaseIconRef(macIconRef[i]);
}
#endif
if (macIconImage[i])
CGImageRelease(macIconImage[i]);
}
#ifdef MAC_PANTHER_SUPPORT

File diff suppressed because it is too large Load Diff

View File

@ -158,7 +158,7 @@ enum
void SetUpHID (void);
void ReleaseHID (void);
void ConfigureHID (void);
//void ConfigureHID (void);
void ClearPadSetting (void);
void SaveControllerSettings (void);
void LoadControllerSettings (void);

1149
macosx/mac-joypad.mm Executable file

File diff suppressed because it is too large Load Diff

View File

@ -308,101 +308,101 @@ static OSStatus KeyLayoutEventHandler (EventHandlerCallRef, EventRef, void *);
void ConfigureKeyboard (void)
{
OSStatus err;
IBNibRef nibRef;
err = CreateNibReference(kMacS9XCFString, &nibRef);
if (err == noErr)
{
WindowRef tWindowRef;
err = CreateWindowFromNib(nibRef, CFSTR("Keyboard"), &tWindowRef);
if (err == noErr)
{
EventHandlerRef wref, iref1, iref2;
EventHandlerUPP wUPP, iUPP;
EventTypeSpec wEvents[] = { { kEventClassWindow, kEventWindowClose },
{ kEventClassCommand, kEventCommandProcess },
{ kEventClassCommand, kEventCommandUpdateStatus } },
cEvents[] = { { kEventClassHIObject, kEventHIObjectConstruct },
{ kEventClassHIObject, kEventHIObjectDestruct },
{ kEventClassHIObject, kEventHIObjectInitialize },
{ kEventClassControl, kEventControlDraw },
{ kEventClassControl, kEventControlHitTest },
{ kEventClassControl, kEventControlTrack } },
iEvents[] = { { kEventClassControl, kEventControlDraw } };
HIObjectRef hiObject;
HIViewRef contentView, image1, image2;
HIViewID cid;
HIRect frame;
Rect winBounds;
UpdateIconPlaceImage();
keyInDrag = false;
dragKey = -1;
dragKeyOfs = CGPointMake(0.0f, 0.0f);
dragKeyRect = CGRectMake(0.0f, 0.0f, 0.0f, 0.0f);
mousePos = CGPointMake(0.0f, 0.0f);
err = noErr;
if (theClass == NULL)
err = HIObjectRegisterSubclass(kCustomLayoutViewClassID, kHIViewClassID, 0, KeyLayoutEventHandler, GetEventTypeCount(cEvents), cEvents, NULL, &theClass);
if (err == noErr)
{
err = HIObjectCreate(kCustomLayoutViewClassID, NULL, &hiObject);
if (err == noErr)
{
GetWindowBounds(tWindowRef, kWindowContentRgn, &winBounds);
frame.origin.x = 2.0f;
frame.origin.y = 2.0f;
frame.size.width = (float) (winBounds.right - winBounds.left) - 4.0f;
frame.size.height = (float) kKeyLayoutHeight + 36.0f;
ofsx = (float) (((int) frame.size.width - kKeyLayoutWidth ) >> 1) + 1.0f;
ofsy = (float) (((int) frame.size.height - kKeyLayoutHeight) >> 1) + 1.0f;
customView = (HIViewRef) hiObject;
HIViewFindByID(HIViewGetRoot(tWindowRef), kHIViewWindowContentID, &contentView);
HIViewAddSubview(contentView, customView);
HIViewSetFrame(customView, &frame);
HIViewSetVisible(customView, true);
cid.signature = 'Lgnd';
cid.id = 0;
HIViewFindByID(contentView, cid, &image1);
cid.id = 1;
HIViewFindByID(contentView, cid, &image2);
iUPP = NewEventHandlerUPP(KeyLegendEventHandler);
err = InstallControlEventHandler(image1, iUPP, GetEventTypeCount(iEvents), iEvents, (void *) image1, &iref1);
err = InstallControlEventHandler(image2, iUPP, GetEventTypeCount(iEvents), iEvents, (void *) image2, &iref2);
wUPP = NewEventHandlerUPP(KeyWindowEventHandler);
err = InstallWindowEventHandler(tWindowRef, wUPP, GetEventTypeCount(wEvents), wEvents, (void *) tWindowRef, &wref);
MoveWindowPosition(tWindowRef, kWindowKeyConfig, false);
ShowWindow(tWindowRef);
err = RunAppModalLoopForWindow(tWindowRef);
HideWindow(tWindowRef);
SaveWindowPosition(tWindowRef, kWindowKeyConfig);
err = RemoveEventHandler(iref2);
err = RemoveEventHandler(iref1);
DisposeEventHandlerUPP(iUPP);
err = RemoveEventHandler(wref);
DisposeEventHandlerUPP(wUPP);
}
}
CFRelease(tWindowRef);
}
DisposeNibReference(nibRef);
}
// OSStatus err;
// IBNibRef nibRef;
//
// err = CreateNibReference(kMacS9XCFString, &nibRef);
// if (err == noErr)
// {
// WindowRef tWindowRef;
//
// err = CreateWindowFromNib(nibRef, CFSTR("Keyboard"), &tWindowRef);
// if (err == noErr)
// {
// EventHandlerRef wref, iref1, iref2;
// EventHandlerUPP wUPP, iUPP;
// EventTypeSpec wEvents[] = { { kEventClassWindow, kEventWindowClose },
// { kEventClassCommand, kEventCommandProcess },
// { kEventClassCommand, kEventCommandUpdateStatus } },
// cEvents[] = { { kEventClassHIObject, kEventHIObjectConstruct },
// { kEventClassHIObject, kEventHIObjectDestruct },
// { kEventClassHIObject, kEventHIObjectInitialize },
// { kEventClassControl, kEventControlDraw },
// { kEventClassControl, kEventControlHitTest },
// { kEventClassControl, kEventControlTrack } },
// iEvents[] = { { kEventClassControl, kEventControlDraw } };
// HIObjectRef hiObject;
// HIViewRef contentView, image1, image2;
// HIViewID cid;
// HIRect frame;
// Rect winBounds;
//
// UpdateIconPlaceImage();
//
// keyInDrag = false;
// dragKey = -1;
// dragKeyOfs = CGPointMake(0.0f, 0.0f);
// dragKeyRect = CGRectMake(0.0f, 0.0f, 0.0f, 0.0f);
// mousePos = CGPointMake(0.0f, 0.0f);
//
// err = noErr;
// if (theClass == NULL)
// err = HIObjectRegisterSubclass(kCustomLayoutViewClassID, kHIViewClassID, 0, KeyLayoutEventHandler, GetEventTypeCount(cEvents), cEvents, NULL, &theClass);
//
// if (err == noErr)
// {
// err = HIObjectCreate(kCustomLayoutViewClassID, NULL, &hiObject);
// if (err == noErr)
// {
// GetWindowBounds(tWindowRef, kWindowContentRgn, &winBounds);
//
// frame.origin.x = 2.0f;
// frame.origin.y = 2.0f;
// frame.size.width = (float) (winBounds.right - winBounds.left) - 4.0f;
// frame.size.height = (float) kKeyLayoutHeight + 36.0f;
//
// ofsx = (float) (((int) frame.size.width - kKeyLayoutWidth ) >> 1) + 1.0f;
// ofsy = (float) (((int) frame.size.height - kKeyLayoutHeight) >> 1) + 1.0f;
//
// customView = (HIViewRef) hiObject;
//
// HIViewFindByID(HIViewGetRoot(tWindowRef), kHIViewWindowContentID, &contentView);
// HIViewAddSubview(contentView, customView);
// HIViewSetFrame(customView, &frame);
// HIViewSetVisible(customView, true);
//
// cid.signature = 'Lgnd';
// cid.id = 0;
// HIViewFindByID(contentView, cid, &image1);
// cid.id = 1;
// HIViewFindByID(contentView, cid, &image2);
// iUPP = NewEventHandlerUPP(KeyLegendEventHandler);
// err = InstallControlEventHandler(image1, iUPP, GetEventTypeCount(iEvents), iEvents, (void *) image1, &iref1);
// err = InstallControlEventHandler(image2, iUPP, GetEventTypeCount(iEvents), iEvents, (void *) image2, &iref2);
//
// wUPP = NewEventHandlerUPP(KeyWindowEventHandler);
// err = InstallWindowEventHandler(tWindowRef, wUPP, GetEventTypeCount(wEvents), wEvents, (void *) tWindowRef, &wref);
//
// MoveWindowPosition(tWindowRef, kWindowKeyConfig, false);
// ShowWindow(tWindowRef);
// err = RunAppModalLoopForWindow(tWindowRef);
// HideWindow(tWindowRef);
// SaveWindowPosition(tWindowRef, kWindowKeyConfig);
//
// err = RemoveEventHandler(iref2);
// err = RemoveEventHandler(iref1);
// DisposeEventHandlerUPP(iUPP);
//
// err = RemoveEventHandler(wref);
// DisposeEventHandlerUPP(wUPP);
// }
// }
//
// CFRelease(tWindowRef);
// }
//
// DisposeNibReference(nibRef);
// }
}
static void CreateIconTableImage (void)
@ -416,19 +416,19 @@ static void CreateIconTableImage (void)
iconTableCGWld = (Ptr) malloc(kIconSize * kKeys * (kIconSize + 1) * 4);
if (!iconTableCGWld)
QuitWithFatalError(0, "keyboard 08");
QuitWithFatalError(@"keyboard 08");
ctx = NULL;
color = CGColorSpaceCreateDeviceRGB();
if (color)
{
ctx = CGBitmapContextCreate(iconTableCGWld, kIconSize * kKeys, kIconSize, 8, kIconSize * kKeys * 4, color, kCGImageAlphaNoneSkipFirst | ((systemVersion >= 0x1040) ? kCGBitmapByteOrderDefault : 0));
ctx = CGBitmapContextCreate(iconTableCGWld, kIconSize * kKeys, kIconSize, 8, kIconSize * kKeys * 4, color, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrderDefault);
CGColorSpaceRelease(color);
}
if (!ctx)
QuitWithFatalError(0, "keyboard 09");
QuitWithFatalError(@"keyboard 09");
CGContextTranslateCTM(ctx, 0.0f, (float) kIconSize);
CGContextScaleCTM(ctx, 1.0f, -1.0f);
@ -436,24 +436,13 @@ static void CreateIconTableImage (void)
// SNES pads
for (int i = macPadIconIndex; i < macPadIconIndex + 12 * 2; i++)
{
if (systemVersion >= 0x1040)
CGContextDrawImage(ctx, rct, macIconImage[i]);
#ifdef MAC_PANTHER_SUPPORT
else
PlotIconRefInContext(ctx, &rct, kAlignNone, kTransformNone, NULL, kPlotIconRefNormalFlags, macIconRef[i]);
#endif
rct = CGRectOffset(rct, kIconSize, 0);
}
CGContextDrawImage(ctx, rct, macIconImage[i]);
}
// Function buttons
for (int i = macFunctionIconIndex; i < macFunctionIconIndex + 17; i++)
{
if (systemVersion >= 0x1040)
CGContextDrawImage(ctx, rct, macIconImage[i]);
#ifdef MAC_PANTHER_SUPPORT
else
PlotIconRefInContext(ctx, &rct, kAlignNone, kTransformNone, NULL, kPlotIconRefNormalFlags, macIconRef[i]);
#endif
CGContextDrawImage(ctx, rct, macIconImage[i]);
rct = CGRectOffset(rct, kIconSize, 0);
}
@ -467,7 +456,7 @@ static void CreateIconTableImage (void)
color = CGColorSpaceCreateDeviceRGB();
if (color)
{
iconTableImage = CGImageCreate(kIconSize * kKeys, kIconSize, 8, 32, kIconSize * kKeys * 4, color, kCGImageAlphaNoneSkipFirst | ((systemVersion >= 0x1040) ? kCGBitmapByteOrderDefault : 0), prov, NULL, 0, kCGRenderingIntentDefault);
iconTableImage = CGImageCreate(kIconSize * kKeys, kIconSize, 8, 32, kIconSize * kKeys * 4, color, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrderDefault, prov, NULL, 0, kCGRenderingIntentDefault);
CGColorSpaceRelease(color);
}
@ -475,7 +464,7 @@ static void CreateIconTableImage (void)
}
if (!iconTableImage)
QuitWithFatalError(0, "keyboard 10");
QuitWithFatalError(@"keyboard 10");
}
static void ReleaseIconTableImage (void)
@ -499,19 +488,19 @@ static void CreateKeyLayoutImage (void)
keyLayoutWorld = (Ptr) malloc(kKeyLayoutWidth * (kKeyLayoutHeight + 1) * 4);
if (!keyLayoutWorld)
QuitWithFatalError(0, "keyboard 02");
QuitWithFatalError(@"keyboard 02");
ctx = NULL;
color = CGColorSpaceCreateDeviceRGB();
if (color)
{
ctx = CGBitmapContextCreate(keyLayoutWorld, kKeyLayoutWidth, kKeyLayoutHeight, 8, kKeyLayoutWidth * 4, color, kCGImageAlphaPremultipliedFirst | ((systemVersion >= 0x1040) ? kCGBitmapByteOrderDefault : 0));
ctx = CGBitmapContextCreate(keyLayoutWorld, kKeyLayoutWidth, kKeyLayoutHeight, 8, kKeyLayoutWidth * 4, color, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrderDefault);
CGColorSpaceRelease(color);
}
if (!ctx)
QuitWithFatalError(0, "keyboard 04");
QuitWithFatalError(@"keyboard 04");
CGContextSetLineJoin(ctx, kCGLineJoinMiter);
@ -587,7 +576,7 @@ static void CreateKeyLayoutImage (void)
color = CGColorSpaceCreateDeviceRGB();
if (color)
{
keyLayoutImage = CGImageCreate(kKeyLayoutWidth, kKeyLayoutHeight, 8, 32, kKeyLayoutWidth * 4, color, kCGImageAlphaPremultipliedFirst | ((systemVersion >= 0x1040) ? kCGBitmapByteOrderDefault : 0), prov, NULL, 0, kCGRenderingIntentDefault);
keyLayoutImage = CGImageCreate(kKeyLayoutWidth, kKeyLayoutHeight, 8, 32, kKeyLayoutWidth * 4, color, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrderDefault, prov, NULL, 0, kCGRenderingIntentDefault);
CGColorSpaceRelease(color);
}
@ -595,7 +584,7 @@ static void CreateKeyLayoutImage (void)
}
if (!keyLayoutImage)
QuitWithFatalError(0, "keyboard 05");
QuitWithFatalError(@"keyboard 05");
}
static void ReleaseKeyLayoutImage (void)
@ -608,7 +597,7 @@ static void CreateIconPlaceImage (void)
{
iconPlaceWorld = (Ptr) malloc(kKeyLayoutWidth * (kKeyLayoutHeight + 1) * 4);
if (!iconPlaceWorld)
QuitWithFatalError(0, "keyboard 06");
QuitWithFatalError(@"keyboard 06");
iconPlaceImage = NULL;
@ -630,7 +619,7 @@ static void UpdateIconPlaceImage (void)
color = CGColorSpaceCreateDeviceRGB();
if (color)
{
ctx = CGBitmapContextCreate(iconPlaceWorld, kKeyLayoutWidth, kKeyLayoutHeight, 8, kKeyLayoutWidth * 4, color, kCGImageAlphaPremultipliedFirst | ((systemVersion >= 0x1040) ? kCGBitmapByteOrderDefault : 0));
ctx = CGBitmapContextCreate(iconPlaceWorld, kKeyLayoutWidth, kKeyLayoutHeight, 8, kKeyLayoutWidth * 4, color, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrderDefault);
if (ctx)
{
rct = CGRectMake(0.0f, 0.0f, (float) kKeyLayoutWidth, (float) kKeyLayoutHeight);
@ -645,7 +634,7 @@ static void UpdateIconPlaceImage (void)
prov = CGDataProviderCreateWithData(NULL, iconPlaceWorld, kKeyLayoutWidth * kKeyLayoutHeight * 4, NULL);
if (prov)
{
iconPlaceImage = CGImageCreate(kKeyLayoutWidth, kKeyLayoutHeight, 8, 32, kKeyLayoutWidth * 4, color, kCGImageAlphaPremultipliedFirst | ((systemVersion >= 0x1040) ? kCGBitmapByteOrderDefault : 0), prov, NULL, 0, kCGRenderingIntentDefault);
iconPlaceImage = CGImageCreate(kKeyLayoutWidth, kKeyLayoutHeight, 8, 32, kKeyLayoutWidth * 4, color, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrderDefault, prov, NULL, 0, kCGRenderingIntentDefault);
CGDataProviderRelease(prov);
}
@ -653,7 +642,7 @@ static void UpdateIconPlaceImage (void)
}
if (!iconPlaceImage)
QuitWithFatalError(0, "keyboard 07");
QuitWithFatalError(@"keyboard 07");
}
static void ReleaseIconPlaceImage (void)
@ -782,253 +771,257 @@ static int FindHitKey (HIPoint where, CGRect *keybounds, CGPoint *offset)
static OSStatus KeyWindowEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
OSStatus err, result = eventNotHandledErr;
WindowRef tWindowRef = (WindowRef) inUserData;
switch (GetEventClass(inEvent))
{
case kEventClassWindow:
switch (GetEventKind(inEvent))
{
case kEventWindowClose:
QuitAppModalLoopForWindow(tWindowRef);
result = noErr;
}
break;
case kEventClassCommand:
switch (GetEventKind(inEvent))
{
HICommand tHICommand;
case kEventCommandUpdateStatus:
err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
if (err == noErr && tHICommand.commandID == 'clos')
{
UpdateMenuCommandStatus(true);
result = noErr;
}
break;
case kEventCommandProcess:
err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
if (err == noErr)
{
if (tHICommand.commandID == 'DFLT')
{
memcpy(keyCode, defaultKeys, sizeof(keyCode));
UpdateIconPlaceImage();
HIViewSetNeedsDisplay(customView, true);
result = noErr;
}
}
}
}
return (result);
// OSStatus err, result = eventNotHandledErr;
// WindowRef tWindowRef = (WindowRef) inUserData;
//
// switch (GetEventClass(inEvent))
// {
// case kEventClassWindow:
// switch (GetEventKind(inEvent))
// {
// case kEventWindowClose:
// QuitAppModalLoopForWindow(tWindowRef);
// result = noErr;
// }
//
// break;
//
// case kEventClassCommand:
// switch (GetEventKind(inEvent))
// {
// HICommand tHICommand;
//
// case kEventCommandUpdateStatus:
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
// if (err == noErr && tHICommand.commandID == 'clos')
// {
// UpdateMenuCommandStatus(true);
// result = noErr;
// }
//
// break;
//
// case kEventCommandProcess:
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
// if (err == noErr)
// {
// if (tHICommand.commandID == 'DFLT')
// {
// memcpy(keyCode, defaultKeys, sizeof(keyCode));
// UpdateIconPlaceImage();
// HIViewSetNeedsDisplay(customView, true);
// result = noErr;
// }
// }
// }
// }
//
// return (result);
return 0;
}
static OSStatus KeyLegendEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
OSStatus err, result = eventNotHandledErr;
HIViewRef view = (HIViewRef) inUserData;
// OSStatus err, result = eventNotHandledErr;
// HIViewRef view = (HIViewRef) inUserData;
//
// switch (GetEventClass(inEvent))
// {
// case kEventClassControl:
// switch (GetEventKind(inEvent))
// {
// case kEventControlDraw:
// CGContextRef ctx;
//
// err = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &ctx);
// if (err == noErr)
// {
// HIViewID cid;
// HIRect bounds;
//
// GetControlID(view, &cid);
// HIViewGetBounds(view, &bounds);
// CGContextTranslateCTM(ctx, 0, bounds.size.height);
// CGContextScaleCTM(ctx, 1.0f, -1.0f);
// CGContextDrawImage(ctx, CGRectMake(0, 0, kIconSize, kIconSize), macIconImage[macLegendIconIndex + cid.id]);
//
// result = noErr;
// }
// }
// }
//
// return (result);
switch (GetEventClass(inEvent))
{
case kEventClassControl:
switch (GetEventKind(inEvent))
{
case kEventControlDraw:
CGContextRef ctx;
err = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &ctx);
if (err == noErr)
{
HIViewID cid;
HIRect bounds;
GetControlID(view, &cid);
HIViewGetBounds(view, &bounds);
CGContextTranslateCTM(ctx, 0, bounds.size.height);
CGContextScaleCTM(ctx, 1.0f, -1.0f);
CGContextDrawImage(ctx, CGRectMake(0, 0, kIconSize, kIconSize), macIconImage[macLegendIconIndex + cid.id]);
result = noErr;
}
}
}
return (result);
return 0;
}
static OSStatus KeyLayoutEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
OSStatus err, result = eventNotHandledErr;
CustomViewData *data = (CustomViewData *) inUserData;
switch (GetEventClass(inEvent))
{
case kEventClassHIObject:
switch (GetEventKind(inEvent))
{
case kEventHIObjectConstruct:
data = (CustomViewData *) calloc(1, sizeof(CustomViewData));
if (data)
{
HIViewRef epView;
err = GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(epView), NULL, &epView);
if (err == noErr)
{
data->view = epView;
result = SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(data), &data);
}
}
break;
case kEventHIObjectDestruct:
if (data)
free(data);
result = noErr;
break;
case kEventHIObjectInitialize:
result = CallNextEventHandler(inHandlerRef, inEvent);
}
break;
case kEventClassControl:
switch (GetEventKind(inEvent))
{
case kEventControlDraw:
CGContextRef ctx;
err = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(ctx), NULL, &ctx);
if (err == noErr)
{
HIRect bounds, srcRect, dstRect;
HIViewGetBounds(customView, &bounds);
srcRect = CGRectMake(0, 0, kKeyLayoutWidth, kKeyLayoutHeight);
dstRect.origin.x = (float) (((int) bounds.size.width - kKeyLayoutWidth ) >> 1);
dstRect.origin.y = (float) (((int) bounds.size.height - kKeyLayoutHeight) >> 1);
dstRect.size.width = (float) kKeyLayoutWidth;
dstRect.size.height = (float) kKeyLayoutHeight;
DrawSubCGImage(ctx, iconPlaceImage, srcRect, dstRect);
if (keyInDrag && (dragKey != -1))
DrawDraggedIcon(ctx, dragKey, &dragKeyOfs);
}
result = noErr;
break;
case kEventControlHitTest:
ControlPartCode part;
part = kControlButtonPart;
result = SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(part), &part);
break;
case kEventControlTrack:
MouseTrackingResult trackResult;
WindowRef window;
HIViewRef contentView;
HIPoint hipt;
dragKey = -1;
dragKeyOfs = CGPointMake(0.0f, 0.0f);
dragKeyRect = CGRectMake(0.0f, 0.0f, 0.0f, 0.0f);
mousePos = CGPointMake(0.0f, 0.0f);
trackResult = kMouseTrackingMouseDown;
window = GetControlOwner(customView);
HIViewFindByID(HIViewGetRoot(window), kHIViewWindowContentID, &contentView);
#ifdef MAC_TIGER_PANTHER_SUPPORT
CGrafPtr oldPort;
Point qdpt;
Boolean portChanged = false;
if (systemVersion < 0x1050)
portChanged = QDSwapPort(GetWindowPort(window), &oldPort);
#endif
err = GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(hipt), NULL, &hipt);
if (err == noErr)
{
hipt.x -= ofsx;
hipt.y -= ofsy;
dragKey = FindHitKey(hipt, &dragKeyRect, &dragKeyOfs);
if (dragKey != -1)
{
keyInDrag = true;
while (trackResult != kMouseTrackingMouseUp)
{
if (CGPointEqualToPoint(mousePos, hipt) == 0)
{
mousePos = hipt;
HIViewSetNeedsDisplay(customView, true);
}
if (systemVersion >= 0x1050)
{
err = HIViewTrackMouseLocation(customView, 0, kEventDurationForever, 0, NULL, &hipt, NULL, NULL, &trackResult);
hipt.x -= ofsx;
hipt.y -= ofsy;
}
#ifdef MAC_TIGER_PANTHER_SUPPORT
else
{
TrackMouseLocation(NULL, &qdpt, &trackResult);
hipt.x = qdpt.h - ofsx;
hipt.y = qdpt.v - ofsy;
HIViewConvertPoint(&hipt, contentView, customView);
}
#endif
}
keyInDrag = false;
for (int code = 0; code < 0x80; code++)
{
for (int each = 0; each <= 1; each++)
{
if (CGRectContainsPoint(keyRect[code][each], mousePos))
{
if (!KeyCodeInUse(code))
{
keyCode[dragKey] = code;
UpdateIconPlaceImage();
}
}
}
}
HIViewSetNeedsDisplay(customView, true);
}
}
#ifdef MAC_TIGER_PANTHER_SUPPORT
if (systemVersion < 0x1050)
{
if (portChanged)
QDSwapPort(oldPort, NULL);
}
#endif
result = noErr;
}
}
return (result);
// OSStatus err, result = eventNotHandledErr;
// CustomViewData *data = (CustomViewData *) inUserData;
//
// switch (GetEventClass(inEvent))
// {
// case kEventClassHIObject:
// switch (GetEventKind(inEvent))
// {
// case kEventHIObjectConstruct:
// data = (CustomViewData *) calloc(1, sizeof(CustomViewData));
// if (data)
// {
// HIViewRef epView;
//
// err = GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(epView), NULL, &epView);
// if (err == noErr)
// {
// data->view = epView;
// result = SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(data), &data);
// }
// }
//
// break;
//
// case kEventHIObjectDestruct:
// if (data)
// free(data);
//
// result = noErr;
// break;
//
// case kEventHIObjectInitialize:
// result = CallNextEventHandler(inHandlerRef, inEvent);
// }
//
// break;
//
// case kEventClassControl:
// switch (GetEventKind(inEvent))
// {
// case kEventControlDraw:
// CGContextRef ctx;
//
// err = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(ctx), NULL, &ctx);
// if (err == noErr)
// {
// HIRect bounds, srcRect, dstRect;
//
// HIViewGetBounds(customView, &bounds);
// srcRect = CGRectMake(0, 0, kKeyLayoutWidth, kKeyLayoutHeight);
//
// dstRect.origin.x = (float) (((int) bounds.size.width - kKeyLayoutWidth ) >> 1);
// dstRect.origin.y = (float) (((int) bounds.size.height - kKeyLayoutHeight) >> 1);
// dstRect.size.width = (float) kKeyLayoutWidth;
// dstRect.size.height = (float) kKeyLayoutHeight;
//
// DrawSubCGImage(ctx, iconPlaceImage, srcRect, dstRect);
// if (keyInDrag && (dragKey != -1))
// DrawDraggedIcon(ctx, dragKey, &dragKeyOfs);
// }
//
// result = noErr;
// break;
//
// case kEventControlHitTest:
// ControlPartCode part;
//
// part = kControlButtonPart;
// result = SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(part), &part);
//
// break;
//
// case kEventControlTrack:
// MouseTrackingResult trackResult;
// WindowRef window;
// HIViewRef contentView;
// HIPoint hipt;
//
// dragKey = -1;
// dragKeyOfs = CGPointMake(0.0f, 0.0f);
// dragKeyRect = CGRectMake(0.0f, 0.0f, 0.0f, 0.0f);
// mousePos = CGPointMake(0.0f, 0.0f);
// trackResult = kMouseTrackingMouseDown;
//
// window = GetControlOwner(customView);
// HIViewFindByID(HIViewGetRoot(window), kHIViewWindowContentID, &contentView);
//
// #ifdef MAC_TIGER_PANTHER_SUPPORT
// CGrafPtr oldPort;
// Point qdpt;
// Boolean portChanged = false;
//
// if (systemVersion < 0x1050)
// portChanged = QDSwapPort(GetWindowPort(window), &oldPort);
// #endif
//
// err = GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(hipt), NULL, &hipt);
// if (err == noErr)
// {
// hipt.x -= ofsx;
// hipt.y -= ofsy;
//
// dragKey = FindHitKey(hipt, &dragKeyRect, &dragKeyOfs);
// if (dragKey != -1)
// {
// keyInDrag = true;
//
// while (trackResult != kMouseTrackingMouseUp)
// {
// if (CGPointEqualToPoint(mousePos, hipt) == 0)
// {
// mousePos = hipt;
// HIViewSetNeedsDisplay(customView, true);
// }
//
// if (systemVersion >= 0x1050)
// {
// err = HIViewTrackMouseLocation(customView, 0, kEventDurationForever, 0, NULL, &hipt, NULL, NULL, &trackResult);
// hipt.x -= ofsx;
// hipt.y -= ofsy;
// }
// #ifdef MAC_TIGER_PANTHER_SUPPORT
// else
// {
// TrackMouseLocation(NULL, &qdpt, &trackResult);
// hipt.x = qdpt.h - ofsx;
// hipt.y = qdpt.v - ofsy;
// HIViewConvertPoint(&hipt, contentView, customView);
// }
// #endif
// }
//
// keyInDrag = false;
//
// for (int code = 0; code < 0x80; code++)
// {
// for (int each = 0; each <= 1; each++)
// {
// if (CGRectContainsPoint(keyRect[code][each], mousePos))
// {
// if (!KeyCodeInUse(code))
// {
// keyCode[dragKey] = code;
// UpdateIconPlaceImage();
// }
// }
// }
// }
//
// HIViewSetNeedsDisplay(customView, true);
// }
// }
//
// #ifdef MAC_TIGER_PANTHER_SUPPORT
// if (systemVersion < 0x1050)
// {
// if (portChanged)
// QDSwapPort(oldPort, NULL);
// }
// #endif
//
// result = noErr;
// }
// }
//
// return (result);
return 0;
}

View File

@ -1,534 +0,0 @@
/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
/***********************************************************************************
SNES9X for Mac OS (c) Copyright John Stiles
Snes9x for Mac OS X
(c) Copyright 2001 - 2011 zones
(c) Copyright 2002 - 2005 107
(c) Copyright 2002 PB1400c
(c) Copyright 2004 Alexander and Sander
(c) Copyright 2004 - 2005 Steven Seeger
(c) Copyright 2005 Ryan Vogt
***********************************************************************************/
#include "port.h"
#include "mac-prefix.h"
#include "mac-cart.h"
#include "mac-dialog.h"
#include "mac-os.h"
#include "mac-multicart.h"
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
#define truncEnd 0
#endif
static OSStatus MultiCartEventHandler (EventHandlerCallRef, EventRef, void *);
static OSStatus MultiCartPaneEventHandler (EventHandlerCallRef, EventRef, void *);
static int multiCartDragHilite;
static Boolean multiCartDialogResult;
void InitMultiCart (void)
{
CFStringRef keyRef, pathRef;
char key[32];
multiCartPath[0] = multiCartPath[1] = NULL;
for (int i = 0; i < 2; i++)
{
sprintf(key, "MultiCartPath_%02d", i);
keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding());
if (keyRef)
{
pathRef = (CFStringRef) CFPreferencesCopyAppValue(keyRef, kCFPreferencesCurrentApplication);
if (pathRef)
multiCartPath[i] = pathRef;
CFRelease(keyRef);
}
}
}
void DeinitMultiCart (void)
{
CFStringRef keyRef;
char key[32];
for (int i = 0; i < 2; i++)
{
sprintf(key, "MultiCartPath_%02d", i);
keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding());
if (keyRef)
{
if (multiCartPath[i])
{
CFPreferencesSetAppValue(keyRef, multiCartPath[i], kCFPreferencesCurrentApplication);
CFRelease(multiCartPath[i]);
}
else
CFPreferencesSetAppValue(keyRef, NULL, kCFPreferencesCurrentApplication);
CFRelease(keyRef);
}
}
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
}
Boolean MultiCartDialog (void)
{
OSStatus err;
IBNibRef nibRef;
multiCartDragHilite = -1;
multiCartDialogResult = false;
err = CreateNibReference(kMacS9XCFString, &nibRef);
if (err == noErr)
{
WindowRef window;
err = CreateWindowFromNib(nibRef, CFSTR("MultiCart"), &window);
if (err == noErr)
{
static int index[2] = { 0, 1 };
EventHandlerRef wRef, cRef[2];
EventHandlerUPP wUPP, cUPP[2];
EventTypeSpec wEvent[] = { { kEventClassCommand, kEventCommandProcess },
{ kEventClassCommand, kEventCommandUpdateStatus } },
cEvent[] = { { kEventClassControl, kEventControlDraw },
{ kEventClassControl, kEventControlDragEnter },
{ kEventClassControl, kEventControlDragWithin },
{ kEventClassControl, kEventControlDragLeave },
{ kEventClassControl, kEventControlDragReceive } };
HIViewRef ctl, root, pane[2];
HIViewID cid;
root = HIViewGetRoot(window);
wUPP = NewEventHandlerUPP(MultiCartEventHandler);
err = InstallWindowEventHandler(window, wUPP, GetEventTypeCount(wEvent), wEvent, (void *) window, &wRef);
err = SetAutomaticControlDragTrackingEnabledForWindow(window, true);
for (int i = 0; i < 2; i++)
{
cid.id = i;
cid.signature = 'MPan';
HIViewFindByID(root, cid, &pane[i]);
cUPP[i] = NewEventHandlerUPP(MultiCartPaneEventHandler);
err = InstallControlEventHandler(pane[i], cUPP[i], GetEventTypeCount(cEvent), cEvent, (void *) &index[i], &cRef[i]);
err = SetControlDragTrackingEnabled(pane[i], true);
cid.signature = 'MNAM';
HIViewFindByID(root, cid, &ctl);
SetStaticTextTrunc(ctl, truncEnd, false);
if (multiCartPath[i])
{
CFStringRef str;
CFURLRef url;
url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, multiCartPath[i], kCFURLPOSIXPathStyle, false);
str = CFURLCopyLastPathComponent(url);
SetStaticTextCFString(ctl, str, false);
CFRelease(str);
CFRelease(url);
}
else
SetStaticTextCFString(ctl, CFSTR(""), false);
}
MoveWindowPosition(window, kWindowMultiCart, false);
ShowWindow(window);
err = RunAppModalLoopForWindow(window);
HideWindow(window);
SaveWindowPosition(window, kWindowMultiCart);
for (int i = 0; i < 2; i++)
{
err = RemoveEventHandler(cRef[i]);
DisposeEventHandlerUPP(cUPP[i]);
}
err = RemoveEventHandler(wRef);
DisposeEventHandlerUPP(wUPP);
CFRelease(window);
}
DisposeNibReference(nibRef);
}
return (multiCartDialogResult);
}
static OSStatus MultiCartEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
OSStatus err, result = eventNotHandledErr;
WindowRef window = (WindowRef) inUserData;
static int index = -1;
switch (GetEventClass(inEvent))
{
case kEventClassCommand:
{
switch (GetEventKind(inEvent))
{
HICommand tHICommand;
case kEventCommandUpdateStatus:
{
err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
if (err == noErr && tHICommand.commandID == 'clos')
{
UpdateMenuCommandStatus(false);
result = noErr;
}
break;
}
case kEventCommandProcess:
{
err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
if (err == noErr)
{
HIViewRef ctl, root;
HIViewID cid;
FSRef ref;
bool8 r;
root = HIViewGetRoot(window);
switch (tHICommand.commandID)
{
case 'Cho0':
case 'Cho1':
{
index = (tHICommand.commandID & 0xFF) - '0';
r = NavBeginOpenROMImageSheet(window, NULL);
result = noErr;
break;
}
case 'NvDn':
{
r = NavEndOpenROMImageSheet(&ref);
if (r)
{
CFStringRef str;
CFURLRef url;
url = CFURLCreateFromFSRef(kCFAllocatorDefault, &ref);
str = CFURLCopyLastPathComponent(url);
cid.signature = 'MNAM';
cid.id = index;
HIViewFindByID(root, cid, &ctl);
SetStaticTextCFString(ctl, str, true);
CFRelease(str);
str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
if (multiCartPath[index])
CFRelease(multiCartPath[index]);
multiCartPath[index] = str;
CFRelease(url);
}
index = -1;
result = noErr;
break;
}
case 'Cle0':
case 'Cle1':
{
index = (tHICommand.commandID & 0xFF) - '0';
cid.signature = 'MNAM';
cid.id = index;
HIViewFindByID(root, cid, &ctl);
SetStaticTextCFString(ctl, CFSTR(""), true);
if (multiCartPath[index])
{
CFRelease(multiCartPath[index]);
multiCartPath[index] = NULL;
}
index = -1;
result = noErr;
break;
}
case 'SWAP':
{
CFStringRef str;
CFURLRef url;
str = multiCartPath[0];
multiCartPath[0] = multiCartPath[1];
multiCartPath[1] = str;
cid.signature = 'MNAM';
for (int i = 0; i < 2; i++)
{
cid.id = i;
HIViewFindByID(root, cid, &ctl);
if (multiCartPath[i])
{
url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, multiCartPath[i], kCFURLPOSIXPathStyle, false);
str = CFURLCopyLastPathComponent(url);
SetStaticTextCFString(ctl, str, true);
CFRelease(str);
CFRelease(url);
}
else
SetStaticTextCFString(ctl, CFSTR(""), true);
}
result = noErr;
break;
}
case 'ok ':
{
QuitAppModalLoopForWindow(window);
multiCartDialogResult = true;
result = noErr;
break;
}
case 'not!':
{
QuitAppModalLoopForWindow(window);
multiCartDialogResult = false;
result = noErr;
break;
}
}
}
}
}
}
}
return (result);
}
static OSStatus MultiCartPaneEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
OSStatus err, result = eventNotHandledErr;
HIViewRef view;
DragRef drag;
PasteboardRef pasteboard;
PasteboardItemID itemID;
CFArrayRef array;
CFStringRef flavorType;
CFIndex numFlavors;
ItemCount numItems;
int index = *((int *) inUserData);
switch (GetEventClass(inEvent))
{
case kEventClassControl:
{
switch (GetEventKind(inEvent))
{
case kEventControlDraw:
{
err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view);
if (err == noErr)
{
CGContextRef ctx;
err = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &ctx);
if (err == noErr)
{
HIThemeFrameDrawInfo info;
HIRect bounds, frame;
HIViewGetBounds(view, &bounds);
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f);
CGContextFillRect(ctx, bounds);
info.version = 0;
info.kind = kHIThemeFrameTextFieldSquare;
info.state = kThemeStateInactive;
info.isFocused = false;
err = HIThemeDrawFrame(&bounds, &info, ctx, kHIThemeOrientationNormal);
if (multiCartDragHilite == index && systemVersion >= 0x1040)
{
err = HIThemeSetStroke(kThemeBrushDragHilite, NULL, ctx, kHIThemeOrientationNormal);
frame = CGRectInset(bounds, 1, 1);
CGContextBeginPath(ctx);
CGContextAddRect(ctx, frame);
CGContextStrokePath(ctx);
}
}
}
result = noErr;
break;
}
case kEventControlDragEnter:
{
err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view);
if (err == noErr)
{
err = GetEventParameter(inEvent, kEventParamDragRef, typeDragRef, NULL, sizeof(DragRef), NULL, &drag);
if (err == noErr)
{
err = GetDragPasteboard(drag, &pasteboard);
if (err == noErr)
{
err = PasteboardGetItemCount(pasteboard, &numItems);
if (err == noErr && numItems == 1)
{
err = PasteboardGetItemIdentifier(pasteboard, 1, &itemID);
if (err == noErr)
{
err = PasteboardCopyItemFlavors(pasteboard, itemID, &array);
if (err == noErr)
{
numFlavors = CFArrayGetCount(array);
for (CFIndex i = 0; i < numFlavors; i++)
{
flavorType = (CFStringRef) CFArrayGetValueAtIndex(array, i);
if (UTTypeConformsTo(flavorType, CFSTR("public.file-url")))
{
Boolean accept = true;
err = SetEventParameter(inEvent, kEventParamControlWouldAcceptDrop, typeBoolean, sizeof(Boolean), &accept);
if (err == noErr)
{
multiCartDragHilite = index;
HIViewSetNeedsDisplay(view, true);
result = noErr;
}
}
}
CFRelease(array);
}
}
}
}
}
}
break;
}
case kEventControlDragWithin:
{
result = noErr;
break;
}
case kEventControlDragLeave:
{
err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view);
if (err == noErr)
{
multiCartDragHilite = -1;
HIViewSetNeedsDisplay(view, true);
}
result = noErr;
break;
}
case kEventControlDragReceive:
{
err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view);
if (err == noErr)
{
err = GetEventParameter(inEvent, kEventParamDragRef, typeDragRef, NULL, sizeof(DragRef), NULL, &drag);
if (err == noErr)
{
multiCartDragHilite = -1;
HIViewSetNeedsDisplay(view, true);
err = GetDragPasteboard(drag, &pasteboard);
if (err == noErr)
{
err = PasteboardGetItemIdentifier(pasteboard, 1, &itemID);
if (err == noErr)
{
err = PasteboardCopyItemFlavors(pasteboard, itemID, &array);
if (err == noErr)
{
numFlavors = CFArrayGetCount(array);
for (CFIndex i = 0; i < numFlavors; i++)
{
flavorType = (CFStringRef) CFArrayGetValueAtIndex(array, i);
if (UTTypeConformsTo(flavorType, CFSTR("public.file-url")))
{
CFDataRef flavorData;
err = PasteboardCopyItemFlavorData(pasteboard, itemID, flavorType, &flavorData);
if (err == noErr)
{
CFIndex dataSize;
UInt8 *data;
dataSize = CFDataGetLength(flavorData);
data = (UInt8 *) malloc(dataSize);
if (data)
{
CFDataGetBytes(flavorData, CFRangeMake(0, dataSize), data);
HIViewRef ctl;
HIViewID cid;
CFStringRef str;
CFURLRef url;
GetControlID(view, &cid);
cid.signature = 'MNAM';
HIViewFindByID(view, cid, &ctl);
url = CFURLCreateWithBytes(kCFAllocatorDefault, data, dataSize, kCFStringEncodingUTF8, NULL);
str = CFURLCopyLastPathComponent(url);
SetStaticTextCFString(ctl, str, true);
CFRelease(str);
str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
if (multiCartPath[cid.id])
CFRelease(multiCartPath[cid.id]);
multiCartPath[cid.id] = str;
CFRelease(url);
result = noErr;
free(data);
}
CFRelease(flavorData);
}
}
}
CFRelease(array);
}
}
}
}
}
}
}
}
}
return (result);
}

539
macosx/mac-multicart.mm Normal file
View File

@ -0,0 +1,539 @@
/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
/***********************************************************************************
SNES9X for Mac OS (c) Copyright John Stiles
Snes9x for Mac OS X
(c) Copyright 2001 - 2011 zones
(c) Copyright 2002 - 2005 107
(c) Copyright 2002 PB1400c
(c) Copyright 2004 Alexander and Sander
(c) Copyright 2004 - 2005 Steven Seeger
(c) Copyright 2005 Ryan Vogt
***********************************************************************************/
#include "port.h"
#include "mac-prefix.h"
#include "mac-cart.h"
#include "mac-dialog.h"
#include "mac-os.h"
#include "mac-multicart.h"
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
#define truncEnd 0
#endif
static OSStatus MultiCartEventHandler (EventHandlerCallRef, EventRef, void *);
static OSStatus MultiCartPaneEventHandler (EventHandlerCallRef, EventRef, void *);
static int multiCartDragHilite;
static Boolean multiCartDialogResult;
void InitMultiCart (void)
{
CFStringRef keyRef, pathRef;
char key[32];
multiCartPath[0] = multiCartPath[1] = NULL;
for (int i = 0; i < 2; i++)
{
sprintf(key, "MultiCartPath_%02d", i);
keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding());
if (keyRef)
{
pathRef = (CFStringRef) CFPreferencesCopyAppValue(keyRef, kCFPreferencesCurrentApplication);
if (pathRef)
multiCartPath[i] = pathRef;
CFRelease(keyRef);
}
}
}
void DeinitMultiCart (void)
{
CFStringRef keyRef;
char key[32];
for (int i = 0; i < 2; i++)
{
sprintf(key, "MultiCartPath_%02d", i);
keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding());
if (keyRef)
{
if (multiCartPath[i])
{
CFPreferencesSetAppValue(keyRef, multiCartPath[i], kCFPreferencesCurrentApplication);
CFRelease(multiCartPath[i]);
}
else
CFPreferencesSetAppValue(keyRef, NULL, kCFPreferencesCurrentApplication);
CFRelease(keyRef);
}
}
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
}
Boolean MultiCartDialog (void)
{
// OSStatus err;
// IBNibRef nibRef;
//
// multiCartDragHilite = -1;
// multiCartDialogResult = false;
//
// err = CreateNibReference(kMacS9XCFString, &nibRef);
// if (err == noErr)
// {
// WindowRef window;
//
// err = CreateWindowFromNib(nibRef, CFSTR("MultiCart"), &window);
// if (err == noErr)
// {
// static int index[2] = { 0, 1 };
//
// EventHandlerRef wRef, cRef[2];
// EventHandlerUPP wUPP, cUPP[2];
// EventTypeSpec wEvent[] = { { kEventClassCommand, kEventCommandProcess },
// { kEventClassCommand, kEventCommandUpdateStatus } },
// cEvent[] = { { kEventClassControl, kEventControlDraw },
// { kEventClassControl, kEventControlDragEnter },
// { kEventClassControl, kEventControlDragWithin },
// { kEventClassControl, kEventControlDragLeave },
// { kEventClassControl, kEventControlDragReceive } };
// HIViewRef ctl, root, pane[2];
// HIViewID cid;
//
// root = HIViewGetRoot(window);
//
// wUPP = NewEventHandlerUPP(MultiCartEventHandler);
// err = InstallWindowEventHandler(window, wUPP, GetEventTypeCount(wEvent), wEvent, (void *) window, &wRef);
// err = SetAutomaticControlDragTrackingEnabledForWindow(window, true);
//
// for (int i = 0; i < 2; i++)
// {
// cid.id = i;
//
// cid.signature = 'MPan';
// HIViewFindByID(root, cid, &pane[i]);
// cUPP[i] = NewEventHandlerUPP(MultiCartPaneEventHandler);
// err = InstallControlEventHandler(pane[i], cUPP[i], GetEventTypeCount(cEvent), cEvent, (void *) &index[i], &cRef[i]);
// err = SetControlDragTrackingEnabled(pane[i], true);
//
// cid.signature = 'MNAM';
// HIViewFindByID(root, cid, &ctl);
// SetStaticTextTrunc(ctl, truncEnd, false);
// if (multiCartPath[i])
// {
// CFStringRef str;
// CFURLRef url;
//
// url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, multiCartPath[i], kCFURLPOSIXPathStyle, false);
// str = CFURLCopyLastPathComponent(url);
// SetStaticTextCFString(ctl, str, false);
// CFRelease(str);
// CFRelease(url);
// }
// else
// SetStaticTextCFString(ctl, CFSTR(""), false);
// }
//
// MoveWindowPosition(window, kWindowMultiCart, false);
// ShowWindow(window);
// err = RunAppModalLoopForWindow(window);
// HideWindow(window);
// SaveWindowPosition(window, kWindowMultiCart);
//
// for (int i = 0; i < 2; i++)
// {
// err = RemoveEventHandler(cRef[i]);
// DisposeEventHandlerUPP(cUPP[i]);
// }
//
// err = RemoveEventHandler(wRef);
// DisposeEventHandlerUPP(wUPP);
//
// CFRelease(window);
// }
//
// DisposeNibReference(nibRef);
// }
//
// return (multiCartDialogResult);
return 0;
}
static OSStatus MultiCartEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
// OSStatus err, result = eventNotHandledErr;
// WindowRef window = (WindowRef) inUserData;
// static int index = -1;
//
// switch (GetEventClass(inEvent))
// {
// case kEventClassCommand:
// {
// switch (GetEventKind(inEvent))
// {
// HICommand tHICommand;
//
// case kEventCommandUpdateStatus:
// {
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
// if (err == noErr && tHICommand.commandID == 'clos')
// {
// UpdateMenuCommandStatus(false);
// result = noErr;
// }
//
// break;
// }
//
// case kEventCommandProcess:
// {
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &tHICommand);
// if (err == noErr)
// {
// HIViewRef ctl, root;
// HIViewID cid;
// FSRef ref;
// bool8 r;
//
// root = HIViewGetRoot(window);
//
// switch (tHICommand.commandID)
// {
// case 'Cho0':
// case 'Cho1':
// {
// index = (tHICommand.commandID & 0xFF) - '0';
// // r = NavBeginOpenROMImageSheet(window, NULL);
// result = noErr;
// break;
// }
//
// case 'NvDn':
// {
// r = NavEndOpenROMImageSheet(&ref);
// if (r)
// {
// CFStringRef str;
// CFURLRef url;
//
// url = CFURLCreateFromFSRef(kCFAllocatorDefault, &ref);
// str = CFURLCopyLastPathComponent(url);
// cid.signature = 'MNAM';
// cid.id = index;
// HIViewFindByID(root, cid, &ctl);
// SetStaticTextCFString(ctl, str, true);
// CFRelease(str);
// str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
// if (multiCartPath[index])
// CFRelease(multiCartPath[index]);
// multiCartPath[index] = str;
// CFRelease(url);
// }
//
// index = -1;
// result = noErr;
// break;
// }
//
// case 'Cle0':
// case 'Cle1':
// {
// index = (tHICommand.commandID & 0xFF) - '0';
// cid.signature = 'MNAM';
// cid.id = index;
// HIViewFindByID(root, cid, &ctl);
// SetStaticTextCFString(ctl, CFSTR(""), true);
// if (multiCartPath[index])
// {
// CFRelease(multiCartPath[index]);
// multiCartPath[index] = NULL;
// }
//
// index = -1;
// result = noErr;
// break;
// }
//
// case 'SWAP':
// {
// CFStringRef str;
// CFURLRef url;
//
// str = multiCartPath[0];
// multiCartPath[0] = multiCartPath[1];
// multiCartPath[1] = str;
//
// cid.signature = 'MNAM';
//
// for (int i = 0; i < 2; i++)
// {
// cid.id = i;
// HIViewFindByID(root, cid, &ctl);
//
// if (multiCartPath[i])
// {
// url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, multiCartPath[i], kCFURLPOSIXPathStyle, false);
// str = CFURLCopyLastPathComponent(url);
// SetStaticTextCFString(ctl, str, true);
// CFRelease(str);
// CFRelease(url);
// }
// else
// SetStaticTextCFString(ctl, CFSTR(""), true);
// }
//
// result = noErr;
// break;
// }
//
// case 'ok ':
// {
// QuitAppModalLoopForWindow(window);
// multiCartDialogResult = true;
// result = noErr;
// break;
// }
//
// case 'not!':
// {
// QuitAppModalLoopForWindow(window);
// multiCartDialogResult = false;
// result = noErr;
// break;
// }
// }
// }
// }
// }
// }
// }
//
// return (result);
return 0;
}
static OSStatus MultiCartPaneEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData)
{
// OSStatus err, result = eventNotHandledErr;
// HIViewRef view;
// DragRef drag;
// PasteboardRef pasteboard;
// PasteboardItemID itemID;
// CFArrayRef array;
// CFStringRef flavorType;
// CFIndex numFlavors;
// ItemCount numItems;
// int index = *((int *) inUserData);
//
// switch (GetEventClass(inEvent))
// {
// case kEventClassControl:
// {
// switch (GetEventKind(inEvent))
// {
// case kEventControlDraw:
// {
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view);
// if (err == noErr)
// {
// CGContextRef ctx;
//
// err = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &ctx);
// if (err == noErr)
// {
// HIThemeFrameDrawInfo info;
// HIRect bounds, frame;
//
// HIViewGetBounds(view, &bounds);
//
// CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f);
// CGContextFillRect(ctx, bounds);
//
// info.version = 0;
// info.kind = kHIThemeFrameTextFieldSquare;
// info.state = kThemeStateInactive;
// info.isFocused = false;
// err = HIThemeDrawFrame(&bounds, &info, ctx, kHIThemeOrientationNormal);
//
// if (multiCartDragHilite == index && systemVersion >= 0x1040)
// {
// err = HIThemeSetStroke(kThemeBrushDragHilite, NULL, ctx, kHIThemeOrientationNormal);
// frame = CGRectInset(bounds, 1, 1);
// CGContextBeginPath(ctx);
// CGContextAddRect(ctx, frame);
// CGContextStrokePath(ctx);
// }
// }
// }
//
// result = noErr;
// break;
// }
//
// case kEventControlDragEnter:
// {
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view);
// if (err == noErr)
// {
// err = GetEventParameter(inEvent, kEventParamDragRef, typeDragRef, NULL, sizeof(DragRef), NULL, &drag);
// if (err == noErr)
// {
// err = GetDragPasteboard(drag, &pasteboard);
// if (err == noErr)
// {
// err = PasteboardGetItemCount(pasteboard, &numItems);
// if (err == noErr && numItems == 1)
// {
// err = PasteboardGetItemIdentifier(pasteboard, 1, &itemID);
// if (err == noErr)
// {
// err = PasteboardCopyItemFlavors(pasteboard, itemID, &array);
// if (err == noErr)
// {
// numFlavors = CFArrayGetCount(array);
// for (CFIndex i = 0; i < numFlavors; i++)
// {
// flavorType = (CFStringRef) CFArrayGetValueAtIndex(array, i);
// if (UTTypeConformsTo(flavorType, CFSTR("public.file-url")))
// {
// Boolean accept = true;
//
// err = SetEventParameter(inEvent, kEventParamControlWouldAcceptDrop, typeBoolean, sizeof(Boolean), &accept);
// if (err == noErr)
// {
// multiCartDragHilite = index;
// HIViewSetNeedsDisplay(view, true);
// result = noErr;
// }
// }
// }
//
// CFRelease(array);
// }
// }
// }
// }
// }
// }
//
// break;
// }
//
// case kEventControlDragWithin:
// {
// result = noErr;
// break;
// }
//
// case kEventControlDragLeave:
// {
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view);
// if (err == noErr)
// {
// multiCartDragHilite = -1;
// HIViewSetNeedsDisplay(view, true);
// }
//
// result = noErr;
// break;
// }
//
// case kEventControlDragReceive:
// {
// err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view);
// if (err == noErr)
// {
// err = GetEventParameter(inEvent, kEventParamDragRef, typeDragRef, NULL, sizeof(DragRef), NULL, &drag);
// if (err == noErr)
// {
// multiCartDragHilite = -1;
// HIViewSetNeedsDisplay(view, true);
//
// err = GetDragPasteboard(drag, &pasteboard);
// if (err == noErr)
// {
// err = PasteboardGetItemIdentifier(pasteboard, 1, &itemID);
// if (err == noErr)
// {
// err = PasteboardCopyItemFlavors(pasteboard, itemID, &array);
// if (err == noErr)
// {
// numFlavors = CFArrayGetCount(array);
// for (CFIndex i = 0; i < numFlavors; i++)
// {
// flavorType = (CFStringRef) CFArrayGetValueAtIndex(array, i);
// if (UTTypeConformsTo(flavorType, CFSTR("public.file-url")))
// {
// CFDataRef flavorData;
//
// err = PasteboardCopyItemFlavorData(pasteboard, itemID, flavorType, &flavorData);
// if (err == noErr)
// {
// CFIndex dataSize;
// UInt8 *data;
//
// dataSize = CFDataGetLength(flavorData);
// data = (UInt8 *) malloc(dataSize);
// if (data)
// {
// CFDataGetBytes(flavorData, CFRangeMake(0, dataSize), data);
//
// HIViewRef ctl;
// HIViewID cid;
// CFStringRef str;
// CFURLRef url;
//
// GetControlID(view, &cid);
// cid.signature = 'MNAM';
// HIViewFindByID(view, cid, &ctl);
//
// url = CFURLCreateWithBytes(kCFAllocatorDefault, data, dataSize, kCFStringEncodingUTF8, NULL);
// str = CFURLCopyLastPathComponent(url);
// SetStaticTextCFString(ctl, str, true);
// CFRelease(str);
// str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
// if (multiCartPath[cid.id])
// CFRelease(multiCartPath[cid.id]);
// multiCartPath[cid.id] = str;
// CFRelease(url);
//
// result = noErr;
//
// free(data);
// }
//
// CFRelease(flavorData);
// }
// }
// }
//
// CFRelease(array);
// }
// }
// }
// }
// }
// }
// }
// }
// }
//
// return (result);
return 0;
}

View File

@ -122,7 +122,7 @@ static void * SoundTask (void *);
MacStartSound();
pthread_create(&mbxThread, NULL, SoundTask, NULL);
timer = [[NSTimer scheduledTimerWithTimeInterval: (2.0 / (double) Memory.ROMFramesPerSecond) target: self selector: @selector(updateIndicator:) userInfo: nil repeats: YES] retain];
timer = [NSTimer scheduledTimerWithTimeInterval: (2.0 / (double) Memory.ROMFramesPerSecond) target: self selector: @selector(updateIndicator:) userInfo: nil repeats: YES];
return (self);
}
@ -134,7 +134,7 @@ static void * SoundTask (void *);
BOOL r;
[timer invalidate];
[timer release];
timer = nil;
showIndicator = false;
@ -159,10 +159,6 @@ static void * SoundTask (void *);
SPCPlayDefrost();
else
MusicBoxForceDefrost();
[window release];
[super dealloc];
}
- (NSWindow *) window
@ -268,7 +264,7 @@ static void * SoundTask (void *);
const float length[] = { 1.0f, 1.0f };
CGContextSetLineWidth(mboxctx, mbxBarWidth);
CGContextSetLineDash(mboxctx, 0, length, 2);
//CGContextSetLineDash(mboxctx, 0, length, 2);
CGContextSetLineJoin(mboxctx, kCGLineJoinMiter);
CGContextBeginPath(mboxctx);
@ -457,21 +453,14 @@ static void SPCPlayDefrost (void)
void MusicBoxDialog (void)
{
MusicBoxController *controller;
NSAutoreleasePool *pool;
if (!cartOpen)
return;
pool = [[NSAutoreleasePool alloc] init];
controller = [[MusicBoxController alloc] init];
[pool release];
if (!controller)
return;
[NSApp runModalForWindow: [controller window]];
pool = [[NSAutoreleasePool alloc] init];
[controller release];
[pool release];
}

View File

@ -125,7 +125,6 @@ extern int macFrameSkip;
extern int32 skipFrames;
extern int64 lastFrame;
extern unsigned long spcFileCount, pngFileCount;
extern SInt32 systemVersion;
extern bool8 finished, cartOpen,
autofire, hidExist, directDisplay;
extern bool8 fullscreen, autoRes,
@ -138,7 +137,7 @@ extern uint32 macSoundBuffer_ms, macSoundInterval_ms;
extern bool8 macSoundLagEnable;
extern uint16 aueffect;
extern uint8 saveInROMFolder;
extern CFStringRef saveFolderPath;
extern NSString *saveFolderPath;
extern int macCurvatureWarp, macAspectRatio;
extern int macFastForwardRate, macFrameAdvanceRate;
extern int inactiveMode;
@ -159,18 +158,15 @@ extern CFStringRef multiCartPath[2];
extern IconRef macIconRef[118];
#endif
void InitGameWindow (void);
void DeinitGameWindow (void);
void UpdateGameWindow (void);
void AddRecentItem (FSRef *);
void BuildRecentMenu (void);
void AddRecentItem (NSURL *);
void AdjustMenus (void);
void UpdateMenuCommandStatus (Boolean);
void ApplyNSRTHeaderControllers (void);
void QuitWithFatalError (OSStatus, const char *);
void QuitWithFatalError (NSString *);
void ChangeInputDevice (void);
void GetGameScreenPointer (int16 *, int16 *, bool);
void PostQueueToSubEventLoop (void);
int PromptFreezeDefrost (Boolean);
uint64 GetMicroseconds();
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1594
macosx/mac-prefs.mm Executable file

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,6 @@
#include "mac-cheatfinder.h"
#include "mac-coreimage.h"
#include "mac-os.h"
#include "mac-quicktime.h"
#include "mac-screenshot.h"
#include "mac-render.h"
@ -197,13 +196,13 @@ void InitGraphics (void)
GFX.Screen = gfxScreen[0];
if (!snesScreenA || !snesScreenB || !blitGLBuffer)
QuitWithFatalError(0, "render 01");
QuitWithFatalError(@"render 01");
if (!S9xBlitFilterInit() |
!S9xBlit2xSaIFilterInit() |
!S9xBlitHQ2xFilterInit() |
!S9xBlitNTSCFilterInit())
QuitWithFatalError(0, "render 02");
QuitWithFatalError(@"render 02");
switch (videoMode)
{
@ -406,8 +405,6 @@ static void SetBestDisplayMode (int width, int height)
static void S9xInitFullScreen (void)
{
DeinitGameWindow();
size_t width, height;
width = autoRes ? 640 : CGDisplayPixelsWide(gGameDisplayID);
@ -485,13 +482,13 @@ static void S9xInitWindowMode (void)
SetBestDisplayMode(width, height);
#endif
InitGameWindow();
ShowWindow(gWindow);
// InitGameWindow();
// ShowWindow(gWindow);
//
// GetWindowBounds(gWindow, kWindowContentRgn, &rct);
// gWindowRect = CGRectMake((float) rct.left, (float) rct.top, (float) (rct.right - rct.left), (float) (rct.bottom - rct.top));
GetWindowBounds(gWindow, kWindowContentRgn, &rct);
gWindowRect = CGRectMake((float) rct.left, (float) rct.top, (float) (rct.right - rct.left), (float) (rct.bottom - rct.top));
UpdateGameWindow();
// UpdateGameWindow();
}
static void S9xDeinitWindowMode (void)
@ -505,7 +502,7 @@ static void S9xDeinitWindowMode (void)
CGDisplayModeRelease(oldDisplayModeRef);
#endif
UpdateGameWindow();
// UpdateGameWindow();
}
static void S9xInitOpenGLFullScreen (void)
@ -565,12 +562,7 @@ static void S9xInitOpenGLWindowMode (void)
aglpix = aglChoosePixelFormat(NULL, 0, attribs);
agContext = aglCreateContext(aglpix, NULL);
if (systemVersion >= 0x1050)
aglSetWindowRef(agContext, gWindow);
#ifdef MAC_TIGER_PANTHER_SUPPORT
else
aglSetDrawable(agContext, GetWindowPort(gWindow));
#endif
aglSetWindowRef(agContext, gWindow);
agSwapInterval = vsync ? 1 : 0;
if (extraOptions.benchmark)
@ -578,23 +570,15 @@ static void S9xInitOpenGLWindowMode (void)
aglSetInteger(agContext, AGL_SWAP_INTERVAL, &agSwapInterval);
aglSetCurrentContext(agContext);
if (systemVersion >= 0x1040)
{
aglGetCGLPixelFormat(aglpix, (void **) &cglpix);
aglGetCGLContext(agContext, (void **) &glContext);
}
aglGetCGLPixelFormat(aglpix, (void **) &cglpix);
aglGetCGLContext(agContext, (void **) &glContext);
}
static void S9xDeinitOpenGLWindowMode (void)
{
if (agContext)
{
if (systemVersion >= 0x1050)
aglSetWindowRef(agContext, NULL);
#ifdef MAC_TIGER_PANTHER_SUPPORT
else
aglSetDrawable(agContext, NULL);
#endif
aglSetWindowRef(agContext, NULL);
aglSetCurrentContext(NULL);
aglDestroyContext(agContext);

View File

@ -118,7 +118,7 @@ CGImageRef CreateGameScreenCGImage (void)
color = CGColorSpaceCreateDeviceRGB();
if (color)
{
image = CGImageCreate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, 5, 16, rowbytes, color, kCGImageAlphaNoneSkipFirst | ((systemVersion >= 0x1040) ? kCGBitmapByteOrder16Host : 0), prov, NULL, 1, kCGRenderingIntentDefault);
image = CGImageCreate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, 5, 16, rowbytes, color, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host, prov, NULL, 1, kCGRenderingIntentDefault);
CGColorSpaceRelease(color);
}
@ -140,7 +140,7 @@ CGImageRef CreateBlitScreenCGImage (int width, int height, int rowbytes, uint8 *
color = CGColorSpaceCreateDeviceRGB();
if (color)
{
image = CGImageCreate(width, height, 5, 16, rowbytes, color, kCGImageAlphaNoneSkipFirst | ((systemVersion >= 0x1040) ? kCGBitmapByteOrder16Host : 0), prov, NULL, 1, kCGRenderingIntentDefault);
image = CGImageCreate(width, height, 5, 16, rowbytes, color, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host, prov, NULL, 1, kCGRenderingIntentDefault);
CGColorSpaceRelease(color);
}

View File

@ -58,7 +58,7 @@ void SNES9X_Reset (void);
void SNES9X_SoftReset (void);
void SNES9X_Quit (void);
void SNES9X_InitSound (void);
bool8 SNES9X_OpenCart (FSRef *);
bool8 SNES9X_OpenCart (NSURL *);
bool8 SNES9X_OpenMultiCart (void);
bool8 SNES9X_Freeze (void);
bool8 SNES9X_FreezeTo (void);

View File

@ -37,7 +37,6 @@
#include "mac-file.h"
#include "mac-multicart.h"
#include "mac-os.h"
#include "mac-quicktime.h"
#include "mac-screenshot.h"
#include "mac-stringtools.h"
#include "mac-snes9x.h"
@ -51,13 +50,10 @@ void SNES9X_Go (void)
running = true;
}
bool8 SNES9X_OpenCart (FSRef *inRef)
bool8 SNES9X_OpenCart (NSURL *inRef)
{
OSStatus err;
FSRef cartRef;
char filename[PATH_MAX + 1];
DeinitGameWindow();
NSURL *cartRef;
const char *filename = inRef.lastPathComponent.UTF8String;
if (cartOpen)
{
@ -70,18 +66,19 @@ bool8 SNES9X_OpenCart (FSRef *inRef)
if (!inRef)
{
if (!NavOpenROMImage(&cartRef))
cartRef = NavOpenROMImage();
if (!cartRef)
{
cartOpen = false;
return (false);
}
}
else
cartRef = *inRef;
cartRef = inRef;
spcFileCount = pngFileCount = 0;
CheckSaveFolder(&cartRef);
CheckSaveFolder(cartRef);
Settings.ForceLoROM = (romDetect == kLoROMForce );
Settings.ForceHiROM = (romDetect == kHiROMForce );
@ -99,8 +96,6 @@ bool8 SNES9X_OpenCart (FSRef *inRef)
S9xResetSaveTimer(true);
err = FSRefMakePath(&cartRef, (unsigned char *) filename, PATH_MAX);
SNES9X_InitSound();
if (Memory.LoadROM(filename))
@ -111,8 +106,8 @@ bool8 SNES9X_OpenCart (FSRef *inRef)
ChangeTypeAndCreator(filename, 'CART', '~9X~');
AddRecentItem(&cartRef);
BuildRecentMenu();
AddRecentItem(cartRef);
//BuildRecentMenu();
ApplyNSRTHeaderControllers();
@ -134,8 +129,6 @@ bool8 SNES9X_OpenMultiCart (void)
Boolean r;
char cart[2][PATH_MAX + 1];
DeinitGameWindow();
if (cartOpen)
{
SNES9X_SaveSRAM();
@ -306,12 +299,12 @@ bool8 SNES9X_Defrost (void)
bool8 SNES9X_FreezeTo (void)
{
char filename[PATH_MAX + 1];
if (cartOpen)
{
if (NavFreezeTo(filename))
NSURL *url = NavFreezeTo();
if (url != nil)
{
const char *filename = url.lastPathComponent.UTF8String;
unlink(filename);
S9xFreezeGame(filename);
@ -331,8 +324,10 @@ bool8 SNES9X_DefrostFrom (void)
if (cartOpen)
{
if (NavDefrostFrom(filename))
NSURL *url = NavDefrostFrom();
if (url != nil)
{
const char *filename = url.lastPathComponent.UTF8String;
S9xUnfreezeGame(filename);
SNES9X_Go();
@ -346,12 +341,12 @@ bool8 SNES9X_DefrostFrom (void)
bool8 SNES9X_RecordMovie (void)
{
char filename[PATH_MAX + 1];
if (cartOpen)
{
if (NavRecordMovieTo(filename))
NSURL *url = NavRecordMovieTo();
if (url != nil)
{
const char *filename = url.lastPathComponent.UTF8String;
unlink(filename);
int r;
@ -392,8 +387,10 @@ bool8 SNES9X_PlayMovie (void)
if (cartOpen)
{
if (NavPlayMovieFrom(filename))
NSURL *url = NavPlayMovieFrom();
if (url != nil)
{
const char *filename = url.lastPathComponent.UTF8String;
int r;
r = S9xMovieOpen(filename, macPlayFlag & 1);
@ -415,9 +412,10 @@ bool8 SNES9X_QTMovieRecord (void)
if (cartOpen)
{
if (NavQTMovieRecordTo(filename))
NSURL *url = NavQTMovieRecordTo();
if (url != nil)
{
MacQTStartRecording(filename);
const char *filename = url.lastPathComponent.UTF8String;
macQTRecord = true;
SNES9X_Go();
@ -432,8 +430,6 @@ bool8 SNES9X_QTMovieRecord (void)
void SNES9X_Quit (void)
{
DeinitGameWindow();
if (cartOpen)
{
SNES9X_SaveSRAM();

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
</plist>

View File

@ -0,0 +1,18 @@
//
// snes9x_framework.h
// snes9x framework
//
// Created by Buckley on 7/4/19.
//
#import <Cocoa/Cocoa.h>
//! Project version number for snes9x_framework.
FOUNDATION_EXPORT double snes9x_frameworkVersionNumber;
//! Project version string for snes9x_framework.
FOUNDATION_EXPORT const unsigned char snes9x_frameworkVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <snes9x_framework/PublicHeader.h>

File diff suppressed because it is too large Load Diff