diff --git a/src/tools/aueffectutil-Info.plist b/src/tools/aueffectutil-Info.plist
deleted file mode 100644
index e509415..0000000
--- a/src/tools/aueffectutil-Info.plist
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-
-
- CFBundleDisplayName
- AUEffectUtil
- CFBundleDocumentTypes
-
-
- CFBundleTypeExtensions
-
- aueffect
-
- CFBundleTypeName
- AUEffect
- CFBundleTypeOSTypes
-
- CFBundleTypeRole
- Editor
- NSDocumentClass
- AUEffectDocument
-
-
- CFBundleTypeExtensions
-
- aupreset
-
- CFBundleTypeName
- AudioUnit Preset
- CFBundleTypeOSTypes
-
- CFBundleTypeRole
- Editor
- NSDocumentClass
- AUEffectDocument
-
-
- CFBundleIdentifier
- org.mamedev.aueffectutil
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundleName
- AUEffectUtil
-
-
diff --git a/src/tools/aueffectutil.mm b/src/tools/aueffectutil.mm
deleted file mode 100644
index 661800a..0000000
--- a/src/tools/aueffectutil.mm
+++ /dev/null
@@ -1,1076 +0,0 @@
-// license:BSD-3-Clause
-// copyright-holders:Vas Crabb
-#import
-#import
-#import
-#import
-#import
-#import
-#import
-#import
-#import
-
-#include
-#include
-
-#include
-
-
-#ifdef MAC_OS_X_VERSION_MAX_ALLOWED
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
-
-typedef ComponentDescription AudioComponentDescription;
-
-@protocol NSApplicationDelegate
-@end
-
-@protocol NSWindowDelegate
-@end
-
-#endif // MAC_OS_X_VERSION_MAX_ALLOWED < 1060
-
-#endif // MAC_OS_X_VERSION_MAX_ALLOWED
-
-
-struct EffectInfo
-{
- Component component;
- OSType type;
- OSType subtype;
- OSType manufacturer;
-};
-
-
-static NSString *const AUEffectUtilErrorDomain = @"AUEffectUtilErrorDomain";
-
-static NSString *const AUEffectDocumentType = @"AUEffect";
-static NSString *const AUPresetDocumentType = @"AudioUnit Preset";
-
-static NSString *const ComponentTypeKey = @"ComponentType";
-static NSString *const ComponentSubTypeKey = @"ComponentSubType";
-static NSString *const ComponentManufacturerKey = @"ComponentManufacturer";
-static NSString *const ClassInfoKey = @"ClassInfo";
-static NSString *const ForceGenericViewKey = @"ForceGenericView";
-static NSString *const WindowFrameKey = @"WindowFrame";
-
-
-static void UpdateChangeCountCallback(
- void *userData,
- void *object,
- AudioUnitEvent const *inEvent,
- UInt64 inEventHostTime,
- AudioUnitParameterValue inParameterValue)
-{
- [(NSDocument *)userData updateChangeCount:NSChangeDone];
-}
-
-
-@interface AUEffectDocument : NSDocument
-{
- IBOutlet NSWindow *window;
- IBOutlet NSButton *genericViewButton;
- IBOutlet NSPopUpButton *presetButton;
- NSView *view;
- NSSize headerSize;
- CFArrayRef presets;
- AUParameterListenerRef listener;
- BOOL forceGenericView;
- NSString *restoreFrame;
-
- AudioComponentDescription description;
- AUGraph graph;
- AUNode outputNode, sourceNode, effectNode;
- AudioUnit outputUnit, sourceUnit, effectUnit;
-}
-
-- (void)dealloc;
-
-- (void)makeWindowControllers;
-- (BOOL)readFromData:(NSData *)data ofType:(NSString *)type error:(NSError **)error;
-- (NSData *)dataOfType:(NSString *)type error:(NSError **)error;
-
-- (IBAction)toggleGenericView:(id)sender;
-- (IBAction)loadPreset:(id)sender;
-
-- (void)viewFrameDidChange:(NSNotification *)notification;
-
-@end
-
-@implementation AUEffectDocument
-
-- (void)loadEffectUI {
- if ((0 == effectNode) || !window)
- return;
-
- BOOL customViewValid = NO;
- OSStatus status;
- UInt32 uiDescSize;
- AudioUnitCocoaViewInfo *viewInfo;
- status = AudioUnitGetPropertyInfo(
- effectUnit,
- kAudioUnitProperty_CocoaUI,
- kAudioUnitScope_Global,
- 0,
- &uiDescSize,
- NULL);
- UInt32 const uiClassCount = 1 + ((uiDescSize - sizeof(*viewInfo)) / sizeof(viewInfo->mCocoaAUViewClass[0]));
- if ((noErr == status) && (0 < uiClassCount))
- {
- viewInfo = (AudioUnitCocoaViewInfo *)malloc(uiDescSize);
- status = AudioUnitGetProperty(effectUnit,
- kAudioUnitProperty_CocoaUI,
- kAudioUnitScope_Global,
- 0,
- viewInfo,
- &uiDescSize);
- if (noErr == status)
- {
- NSBundle *const bundle = [NSBundle bundleWithPath:[(NSURL *)viewInfo->mCocoaAUViewBundleLocation path]];
- Class const viewClass = [bundle classNamed:(NSString *)viewInfo->mCocoaAUViewClass[0]];
- if (viewClass
- && [viewClass conformsToProtocol:@protocol(AUCocoaUIBase)]
- && [viewClass instancesRespondToSelector:@selector(uiViewForAudioUnit:withSize:)])
- {
- customViewValid = YES;
- if (!forceGenericView)
- {
- id const factory = [[viewClass alloc] init];
- view = [factory uiViewForAudioUnit:effectUnit
- withSize:[[window contentView] bounds].size];
- [factory release];
- }
- }
- CFRelease(viewInfo->mCocoaAUViewBundleLocation);
- for (UInt32 i = 0; i < uiClassCount; i++)
- CFRelease(viewInfo->mCocoaAUViewClass[i]);
- }
- free(viewInfo);
- }
- if (!view)
- {
- view = [[[AUGenericView alloc] initWithAudioUnit:effectUnit] autorelease];
- [(AUGenericView *)view setShowsExpertParameters:YES];
- }
-
- [view setAutoresizingMask:NSViewNotSizable];
- [view setFrameOrigin:NSMakePoint(0, 0)];
- NSRect const oldFrame = [window frame];
- NSRect const desired = [window frameRectForContentRect:[view frame]];
- NSRect const newFrame = NSMakeRect(oldFrame.origin.x,
- oldFrame.origin.y + oldFrame.size.height - headerSize.height - desired.size.height,
- desired.size.width,
- headerSize.height + desired.size.height);
- [window setFrame:newFrame display:YES animate:NO];
- [[window contentView] addSubview:view];
- [view setPostsFrameChangedNotifications:YES];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(viewFrameDidChange:)
- name:NSViewFrameDidChangeNotification
- object:view];
-
- [genericViewButton setEnabled:customViewValid];
- if (!customViewValid)
- {
- forceGenericView = YES;
- [genericViewButton setState:NSOnState];
- }
-
- CFIndex const presetCount = (NULL != presets) ? CFArrayGetCount(presets) : 0;
- [presetButton setEnabled:(0 < presetCount)];
- while (1 < [presetButton numberOfItems])
- [presetButton removeItemAtIndex:1];
- for (CFIndex i = 0; i < presetCount; i++)
- {
- AUPreset const *preset = (AUPreset const*)CFArrayGetValueAtIndex(presets, i);
- NSMenuItem const *item = [[presetButton menu] addItemWithTitle:(NSString *)preset->presetName
- action:@selector(loadPreset:)
- keyEquivalent:@""];
- [item setTarget:self];
- [item setTag:i];
- }
-}
-
-- (id)init {
- if (!(self = [super init]))
- return nil;
-
- window = nil;
- genericViewButton = nil;
- presetButton = nil;
- view = nil;
- presets = NULL;
- listener = NULL;
- forceGenericView = NO;
- restoreFrame = nil;
-
- description.componentType = description.componentSubType = description.componentManufacturer = 0;
- description.componentFlags = description.componentFlagsMask = 0;
- graph = NULL;
- outputNode = sourceNode = effectNode = 0;
-
- AudioComponentDescription const outputDesc = { kAudioUnitType_Output,
- kAudioUnitSubType_DefaultOutput,
- kAudioUnitManufacturer_Apple,
- 0,
- 0, };
- AudioComponentDescription const sourceDesc = { kAudioUnitType_Generator,
- kAudioUnitSubType_AudioFilePlayer,
- kAudioUnitManufacturer_Apple,
- 0,
- 0, };
- if ((noErr != NewAUGraph(&graph))
- || (noErr != AUGraphAddNode(graph, &outputDesc, &outputNode))
- || (noErr != AUGraphAddNode(graph, &sourceDesc, &sourceNode))
- || (noErr != AUGraphOpen(graph))
- || (noErr != AUGraphNodeInfo(graph, outputNode, NULL, &outputUnit))
- || (noErr != AUGraphNodeInfo(graph, sourceNode, NULL, &sourceUnit))
- || (noErr != AUGraphInitialize(graph)))
- {
- [self release];
- return nil;
- }
-
- return self;
-}
-
-- (void)dealloc {
- if (presets)
- CFRelease(presets);
-
- if (listener)
- AUListenerDispose(listener);
-
- if (restoreFrame)
- [restoreFrame release];
-
- if (graph)
- {
- AUGraphClose(graph);
- DisposeAUGraph(graph);
- }
-
- [super dealloc];
-}
-
-- (void)makeWindowControllers {
- genericViewButton = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 100, 18)];
- [genericViewButton setAutoresizingMask:NSViewNotSizable];
- [[genericViewButton cell] setControlSize:NSSmallControlSize];
- [genericViewButton setButtonType:NSSwitchButton];
- [genericViewButton setBordered:NO];
- [genericViewButton setAllowsMixedState:NO];
- [genericViewButton setState:(forceGenericView ? NSOnState : NSOffState)];
- [genericViewButton setTitle:@"Use generic editor view"];
- [genericViewButton setAction:@selector(toggleGenericView:)];
- [genericViewButton setTarget:self];
- [genericViewButton sizeToFit];
-
- presetButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 100, 22) pullsDown:YES];
- [presetButton setAutoresizingMask:NSViewNotSizable];
- [[presetButton cell] setControlSize:NSSmallControlSize];
- [[presetButton cell] setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
- [presetButton setTitle:@"Load preset"];
- [[[presetButton menu] addItemWithTitle:@"Load preset" action:NULL keyEquivalent:@""] setHidden:YES];
- [presetButton sizeToFit];
-
- CGFloat const controlWidth = MAX(NSWidth([genericViewButton frame]), NSWidth([presetButton frame]));
- NSRect const presetFrame = NSMakeRect(
- 17,
- 8,
- controlWidth,
- NSHeight([presetButton frame]));
- NSRect const genericViewFrame = NSMakeRect(
- 17,
- NSMaxY(presetFrame) + 9,
- controlWidth,
- NSHeight([genericViewButton frame]));
- [genericViewButton setFrame:genericViewFrame];
- [presetButton setFrame:presetFrame];
-
- headerSize = NSMakeSize((2 * 17) + controlWidth, 18 + NSMaxY(genericViewFrame));
- NSView *const container = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, headerSize.width, headerSize.height)];
- [container setAutoresizingMask:(NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin)];
- [container addSubview:genericViewButton];
- [genericViewButton release];
- [container addSubview:presetButton];
- [presetButton release];
-
- window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, headerSize.width, headerSize.height)
- styleMask:(NSTitledWindowMask |
- NSClosableWindowMask |
- NSMiniaturizableWindowMask)
- backing:NSBackingStoreBuffered
- defer:YES];
- [window setReleasedWhenClosed:NO];
- [window setDelegate:self];
- [window setTitle:@"Effect"];
- [[window contentView] addSubview:container];
- [container release];
- [self setWindow:window];
-
- NSWindowController *const controller = [[NSWindowController alloc] initWithWindow:window];
- [self addWindowController:controller];
- [controller release];
- [window release];
-
- [self loadEffectUI];
- if (restoreFrame)
- {
- [window setFrameFromString:restoreFrame];
- }
- else
- {
- NSRect const available = [[NSScreen mainScreen] visibleFrame];
- NSRect frame = [window frame];
- frame.origin.x = (NSWidth(available) - NSWidth(frame)) / 4;
- frame.origin.y = (NSHeight(available) - NSHeight(frame)) * 3 / 4;
- [window setFrame:frame display:YES animate:NO];
- }
-}
-
-- (BOOL)readFromData:(NSData *)data ofType:(NSString *)type error:(NSError **)error {
- OSStatus status;
- UInt32 propertySize;
-
- BOOL const hasWrapper = [type isEqualToString:AUEffectDocumentType];
- if (!hasWrapper && ![type isEqualToString:AUPresetDocumentType])
- {
- if (error)
- {
- NSString *const message = [NSString stringWithFormat:@"Unsupported document type %@", type];
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- return NO;
- }
-
- NSString *errDesc = nil;
- id const desc = [NSPropertyListSerialization propertyListFromData:data
- mutabilityOption:0
- format:NULL
- errorDescription:&errDesc];
- if (!desc || ![desc isKindOfClass:[NSDictionary class]] || errDesc)
- {
- if (error)
- {
- NSString *const message = [NSString stringWithFormat:@"Error in file format (%@)", errDesc];
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- if (errDesc)
- [errDesc release];
- return NO;
- }
-
- id const typeValue = [desc objectForKey:(hasWrapper ? ComponentTypeKey : (NSString *)CFSTR(kAUPresetTypeKey))];
- id const subtypeValue = [desc objectForKey:(hasWrapper ? ComponentSubTypeKey : (NSString *)CFSTR(kAUPresetSubtypeKey))];
- id const manufacturerValue = [desc objectForKey:(hasWrapper ? ComponentManufacturerKey : (NSString *)CFSTR(kAUPresetManufacturerKey))];
- if (!typeValue || ![typeValue isKindOfClass:[NSNumber class]]
- || !subtypeValue || ![subtypeValue isKindOfClass:[NSNumber class]]
- || !manufacturerValue || ![manufacturerValue isKindOfClass:[NSNumber class]]
- || ([typeValue unsignedLongValue] != kAudioUnitType_Effect))
- {
- if (error)
- {
- NSString *const message = @"Error in effect description file format";
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- return NO;
- }
-
- if (presets)
- {
- CFRelease(presets);
- presets = NULL;
- }
- if (listener)
- {
- AUListenerDispose(listener);
- listener = NULL;
- }
- if (view)
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:NSViewFrameDidChangeNotification
- object:nil];
- [view removeFromSuperview];
- view = nil;
- }
- if (0 != effectNode)
- {
- view = nil;
- AUGraphRemoveNode(graph, effectNode);
- effectNode = 0;
- }
-
- description.componentType = [typeValue longValue];
- description.componentSubType = [subtypeValue longValue];
- description.componentManufacturer = [manufacturerValue longValue];
- status = noErr;
- status = AUGraphClearConnections(graph);
- if (noErr == status)
- status = AUGraphAddNode(graph, &description, &effectNode);
- if (noErr == status)
- status = AUGraphNodeInfo(graph, effectNode, NULL, &effectUnit);
- if (noErr == status)
- status = AUGraphConnectNodeInput(graph, sourceNode, 0, effectNode, 0);
- if (noErr == status)
- status = AUGraphConnectNodeInput(graph, effectNode, 0, outputNode, 0);
- if (noErr == status)
- status = AUGraphUpdate(graph, NULL);
- if (noErr != status)
- {
- if (error)
- {
- NSString * const message = @"Error encountered while configuring AudioUnit graph";
- NSError *const underlying = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- underlying, NSUnderlyingErrorKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- return NO;
- }
-
- CFPropertyListRef const classInfo = (CFPropertyListRef)(hasWrapper ? [desc objectForKey:ClassInfoKey] : desc);
- if (classInfo)
- {
- AudioUnitParameter change = { effectUnit, kAUParameterListener_AnyParameter, 0, 0 };
- status = AudioUnitSetProperty(
- effectUnit,
- kAudioUnitProperty_ClassInfo,
- kAudioUnitScope_Global,
- 0,
- &classInfo,
- sizeof(classInfo));
- if (noErr == status)
- status = AUParameterListenerNotify(NULL, NULL, &change);
- if (noErr != status)
- {
- if (error)
- {
- NSString * const message = @"Error configuring effect";
- NSError *const underlying = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- underlying, NSUnderlyingErrorKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- return NO;
- }
- }
-
- propertySize = 0;
- status = AudioUnitGetPropertyInfo(
- effectUnit,
- kAudioUnitProperty_ParameterList,
- kAudioUnitScope_Global,
- 0,
- &propertySize,
- NULL);
- if (noErr != status)
- {
- if (error)
- {
- NSString * const message = @"Error getting effect parameters";
- NSError *const underlying = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- underlying, NSUnderlyingErrorKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- return NO;
- }
- UInt32 const paramCount = propertySize / sizeof(AudioUnitParameterID);
- if (0U < paramCount)
- {
- status = AUEventListenerCreate(
- UpdateChangeCountCallback,
- self,
- CFRunLoopGetCurrent(),
- kCFRunLoopDefaultMode,
- 0.05,
- 0.05,
- &listener);
- if (noErr != status)
- {
- if (error)
- {
- NSString * const message = @"Error creating AudioUnit event listener";
- NSError *const underlying = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- underlying, NSUnderlyingErrorKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- return NO;
- }
- AudioUnitParameterID *const params = (AudioUnitParameterID *)malloc(propertySize);
- AudioUnitGetProperty(
- effectUnit,
- kAudioUnitProperty_ParameterList,
- kAudioUnitScope_Global,
- 0,
- params,
- &propertySize);
- if (noErr != status)
- {
- free(params);
- if (error)
- {
- NSString * const message = @"Error getting effect parameters";
- NSError *const underlying = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- underlying, NSUnderlyingErrorKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- return NO;
- }
- for (UInt32 i = 0; (i < paramCount) && (noErr == status); i++)
- {
- AudioUnitEvent event;
- event.mEventType = kAudioUnitEvent_ParameterValueChange;
- event.mArgument.mParameter.mAudioUnit = effectUnit;
- event.mArgument.mParameter.mParameterID = params[i];
- event.mArgument.mParameter.mScope = kAudioUnitScope_Global;
- event.mArgument.mParameter.mElement = 0;
- status = AUEventListenerAddEventType(listener, self, &event);
- }
- free(params);
- if (noErr != status)
- {
- free(params);
- if (error)
- {
- NSString * const message = @"Error getting effect parameters";
- NSError *const underlying = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- underlying, NSUnderlyingErrorKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- return NO;
- }
- }
-
- propertySize = sizeof(presets);
- status = AudioUnitGetProperty(
- effectUnit,
- kAudioUnitProperty_FactoryPresets,
- kAudioUnitScope_Global,
- 0,
- &presets,
- &propertySize);
- if ((noErr != status) && presets)
- {
- CFRelease(presets);
- presets = NULL;
- }
-
- if (hasWrapper)
- {
- if ([desc objectForKey:ForceGenericViewKey]
- && [[desc objectForKey:ForceGenericViewKey] respondsToSelector:@selector(boolValue)])
- {
- forceGenericView = [[desc objectForKey:ForceGenericViewKey] boolValue];
- [genericViewButton setState:(forceGenericView ? NSOnState : NSOffState)];
- }
- if ([desc objectForKey:WindowFrameKey]
- && [[desc objectForKey:WindowFrameKey] isKindOfClass:[NSString class]])
- {
- if (restoreFrame)
- [restoreFrame release];
- restoreFrame = [[NSString alloc] initWithString:[desc objectForKey:WindowFrameKey]];
- }
- }
-
- [self loadEffectUI];
-
- return YES;
-}
-
-- (NSData *)dataOfType:(NSString *)type error:(NSError **)error {
- CFPropertyListRef classInfo;
- UInt32 infoSize = sizeof(classInfo);
- OSStatus const status = AudioUnitGetProperty(
- effectUnit,
- kAudioUnitProperty_ClassInfo,
- kAudioUnitScope_Global,
- 0,
- &classInfo,
- &infoSize);
- if (noErr != status)
- {
- if (NULL != error)
- {
- NSString const *message = @"Error getting effect settings";
- NSError const *underlying = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- underlying, NSUnderlyingErrorKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- return nil;
- }
- NSDictionary *desc = nil;
- if ([type isEqualToString:AUEffectDocumentType])
- {
- NSNumber const *typeVal = [NSNumber numberWithUnsignedLong:description.componentType];
- NSNumber const *subtypeVal = [NSNumber numberWithUnsignedLong:description.componentSubType];
- NSNumber const *manufacturerVal = [NSNumber numberWithUnsignedLong:description.componentManufacturer];
- NSNumber const *forceGenericViewVal = [NSNumber numberWithBool:forceGenericView];
- NSString const *windowFrameVal = [window stringWithSavedFrame];
- desc = [NSDictionary dictionaryWithObjectsAndKeys:typeVal, ComponentTypeKey,
- subtypeVal, ComponentSubTypeKey,
- manufacturerVal, ComponentManufacturerKey,
- classInfo, ClassInfoKey,
- forceGenericViewVal, ForceGenericViewKey,
- windowFrameVal, WindowFrameKey,
- nil];
- }
- else if ([type isEqualToString:AUPresetDocumentType])
- {
- desc = [NSDictionary dictionaryWithDictionary:(NSDictionary *)classInfo];
- }
- CFRelease(classInfo);
- if (!desc)
- {
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:@"Unsupported document type", NSLocalizedDescriptionKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- return nil;
- }
-
- NSString *errDesc = nil;
- NSData *const data = [NSPropertyListSerialization dataFromPropertyList:desc
- format:NSPropertyListXMLFormat_v1_0
- errorDescription:&errDesc];
- if (!data || errDesc)
- {
- if (error)
- {
- NSString *message;
- if (errDesc)
- message = [NSString stringWithFormat:@"Error serialising effect settings: %@", errDesc];
- else
- message = @"Error serialising effect settings";
- NSDictionary *const info = [NSDictionary dictionaryWithObjectsAndKeys:message, NSLocalizedDescriptionKey,
- nil];
- *error = [NSError errorWithDomain:AUEffectUtilErrorDomain code:0 userInfo:info];
- }
- if (errDesc)
- [errDesc release];
- return nil;
- }
- return data;
-}
-
-- (IBAction)toggleGenericView:(id)sender {
- forceGenericView = (NSOnState == [sender state]);
- if (view)
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:NSViewFrameDidChangeNotification
- object:nil];
- [view removeFromSuperview];
- view = nil;
- }
- if (0 != effectNode)
- [self loadEffectUI];
-}
-
-- (IBAction)loadPreset:(id)sender {
- OSStatus status;
-
- CFIndex const idx = [sender tag];
- CFIndex const total = (NULL == presets) ? 0 : CFArrayGetCount(presets);
- if ((0 > idx) || (total <= idx))
- {
- NSAlert const *alert = [[NSAlert alloc] init];
- [alert setMessageText:@"Invalid preset selected"];
- [alert setInformativeText:[NSString stringWithFormat:@"Tried to select preset %ld of %ld",
- (long)idx + 1,
- (long)total]];
- [alert beginSheetModalForWindow:window modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
- return;
- }
-
- AUPreset const *preset = (AUPreset const *)CFArrayGetValueAtIndex(presets, idx);
- status = AudioUnitSetProperty(
- effectUnit,
- kAudioUnitProperty_PresentPreset,
- kAudioUnitScope_Global,
- 0,
- preset,
- sizeof(AUPreset));
- if (noErr != status)
- {
- NSAlert const *alert = [[NSAlert alloc] init];
- [alert setMessageText:[NSString stringWithFormat:@"Error loading preset %@", preset->presetName]];
- [alert setInformativeText:[NSString stringWithFormat:@"Error %ld encountered while setting AudioUnit property",
- (long)status]];
- [alert beginSheetModalForWindow:window modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
- return;
- }
-
- AudioUnitParameter change = { effectUnit, kAUParameterListener_AnyParameter, 0, 0 };
- status = AUParameterListenerNotify(NULL, NULL, &change);
- if (noErr != status)
- {
- NSAlert const *alert = [[NSAlert alloc] init];
- [alert setMessageText:[NSString stringWithFormat:@"Error notifying of parameter changes for preset %@",
- preset->presetName]];
- [alert setInformativeText:[NSString stringWithFormat:@"Error %ld encountered while sending notification",
- (long)status]];
- [alert beginSheetModalForWindow:window modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
- return;
- }
-}
-
-- (void)viewFrameDidChange:(NSNotification *)notification {
- NSRect const oldFrame = [window frame];
- NSRect const desired = [window frameRectForContentRect:[[notification object] frame]];
- NSRect const newFrame = NSMakeRect(
- oldFrame.origin.x,
- oldFrame.origin.y + oldFrame.size.height - headerSize.height- desired.size.height,
- desired.size.width,
- headerSize.height + desired.size.height);
- [window setFrame:newFrame display:YES animate:NO];
-}
-
-@end
-
-
-@interface AUEffectUtilAppDelegate : NSObject
-{
- EffectInfo *effects;
-
- IBOutlet NSMenu *newEffectMenu;
-}
-
-- (id)init;
-- (void)dealloc;
-
-- (IBAction)newEffect:(id)sender;
-
-- (void)applicationWillFinishLaunching:(NSNotification *)notification;
-- (void)applicationDidFinishLaunching:(NSNotification *)notification;
-- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender;
-
-@end
-
-@implementation AUEffectUtilAppDelegate
-
-- (void)appendApplicationMenu:(NSMenu *)parent {
- NSMenuItem *item;
- NSMenu *submenu;
- NSString *const appName = [(NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()) objectForKey:@"CFBundleName"];
-
- NSMenu *const menu = [[NSMenu alloc] initWithTitle:@"Application"];
- item = [parent addItemWithTitle:@"Application" action:NULL keyEquivalent:@""];
- [parent setSubmenu:menu forItem:item];
- [menu release];
- [menu setValue:@"NSAppleMenu" forKey:@"name"];
-
- item = [menu addItemWithTitle:[NSString stringWithFormat:@"About %@", appName] action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
- [item setTarget:NSApp];
-
- [menu addItem:[NSMenuItem separatorItem]];
-
- item = [menu addItemWithTitle:@"Services" action:NULL keyEquivalent:@""];
- submenu = [[NSMenu alloc] initWithTitle:@"Services"];
- [menu setSubmenu:submenu forItem:item];
- [submenu release];
- [NSApp setServicesMenu:submenu];
-
- [menu addItem:[NSMenuItem separatorItem]];
-
- item = [menu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", appName] action:@selector(hide:) keyEquivalent:@"h"];
- item = [menu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
- [item setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
- item = [menu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
-
- [menu addItem:[NSMenuItem separatorItem]];
-
- item = [menu addItemWithTitle:[NSString stringWithFormat:@"Quit %@", appName] action:@selector(terminate:) keyEquivalent:@"q"];
- [item setTarget:NSApp];
-}
-
-- (void)appendFileMenu:(NSMenu *)parent {
- NSMenuItem *item;
-
- NSMenu *const menu = [[NSMenu allocWithZone:[NSMenu zone]] initWithTitle:@"File"];
- item = [parent addItemWithTitle:@"File" action:NULL keyEquivalent:@""];
- [parent setSubmenu:menu forItem:item];
- [menu release];
-
- item = [menu addItemWithTitle:@"New" action:NULL keyEquivalent:@""];
- newEffectMenu = [[NSMenu allocWithZone:[NSMenu zone]] initWithTitle:@"New"];
- [menu setSubmenu:newEffectMenu forItem:item];
- [newEffectMenu release];
- item = [menu addItemWithTitle:[NSString stringWithFormat:@"Open%C", (unichar)0x2026] action:@selector(openDocument:) keyEquivalent:@"o"];
-
- [menu addItem:[NSMenuItem separatorItem]];
-
- item = [menu addItemWithTitle:@"Close" action:@selector(performClose:) keyEquivalent:@"w"];
- item = [menu addItemWithTitle:@"Save" action:@selector(saveDocument:) keyEquivalent:@"s"];
- item = [menu addItemWithTitle:[NSString stringWithFormat:@"Save As%C", (unichar)0x2026] action:@selector(saveDocumentAs:) keyEquivalent:@"S"];
- item = [menu addItemWithTitle:@"Save All" action:@selector(saveAllDocuments:) keyEquivalent:@""];
- item = [menu addItemWithTitle:@"Revert to Saved" action:@selector(revertDocumentToSaved:) keyEquivalent:@"u"];
-}
-
-- (void)appendEditMenu:(NSMenu *)parent {
- NSMenuItem *item;
-
- NSMenu *const menu = [[NSMenu allocWithZone:[NSMenu zone]] initWithTitle:@"Edit"];
- item = [parent addItemWithTitle:@"Edit" action:NULL keyEquivalent:@""];
- [parent setSubmenu:menu forItem:item];
- [menu release];
-
- item = [menu addItemWithTitle:@"Undo" action:@selector(undo:) keyEquivalent:@"z"];
- item = [menu addItemWithTitle:@"Redo" action:@selector(redo:) keyEquivalent:@"Z"];
-
- [menu addItem:[NSMenuItem separatorItem]];
-
- item = [menu addItemWithTitle:@"Cut" action:@selector(cut:) keyEquivalent:@"x"];
- item = [menu addItemWithTitle:@"Copy" action:@selector(copy:) keyEquivalent:@"c"];
- item = [menu addItemWithTitle:@"Paste" action:@selector(paste:) keyEquivalent:@"v"];
- item = [menu addItemWithTitle:@"Delete" action:@selector(delete:) keyEquivalent:@""];
- item = [menu addItemWithTitle:@"Select All" action:@selector(selectAll:) keyEquivalent:@"a"];
-}
-
-- (void)appendWindowMenu:(NSMenu *)parent {
- NSMenuItem *item;
-
- NSMenu *const menu = [[NSMenu allocWithZone:[NSMenu zone]] initWithTitle:@"Window"];
- item = [parent addItemWithTitle:@"Window" action:NULL keyEquivalent:@""];
- [parent setSubmenu:menu forItem:item];
- [menu release];
- [NSApp setWindowsMenu:menu];
-
- item = [menu addItemWithTitle:@"Minimize" action:@selector(performMinimize:) keyEquivalent:@"m"];
- item = [menu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
-
- [menu addItem:[NSMenuItem separatorItem]];
-
- item = [menu addItemWithTitle:@"Bring All to Front" action:@selector(arrangeInFront:) keyEquivalent:@""];
-}
-
-- (void)appendHelpMenu:(NSMenu *)parent {
- NSMenuItem *item;
- NSString *const appName = [(NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()) objectForKey:@"CFBundleName"];
-
- NSMenu *const menu = [[NSMenu allocWithZone:[NSMenu zone]] initWithTitle:@"Help"];
- item = [parent addItemWithTitle:@"Help" action:NULL keyEquivalent:@""];
- [parent setSubmenu:menu forItem:item];
- [menu release];
- [menu setValue:@"NSHelpMenu" forKey:@"name"];
- if ([NSApp respondsToSelector:@selector(setHelpMenu:)])
- [NSApp performSelector:@selector(setHelpMenu:) withObject:menu];
-
- item = [menu addItemWithTitle:[NSString stringWithFormat:@"%@ Help", appName] action:@selector(showHelp:) keyEquivalent:@"?"];
-}
-
-- (id)init {
- if (!(self = [super init]))
- return nil;
- effects = NULL;
- return self;
-}
-
-- (void)dealloc {
- if (effects)
- free(effects);
- [super dealloc];
-}
-
-- (IBAction)newEffect:(id)sender {
- int const index = [sender tag];
- if ((0 > index) || (0 == effects[index].component))
- {
- NSAlert *const alert = [[NSAlert alloc] init];
- [alert setAlertStyle:NSWarningAlertStyle];
- [alert setMessageText:@"Invalid effect component"];
- [alert addButtonWithTitle:@"OK"];
- [alert runModal];
- [alert release];
- return;
- }
-
- NSNumber *const typeValue = [NSNumber numberWithUnsignedLong:effects[index].type];
- NSNumber *const subtypeValue = [NSNumber numberWithUnsignedLong:effects[index].subtype];
- NSNumber *const manufacturerValue = [NSNumber numberWithUnsignedLong:effects[index].manufacturer];
- NSDictionary *const desc = [NSDictionary dictionaryWithObjectsAndKeys:typeValue, ComponentTypeKey,
- subtypeValue, ComponentSubTypeKey,
- manufacturerValue, ComponentManufacturerKey,
- nil];
- NSString *errDesc = nil;
- NSData *const data = [NSPropertyListSerialization dataFromPropertyList:desc
- format:NSPropertyListXMLFormat_v1_0
- errorDescription:&errDesc];
- if (!data || errDesc)
- {
- NSAlert *const alert = [[NSAlert alloc] init];
- [alert setAlertStyle:NSWarningAlertStyle];
- [alert setMessageText:@"Error serialising properties for new effect"];
- if (errDesc)
- [alert setInformativeText:[errDesc autorelease]];
- [alert addButtonWithTitle:@"OK"];
- [alert runModal];
- [alert release];
- return;
- }
-
- NSError *err = nil;
- AUEffectDocument *const document = [[AUEffectDocument alloc] init];
- if (!document || ![document readFromData:data ofType:AUEffectDocumentType error:&err])
- {
- [document release];
- if (err)
- {
- [[NSAlert alertWithError:err] runModal];
- }
- else
- {
- NSAlert *const alert = [[NSAlert alloc] init];
- [alert setAlertStyle:NSWarningAlertStyle];
- [alert setMessageText:@"Error creating new effect document"];
- [alert addButtonWithTitle:@"OK"];
- [alert runModal];
- [alert release];
- }
- return;
- }
-
- [document makeWindowControllers];
- [document showWindows];
- [[NSDocumentController sharedDocumentController] addDocument:document];
- [document release];
-}
-
-- (void)applicationWillFinishLaunching:(NSNotification *)notification {
- NSMenu *const menubar = [[NSMenu allocWithZone:[NSMenu zone]] initWithTitle:@"MainMenu"];
- [NSApp setMainMenu:menubar];
- [menubar release];
- [self appendApplicationMenu:menubar];
- [self appendFileMenu:menubar];
- [self appendEditMenu:menubar];
- [self appendWindowMenu:menubar];
- [self appendHelpMenu:menubar];
-
- ProcessSerialNumber const serial = { 0, kCurrentProcess };
- OSStatus const status = TransformProcessType(&serial, kProcessTransformToForegroundApplication);
- if (noErr != status)
- {
- NSLog(@"Error transforming to foreground application (%ld)", (long)status);
- [NSApp terminate:self];
- }
- else
- {
- [NSApp activateIgnoringOtherApps:YES];
- }
-}
-
-- (void)applicationDidFinishLaunching:(NSNotification *)notification {
- ComponentDescription effectFilter = { kAudioUnitType_Effect, 0, 0, 0, 0 };
- long const count = CountComponents(&effectFilter);
- if (0 == count)
- {
- NSAlert *const alert = [[NSAlert alloc] init];
- [alert setAlertStyle:NSWarningAlertStyle];
- [alert setMessageText:@"No AudioUnit effects found"];
- [alert addButtonWithTitle:@"OK"];
- [alert runModal];
- [alert release];
- }
-
- std::vector > failed;
- effects = (EffectInfo *)malloc(count * sizeof(*effects));
- Component effect = FindNextComponent(0, &effectFilter);
- for (long i = 0; (i < count) && (effect != 0); i++, effect = FindNextComponent(effect, &effectFilter))
- {
- ComponentDescription effectDesc;
- Handle const nameHandle = NewHandle(4);
- OSStatus const err = GetComponentInfo(effect, &effectDesc, nameHandle, NULL, NULL);
- if (noErr == err)
- {
- effects[i].component = effect;
- effects[i].type = effectDesc.componentType;
- effects[i].subtype = effectDesc.componentSubType;
- effects[i].manufacturer = effectDesc.componentManufacturer;
- HLock(nameHandle);
- CFStringRef const name = CFStringCreateWithPascalString(
- NULL,
- (unsigned char const *)*nameHandle,
- kCFStringEncodingMacRoman);
- HUnlock(nameHandle);
- NSMenuItem *const item = [newEffectMenu addItemWithTitle:(NSString *)name
- action:@selector(newEffect:)
- keyEquivalent:@""];
- [item setTag:i];
- [item setTarget:self];
- CFRelease(name);
- }
- else
- {
- effects[i].component = 0;
- failed.push_back(std::make_pair(effect, err));
- }
- DisposeHandle(nameHandle);
- }
-
- if (!failed.empty())
- {
- NSString *const message = [NSString stringWithFormat:@"Failed to get info for %lu effect%s",
- (unsigned long)failed.size(),
- ((1U == failed.size()) ? "" : "s")];
- NSMutableString *const detail = [NSMutableString stringWithCapacity:(16 * failed.size())];
- std::vector >::const_iterator it = failed.begin();
- [detail appendFormat:@"%lu (%ld)", (unsigned long)it->first, (long)it->second];
- ++it;
- while (failed.end() != it)
- {
- [detail appendFormat:@", %lu (%ld)", (unsigned long)it->first, (long)it->second];
- ++it;
- }
- NSAlert *const alert = [[NSAlert alloc] init];
- [alert setAlertStyle:NSWarningAlertStyle];
- [alert setMessageText:message];
- [alert setInformativeText:[NSString stringWithString:detail]];
- [alert addButtonWithTitle:@"OK"];
- [alert runModal];
- [alert release];
- }
-}
-
-- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender {
- return NO;
-}
-
-@end
-
-
-int main(int argc, char *argv[])
-{
- NSAutoreleasePool *pool;
-
- // Initialise NSApplication
- pool = [[NSAutoreleasePool alloc] init];
- [NSApplication sharedApplication];
- AUEffectUtilAppDelegate *const delegate = [[AUEffectUtilAppDelegate alloc] init];
- [[NSApplication sharedApplication] setDelegate:delegate];
- [pool release];
-
- // Let's go!
- pool = [[NSAutoreleasePool alloc] init];
- [NSApp run];
- [delegate release];
- [pool release];
- return 0;
-}
diff --git a/src/tools/castool.cpp b/src/tools/castool.cpp
deleted file mode 100644
index b5fa9cf..0000000
--- a/src/tools/castool.cpp
+++ /dev/null
@@ -1,227 +0,0 @@
-// license:BSD-3-Clause
-// copyright-holders:Miodrag Milanovic
-/***************************************************************************
-
- main.c
-
- Castool command line front end
-
- 27/03/2009 Initial version by Miodrag Milanovic
-
-***************************************************************************/
-
-#include "formats/a26_cas.h"
-#include "formats/ace_tap.h"
-#include "formats/adam_cas.h"
-#include "formats/apf_apt.h"
-#include "formats/atom_tap.h"
-#include "formats/cbm_tap.h"
-#include "formats/cgen_cas.h"
-#include "formats/coco_cas.h"
-#include "formats/csw_cas.h"
-#include "formats/fm7_cas.h"
-#include "formats/fmsx_cas.h"
-#include "formats/gtp_cas.h"
-#include "formats/hect_tap.h"
-#include "formats/kc_cas.h"
-#include "formats/kim1_cas.h"
-#include "formats/lviv_lvt.h"
-#include "formats/mz_cas.h"
-#include "formats/orao_cas.h"
-#include "formats/oric_tap.h"
-#include "formats/p2000t_cas.h"
-#include "formats/p6001_cas.h"
-#include "formats/phc25_cas.h"
-#include "formats/pmd_cas.h"
-#include "formats/primoptp.h"
-#include "formats/rk_cas.h"
-#include "formats/sc3000_bit.h"
-#include "formats/sol_cas.h"
-#include "formats/sorc_cas.h"
-#include "formats/sord_cas.h"
-#include "formats/spc1000_cas.h"
-#include "formats/svi_cas.h"
-#include "formats/thom_cas.h"
-#include "formats/trs_cas.h"
-#include "formats/tvc_cas.h"
-#include "formats/tzx_cas.h"
-#include "formats/uef_cas.h"
-#include "formats/vg5k_cas.h"
-#include "formats/vt_cas.h"
-#include "formats/x07_cas.h"
-#include "formats/x1_tap.h"
-#include "formats/zx81_p.h"
-
-#include "corestr.h"
-#include "ioprocs.h"
-#include "osdcomm.h"
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-struct SupportedCassetteFormats
-{
- const char *name;
- const cassette_image::Format * const *formats;
- const char *desc;
-};
-
-const struct SupportedCassetteFormats formats[] = {
- {"a26", a26_cassette_formats ,"Atari 2600 SuperCharger"},
- {"apf", apf_cassette_formats ,"APF Imagination Machine"},
- {"atom", atom_cassette_formats ,"Acorn Atom"},
- {"bbc", bbc_cassette_formats ,"Acorn BBC & Electron"},
- {"cbm", cbm_cassette_formats ,"Commodore 8-bit series"},
- {"cdt", cdt_cassette_formats ,"Amstrad CPC"},
- {"cgenie", cgenie_cassette_formats ,"EACA Colour Genie"},
- {"coco", coco_cassette_formats ,"Tandy Radio Shack Color Computer"},
- {"csw", csw_cassette_formats ,"Compressed Square Wave"},
- {"ddp", coleco_adam_cassette_formats ,"Coleco ADAM"},
- {"fm7", fm7_cassette_formats ,"Fujitsu FM-7"},
- {"fmsx", fmsx_cassette_formats ,"MSX"},
- {"gtp", gtp_cassette_formats ,"Elektronika inzenjering Galaksija"},
- {"hector", hector_cassette_formats ,"Micronique Hector & Interact Family Computer"},
- {"jupiter", ace_cassette_formats ,"Jupiter Cantab Jupiter Ace"},
- {"kc85", kc_cassette_formats ,"VEB Mikroelektronik KC 85"},
- {"kim1", kim1_cassette_formats ,"MOS KIM-1"},
- {"lviv", lviv_lvt_format ,"PK-01 Lviv"},
- {"mo5", mo5_cassette_formats ,"Thomson MO-series"},
- {"mz", mz700_cassette_formats ,"Sharp MZ-700"},
- {"orao", orao_cassette_formats ,"PEL Varazdin Orao"},
- {"oric", oric_cassette_formats ,"Tangerine Oric"},
- {"p2000t", p2000t_cassette_formats ,"Philips P2000T"},
- {"pc6001", pc6001_cassette_formats ,"NEC PC-6001"},
- {"phc25", phc25_cassette_formats ,"Sanyo PHC-25"},
- {"pmd85", pmd85_cassette_formats ,"Tesla PMD-85"},
- {"primo", primo_ptp_format ,"Microkey Primo"},
- {"rku", rku_cassette_formats ,"UT-88"},
- {"rk8", rk8_cassette_formats ,"Mikro-80"},
- {"rks", rks_cassette_formats ,"Specialist"},
- {"rko", rko_cassette_formats ,"Orion"},
- {"rkr", rkr_cassette_formats ,"Radio-86RK"},
- {"rka", rka_cassette_formats ,"Zavod BRA Apogee BK-01"},
- {"rkm", rkm_cassette_formats ,"Mikrosha"},
- {"rkp", rkp_cassette_formats ,"SAM SKB VM Partner-01.01"},
- {"sc3000", sc3000_cassette_formats ,"Sega SC-3000"},
- {"sol20", sol20_cassette_formats ,"PTC SOL-20"},
- {"sorcerer", sorcerer_cassette_formats ,"Exidy Sorcerer"},
- {"sordm5", sordm5_cassette_formats ,"Sord M5"},
- {"spc1000", spc1000_cassette_formats ,"Samsung SPC-1000"},
- {"svi", svi_cassette_formats ,"Spectravideo SVI-318 & SVI-328"},
- {"to7", to7_cassette_formats ,"Thomson TO-series"},
- {"trs80l2", trs80l2_cassette_formats ,"TRS-80 Level 2"},
- {"tvc64", tvc64_cassette_formats ,"Videoton TVC 64"},
- {"tzx", tzx_cassette_formats ,"Sinclair ZX Spectrum"},
- {"vg5k", vg5k_cassette_formats ,"Philips VG 5000"},
- {"vtech1", vtech1_cassette_formats ,"Video Technology Laser 110-310"},
- {"vtech2", vtech2_cassette_formats ,"Video Technology Laser 350-700"},
- {"x07", x07_cassette_formats ,"Canon X-07"},
- {"x1", x1_cassette_formats ,"Sharp X1"},
- {"zx80_o", zx80_o_format ,"Sinclair ZX80"},
- {"zx81_p", zx81_p_format ,"Sinclair ZX81"},
-
-
-
- {nullptr,nullptr,nullptr}
-};
-
-
-static std::string get_extension(const char *name)
-{
- const char *s;
- s = name;
- if (s != nullptr)
- s = strrchr(s, '.');
- return s ? std::string(s+1) : "";
-}
-
-static void display_usage(const char *argv0)
-{
- fprintf(stderr, "Usage: \n");
- fprintf(stderr, " %s convert \n", argv0);
-}
-
-static void display_formats(void)
-{
- int i,j;
- fprintf(stderr, "Supported formats:\n\n");
- for (i = 0; formats[i].name; i++) {
- fprintf(stderr, "%10s - %s\n",formats[i].name,formats[i].desc);
- for (j = 1; formats[i].formats[j]; j++) {
- fprintf(stderr, "%15s %s\n","",formats[i].formats[j]->extensions);
- }
- }
-}
-
-int CLIB_DECL main(int argc, char *argv[])
-{
- int i;
- int found =0;
- const cassette_image::Format * const *selected_formats = nullptr;
- cassette_image::ptr cassette;
-
- if (argc > 1)
- {
- if (!core_stricmp("convert", argv[1]))
- {
- // convert command
- if (argc!=5) {
- fprintf(stderr, "Wrong parameter number.\n\n");
- display_usage(argv[0]);
- return -1;
- } else {
- for (i = 0; formats[i].name; i++) {
- if (core_stricmp(formats[i].name,argv[2])==0) {
- selected_formats = formats[i].formats;
- found = 1;
- }
- }
- if (found==0) {
- fprintf(stderr, "Wrong format name.\n\n");
- display_usage(argv[0]);
- fprintf(stderr, "\n");
- display_formats();
- return -1;
- }
-
- FILE *f = fopen(argv[3], "rb");
- if (!f) {
- fprintf(stderr, "File %s not found.\n",argv[3]);
- return -1;
- }
-
- auto io = util::stdio_read_write(f, 0x00);
- f = nullptr;
- if (!io) {
- fprintf(stderr, "Out of memory.\n");
- return -1;
- }
-
- if (cassette_image::open_choices(std::move(io), get_extension(argv[3]), selected_formats, cassette_image::FLAG_READONLY, cassette) != cassette_image::error::SUCCESS) {
- fprintf(stderr, "Invalid format of input file.\n");
- return -1;
- }
-
- cassette->dump(argv[4]);
- cassette.reset();
- goto theend;
- }
- }
- }
-
- /* Usage */
- fprintf(stderr, "castool - Generic cassette manipulation tool for use with MAME\n\n");
- display_usage(argv[0]);
- fprintf(stderr, "\n");
- display_formats();
- fprintf(stderr, "\nExample usage:\n");
- fprintf(stderr, " %s convert tzx game.tzx game.wav\n\n", argv[0]);
-
-theend :
- return 0;
-}
diff --git a/src/tools/discrepancy-fixer.py b/src/tools/discrepancy-fixer.py
deleted file mode 100755
index d36d286..0000000
--- a/src/tools/discrepancy-fixer.py
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/usr/bin/python
-##
-## license:BSD-3-Clause
-## copyright-holders:Zoe Blade
-
-# Fix discrepancies in arcade ROM dump names, by Zoe Blade
-# For Python 2 and 3
-
-import sys
-import xml.etree.ElementTree
-
-
-def fixPair(parentMachine, childMachine):
- changes = { }
- for childRom in childMachine.iter('rom'):
- for parentRom in parentMachine.iter('rom'):
- if parentRom.get('sha1') == childRom.get('sha1'):
- # ROM pair found
- if parentRom.get('name') != childRom.get('name'):
- # The names don't match
- changes[childRom.get('name')] = parentRom.get('name')
-
- if changes:
- sourceFilename = childMachine.get('sourcefile')
-
- try:
- input = open(sourceFilename, 'r')
- source = input.read()
- input.close()
- except Exception as e:
- sys.stderr.write('%s: error reading %s: %s\n' % (sys.argv[0], sourceFilename, e))
- return False
-
- for oldRomFilename in changes:
- newRomFilename = '"%s"' % (changes[oldRomFilename])
- oldRomFilename = '"%s"' % (oldRomFilename)
-
- paddedLen = max(len(oldRomFilename), len(newRomFilename))
- oldRomFilenamePadded = oldRomFilename.ljust(paddedLen, ' ')
- newRomFilenamePadded = newRomFilename.ljust(paddedLen, ' ')
-
- source = source.replace(oldRomFilenamePadded, newRomFilenamePadded) # Try to preserve fancy spacing where possible
- source = source.replace(oldRomFilename, newRomFilename) # Fallback on just replacing the filename
-
- sys.stdout.write('%s: %s -> %s\n' % (sourceFilename, oldRomFilename, newRomFilename))
-
- output = open(sourceFilename, 'w')
- output.write(source)
- output.close()
-
- return True
-
-
-if __name__ == '__main__':
- if len(sys.argv) > 2:
- sys.stderr.write('Usage:\n%s [arcade.xml]\n' % sys.argv[0])
- sys.exit(1)
-
- if len(sys.argv) > 1:
- filename = sys.argv[1]
- else:
- filename = 'arcade.xml'
-
- sys.stderr.write('Loading XML file...')
- sys.stderr.flush()
- try:
- root = xml.etree.ElementTree.parse(filename).getroot()
- except Exception as e:
- sys.stderr.write('\n%s: error parsing %s: %s\n' % (sys.argv[0], filename, e))
- sys.exit(2)
- sys.stderr.write('done.\n')
-
- errors = 0
- for childMachine in root.iter('machine'):
- if childMachine.get('cloneof'):
- for parentMachine in root.iter('machine'):
- if parentMachine.get('name') == childMachine.get('cloneof'):
- # Machine pair found
- if not fixPair(parentMachine, childMachine):
- errors += 1
-
- sys.exit(0 if errors == 0 else 3)
diff --git a/src/tools/discrepancy-spotter.py b/src/tools/discrepancy-spotter.py
deleted file mode 100755
index 27ba7c0..0000000
--- a/src/tools/discrepancy-spotter.py
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/python
-##
-## license:BSD-3-Clause
-## copyright-holders:Zoe Blade
-
-# Find discrepancies in arcade ROM dump names, by Zoe Blade
-# For Python 2 and 3
-
-import sys
-import xml.etree.ElementTree
-
-
-def checkPair(parentMachine, childMachine):
- for childRom in childMachine.iter('rom'):
- for parentRom in parentMachine.iter('rom'):
- if parentRom.get('sha1') == childRom.get('sha1'):
- # ROM pair found
- if parentRom.get('name') != childRom.get('name'):
- # The names don't match
- sys.stdout.write('%s %s: %s -> %s\n' % (childMachine.get('sourcefile'), childMachine.get('name'), childRom.get('name'), parentRom.get('name')))
- else:
- break
-
-
-if __name__ == '__main__':
- if len(sys.argv) > 2:
- sys.stderr.write('Usage:\n%s [arcade.xml]\n' % sys.argv[0])
- sys.exit(1)
-
- if len(sys.argv) > 1:
- filename = sys.argv[1]
- else:
- filename = 'arcade.xml'
-
- sys.stderr.write('Loading XML file...')
- sys.stderr.flush()
- try:
- root = xml.etree.ElementTree.parse(filename).getroot()
- except Exception as e:
- sys.stderr.write('\n%s: error parsing %s: %s\n' % (sys.argv[0], filename, e))
- sys.exit(2)
- sys.stderr.write('done.\n')
-
- for childMachine in root.iter('machine'):
- if childMachine.get('cloneof'):
- for parentMachine in root.iter('machine'):
- if parentMachine.get('name') == childMachine.get('cloneof'):
- # Machine pair found
- checkPair(parentMachine, childMachine)
-
- sys.exit(0)
diff --git a/src/tools/floptool.cpp b/src/tools/floptool.cpp
deleted file mode 100644
index f021e08..0000000
--- a/src/tools/floptool.cpp
+++ /dev/null
@@ -1,711 +0,0 @@
-// license:BSD-3-Clause
-// copyright-holders:Olivier Galibert
-/***************************************************************************
-
- (Floppy) image command-line manager
-
-***************************************************************************/
-
-#include "image_handler.h"
-
-#include "corestr.h"
-#include "ioprocs.h"
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-static formats_table formats;
-
-static void display_usage()
-{
- fprintf(stderr, "Usage: \n");
- fprintf(stderr, " floptool.exe identify [ ...] -- Identify an image format\n");
- fprintf(stderr, " floptool.exe flopconvert [input_format|auto] output_format -- Convert a floppy image\n");
- fprintf(stderr, " floptool.exe flopcreate output_format filesystem -- Create a preformatted floppy image\n");
- fprintf(stderr, " floptool.exe flopdir input_format filesystem -- List the contents of a floppy image\n");
- fprintf(stderr, " floptool.exe flopread input_format filesystem -- Extract a file from a floppy image\n");
- fprintf(stderr, " floptool.exe flopwrite input_format filesystem -- Write a file into a floppy image\n");
-}
-
-static void display_formats()
-{
- int sk = 0;
- for(const auto &e : formats.floppy_format_info_by_key) {
- int sz = e.first.size();
- if(sz > sk)
- sk = sz;
- }
-
- for(const auto &e : formats.filesystem_format_by_key) {
- int sz = e.first.size();
- if(sz > sk)
- sk = sz;
- }
-
- for(const auto &e : formats.floppy_create_info_by_key) {
- int sz = e.first.size();
- if(sz > sk)
- sk = sz;
- }
-
- fprintf(stderr, "Supported floppy formats:\n\n");
- for(const auto &e : formats.floppy_format_info_by_category)
- if(!e.second.empty()) {
- fprintf(stderr, "%s:\n", e.first.c_str());
- for(auto *fif : e.second)
- fprintf(stderr, " %-*s r%c - %s [%s]\n", sk, fif->m_format->name(), fif->m_format->supports_save() ? 'w' : '-', fif->m_format->description(), fif->m_format->extensions());
- }
-
- fprintf(stderr, "\n\n");
- fprintf(stderr, "Supported filesystems (with floppy formatting names):\n\n");
- for(const auto &e : formats.filesystem_format_by_category)
- if(!e.second.empty()) {
- fprintf(stderr, "%s:\n", e.first.c_str());
- for(const auto &f : e.second) {
- fprintf(stderr, " %-*s %c%c%c %c%c%c - %s\n",
- sk,
- f->m_manager->name(),
- f->m_floppy || f->m_floppy_raw ? 'F' : '-',
- f->m_hd ? 'H' : '-',
- f->m_cd ? 'C' : '-',
- f->m_manager->can_format() || f->m_floppy_raw ? 'f' : '-',
- f->m_manager->can_read() ? 'r' : '-',
- f->m_manager->can_write() ? 'w' : '-',
- f->m_manager->description());
- for(auto &f2 : f->m_floppy_create)
- fprintf(stderr, " %-*s - %s\n",
- sk,
- f2->m_name,
- f2->m_description);
- }
- }
-}
-
-static void display_full_usage()
-{
- /* Usage */
- fprintf(stderr, "floptool - Generic floppy image manipulation tool for use with MAME\n\n");
- display_usage();
- fprintf(stderr, "\n");
- display_formats();
-
-}
-
-static int identify(int argc, char *argv[])
-{
- // Need to detect CHDs too
-
- if(argc<3) {
- fprintf(stderr, "Missing name of file to identify.\n\n");
- display_usage();
- return 1;
- }
-
- int sz = 0;
- for(int i=2; i sz)
- sz = len;
- }
-
- for(int i=2; im_format->name());
- if(len > sz2)
- sz2 = len;
- }
-
- bool first = true;
- for(const auto &e : scores) {
- printf("%-*s %c %3d - %-*s %s\n", sz, first ? argv[i] : "", first ? ':' : ' ', e.first, sz2, e.second->m_format->name(), e.second->m_format->description());
- first = false;
- }
- }
- return 0;
-}
-
-static const floppy_format_info *find_floppy_source_format(const char *name, image_handler &ih)
-{
- const floppy_format_info *source_format;
- if(!core_stricmp(name, "auto")) {
- auto scores = ih.identify(formats);
- if(scores.empty()) {
- fprintf(stderr, "Error: Could not identify the format of file %s\n", ih.get_on_disk_path().c_str());
- return nullptr;
- }
- if(scores.size() >= 2 && scores[0].first == scores[1].first) {
- fprintf(stderr, "Ambiguous source format. Possible formats:\n");
- int sz = 0;
- for(const auto &e : scores) {
- int len = strlen(e.second->m_format->name());
- if(len > sz)
- sz = len;
- }
-
- for(const auto &e : scores)
- printf(" %3d - %-*s %s\n", e.first, sz, e.second->m_format->name(), e.second->m_format->description());
- return nullptr;
- }
- source_format = scores[0].second;
-
- } else {
- source_format = formats.find_floppy_format_info_by_key(name);
- if(!source_format) {
- fprintf(stderr, "Error: Format '%s' unknown\n", name);
- return nullptr;
-
- }
- }
- return source_format;
-}
-
-static int flopconvert(int argc, char *argv[])
-{
- if(argc!=6) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- display_usage();
- return 1;
- }
-
- image_handler ih;
- ih.set_on_disk_path(argv[4]);
-
- const floppy_format_info *source_format = find_floppy_source_format(argv[2], ih);
- if(!source_format)
- return 1;
-
- const floppy_format_info *dest_format = formats.find_floppy_format_info_by_key(argv[3]);
- if(!dest_format) {
- fprintf(stderr, "Error: Format '%s' unknown\n", argv[3]);
- return 1;
- }
- if(!dest_format->m_format->supports_save()) {
- fprintf(stderr, "Error: Aaving to format '%s' unsupported\n", argv[3]);
- return 1;
- }
-
- if(ih.floppy_load(source_format)) {
- fprintf(stderr, "Error: Loading as format '%s' failed\n", source_format->m_format->name());
- return 1;
- }
-
- ih.set_on_disk_path(argv[5]);
-
- if(ih.floppy_save(dest_format)) {
- fprintf(stderr, "Error: Saving as format '%s' failed\n", dest_format->m_format->name());
- return 1;
- }
-
- return 0;
-}
-
-static int flopcreate(int argc, char *argv[])
-{
- if(argc!=5) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- display_usage();
- return 1;
- }
-
- auto dest_format = formats.find_floppy_format_info_by_key(argv[2]);
- if(!dest_format) {
- fprintf(stderr, "Error: Floppy format '%s' unknown\n", argv[3]);
- return 1;
- }
- if(!dest_format->m_format->supports_save()) {
- fprintf(stderr, "Error: Saving to format '%s' unsupported\n", argv[3]);
- return 1;
- }
-
- auto create_fs = formats.find_floppy_create_info_by_key(argv[3]);
- if(!create_fs) {
- fprintf(stderr, "Error: Floppy creation format '%s' unknown\n", argv[3]);
- return 1;
- }
- if(!create_fs->m_manager->can_format()) {
- fprintf(stderr, "Error: Floppy creation format '%s' does not support creating new images\n", argv[3]);
- return 1;
- }
-
- fs_meta_data meta;
- image_handler ih;
- ih.set_on_disk_path(argv[4]);
-
- ih.floppy_create(create_fs, meta);
- return ih.floppy_save(dest_format);
-}
-
-static void dir_scan(u32 depth, filesystem_t::dir_t dir, std::vector> &entries, const std::unordered_map &nmap, size_t nc, const std::vector &dmetad, const std::vector &fmetad)
-{
- std::string head;
- for(u32 i = 0; i != depth; i++)
- head += " ";
- auto contents = dir.contents();
- for(const auto &c : contents) {
- size_t id = entries.size();
- entries.resize(id+1);
- entries[id].resize(nc);
- switch(c.m_type) {
- case fs_dir_entry_type::dir: {
- auto subdir = dir.dir_get(c.m_key);
- auto meta = subdir.metadata();
- for(const auto &m : dmetad) {
- if(!meta.has(m.m_name))
- continue;
- size_t slot = nmap.find(m.m_name)->second;
- std::string val = fs_meta::to_string(m.m_type, meta.get(m.m_name));
- if(slot == 0)
- val = head + "dir " + val;
- entries[id][slot] = val;
- }
- dir_scan(depth+1, subdir, entries, nmap, nc, dmetad, fmetad);
- break;
- }
- case fs_dir_entry_type::file:
- case fs_dir_entry_type::system_file: {
- auto file = dir.file_get(c.m_key);
- auto meta = file.metadata();
- for(const auto &m : fmetad) {
- if(!meta.has(m.m_name))
- continue;
- size_t slot = nmap.find(m.m_name)->second;
- std::string val = fs_meta::to_string(m.m_type, meta.get(m.m_name));
- if(slot == 0)
- val = head + (c.m_type == fs_dir_entry_type::system_file ? "sys " : "file ") + val;
- entries[id][slot] = val;
- }
- break;
- }
- }
- }
-}
-
-static int generic_dir(image_handler &ih)
-{
- auto [fsm, fs] = ih.get_fs();
- auto vmetad = fsm->volume_meta_description();
- auto fmetad = fsm->file_meta_description();
- auto dmetad = fsm->directory_meta_description();
-
- auto vmeta = fs->metadata();
- if(!vmeta.empty()) {
- std::string vinf = "Volume:";
- for(const auto &e : vmetad)
- vinf += util::string_format(" %s=%s", fs_meta_data::entry_name(e.m_name), fs_meta::to_string(e.m_type, vmeta.get(e.m_name)));
- printf("%s\n\n", vinf.c_str());
- }
-
- std::vector names;
- names.push_back(fs_meta_name::name);
- for(const auto &e : fmetad)
- if(e.m_name != fs_meta_name::name)
- names.push_back(e.m_name);
- for(const auto &e : dmetad)
- if(std::find(names.begin(), names.end(), e.m_name) == names.end())
- names.push_back(e.m_name);
-
- std::unordered_map nmap;
- for(size_t i = 0; i != names.size(); i++)
- nmap[names[i]] = i;
-
- auto root = fs->root();
- std::vector> entries;
-
- entries.resize(1);
- for(fs_meta_name n : names)
- entries[0].push_back(fs_meta_data::entry_name(n));
-
- dir_scan(0, root, entries, nmap, names.size(), dmetad, fmetad);
-
- std::vector sizes(names.size());
-
- for(const auto &e : entries)
- for(unsigned int i=0; i != names.size(); i++)
- sizes[i] = std::max(sizes[i], e[i].size());
-
- for(const auto &e : entries) {
- std::string l;
- for(unsigned int i=0; i != names.size(); i++) {
- if(i)
- l += ' ';
- l += util::string_format("%-*s", sizes[i], e[i]);
- }
- printf("%s\n", l.c_str());
- }
-
- return 0;
-}
-
-static int flopdir(int argc, char *argv[])
-{
- if(argc!=5) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- display_usage();
- return 1;
- }
-
- image_handler ih;
- ih.set_on_disk_path(argv[4]);
-
- const floppy_format_info *source_format = find_floppy_source_format(argv[2], ih);
- if(!source_format)
- return 1;
-
- auto fs = formats.find_filesystem_format_by_key(argv[3]);
- if(!fs) {
- fprintf(stderr, "Error: Filesystem '%s' unknown\n", argv[3]);
- return 1;
- }
-
- if(!fs->m_manager || !fs->m_manager->can_read()) {
- fprintf(stderr, "Error: Filesystem '%s' does not implement reading\n", argv[3]);
- return 1;
- }
-
- if(ih.floppy_load(source_format)) {
- fprintf(stderr, "Error: Loading as format '%s' failed\n", source_format->m_format->name());
- return 1;
- }
-
- if(ih.floppy_mount_fs(fs)) {
- fprintf(stderr, "Error: Parsing as filesystem '%s' failed\n", fs->m_manager->name());
- return 1;
- }
-
- return generic_dir(ih);
-}
-
-static int hddir(int argc, char *argv[])
-{
- if(argc!=4) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- display_usage();
- return 1;
- }
-
- image_handler ih;
- ih.set_on_disk_path(argv[3]);
-
- auto fs = formats.find_filesystem_format_by_key(argv[2]);
- if(!fs) {
- fprintf(stderr, "Error: Filesystem '%s' unknown\n", argv[2]);
- return 1;
- }
-
- if(!fs->m_manager || !fs->m_manager->can_read()) {
- fprintf(stderr, "Error: Filesystem '%s' does not implement reading\n", argv[2]);
- return 1;
- }
-
- if(ih.hd_mount_fs(fs)) {
- fprintf(stderr, "Error: Parsing as filesystem '%s' failed\n", fs->m_manager->name());
- return 1;
- }
-
- return generic_dir(ih);
-}
-
-
-static int generic_read(image_handler &ih, const char *srcpath, const char *dstpath)
-{
- auto [fsm, fs] = ih.get_fs();
-
- std::vector path = ih.path_split(srcpath);
-
- auto dir = fs->root();
- std::string apath;
- for(unsigned int i = 0; i < path.size() - 1; i++) {
- auto c = dir.contents();
- unsigned int j;
- for(j = 0; j != c.size(); j++)
- if(c[j].m_name == path[i])
- break;
- if(j == c.size()) {
- fprintf(stderr, "Error: directory %s%c%s not found\n", apath.c_str(), fsm->directory_separator(), path[i].c_str());
- return 1;
- }
- if(c[j].m_type != fs_dir_entry_type::dir) {
- fprintf(stderr, "Error: %s%c%s is not a directory\n", apath.c_str(), fsm->directory_separator(), path[i].c_str());
- return 1;
- }
- dir = dir.dir_get(c[j].m_key);
- apath += fsm->directory_separator() + path[i];
- }
-
- auto c = dir.contents();
- unsigned int j;
- for(j = 0; j != c.size(); j++)
- if(c[j].m_name == path.back())
- break;
- if(j == c.size()) {
- fprintf(stderr, "Error: file %s%c%s not found\n", apath.c_str(), fsm->directory_separator(), path.back().c_str());
- return 1;
- }
- auto file = dir.file_get(c[j].m_key);
- auto meta = file.metadata();
-
- if(!meta.has(fs_meta_name::length)) {
- fprintf(stderr, "Error: %s%c%s is not a readable file\n", apath.c_str(), fsm->directory_separator(), path.back().c_str());
- return 1;
- }
-
- image_handler::fsave(dstpath, file.read_all());
-
- bool has_rsrc = fsm->has_rsrc() && meta.has(fs_meta_name::rsrc_length);
-
- if(has_rsrc)
- image_handler::fsave_rsrc(image_handler::path_make_rsrc(dstpath), file.rsrc_read_all());
-
- return 0;
-}
-
-
-static int flopread(int argc, char *argv[])
-{
- if(argc!=7) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- display_usage();
- return 1;
- }
-
- image_handler ih;
- ih.set_on_disk_path(argv[4]);
-
- const floppy_format_info *source_format = find_floppy_source_format(argv[2], ih);
- if(!source_format)
- return 1;
-
- auto fs = formats.find_filesystem_format_by_key(argv[3]);
- if(!fs) {
- fprintf(stderr, "Error: Filesystem '%s' unknown\n", argv[3]);
- return 1;
- }
-
- if(!fs->m_manager || !fs->m_manager->can_read()) {
- fprintf(stderr, "Error: Filesystem '%s' does not implement reading\n", argv[3]);
- return 1;
- }
-
- if(ih.floppy_load(source_format)) {
- fprintf(stderr, "Error: Loading as format '%s' failed\n", source_format->m_format->name());
- return 1;
- }
-
- if(ih.floppy_mount_fs(fs)) {
- fprintf(stderr, "Error: Parsing as filesystem '%s' failed\n", fs->m_manager->name());
- return 1;
- }
-
- return generic_read(ih, argv[5], argv[6]);
-}
-
-static int hdread(int argc, char *argv[])
-{
- if(argc!=6) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- display_usage();
- return 1;
- }
-
- image_handler ih;
- ih.set_on_disk_path(argv[3]);
-
- auto fs = formats.find_filesystem_format_by_key(argv[2]);
- if(!fs) {
- fprintf(stderr, "Error: Filesystem '%s' unknown\n", argv[2]);
- return 1;
- }
-
- if(!fs->m_manager || !fs->m_manager->can_read()) {
- fprintf(stderr, "Error: Filesystem '%s' does not implement reading\n", argv[2]);
- return 1;
- }
-
- if(ih.hd_mount_fs(fs)) {
- fprintf(stderr, "Error: Parsing as filesystem '%s' failed\n", fs->m_manager->name());
- return 1;
- }
-
- return generic_read(ih, argv[4], argv[5]);
-}
-
-
-
-static int generic_write(image_handler &ih, const char *srcpath, const char *dstpath)
-{
- auto [fsm, fs] = ih.get_fs();
-
- std::vector path = ih.path_split(dstpath);
-
- auto dir = fs->root();
- std::string apath;
- for(unsigned int i = 0; i < path.size() - 1; i++) {
- auto c = dir.contents();
- unsigned int j;
- for(j = 0; j != c.size(); j++)
- if(c[j].m_name == path[i])
- break;
- if(j == c.size()) {
- fprintf(stderr, "Error: directory %s%c%s not found\n", apath.c_str(), fsm->directory_separator(), path[i].c_str());
- return 1;
- }
- if(c[j].m_type != fs_dir_entry_type::dir) {
- fprintf(stderr, "Error: %s%c%s is not a directory\n", apath.c_str(), fsm->directory_separator(), path[i].c_str());
- return 1;
- }
- dir = dir.dir_get(c[j].m_key);
- apath += fsm->directory_separator() + path[i];
- }
-
-
- fs_meta_data meta;
- meta.set(fs_meta_name::name, path.back());
-
- auto file = dir.file_create(meta);
- auto filedata = image_handler::fload(srcpath);
- file.replace(filedata);
-
- bool has_rsrc = fsm->has_rsrc();
-
- if(has_rsrc) {
- std::string rpath = image_handler::path_make_rsrc(dstpath);
-
- if(image_handler::fexists(rpath)) {
- filedata = image_handler::fload_rsrc(rpath);
- if(!filedata.empty())
- file.rsrc_replace(filedata);
- }
- }
-
- return 0;
-}
-
-
-static int flopwrite(int argc, char *argv[])
-{
- if(argc!=7) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- display_usage();
- return 1;
- }
-
- image_handler ih;
- ih.set_on_disk_path(argv[4]);
-
- const floppy_format_info *source_format = find_floppy_source_format(argv[2], ih);
- if(!source_format)
- return 1;
-
- auto fs = formats.find_filesystem_format_by_key(argv[3]);
- if(!fs) {
- fprintf(stderr, "Error: Filesystem '%s' unknown\n", argv[3]);
- return 1;
- }
-
- if(!fs->m_manager || !fs->m_manager->can_read()) {
- fprintf(stderr, "Error: Filesystem '%s' does not implement reading\n", argv[3]);
- return 1;
- }
-
- if(ih.floppy_load(source_format)) {
- fprintf(stderr, "Error: Loading as format '%s' failed\n", source_format->m_format->name());
- return 1;
- }
-
- if(ih.floppy_mount_fs(fs)) {
- fprintf(stderr, "Error: Parsing as filesystem '%s' failed\n", fs->m_manager->name());
- return 1;
- }
-
- int err = generic_write(ih, argv[5], argv[6]);
- if(err)
- return err;
-
- ih.fs_to_floppy();
- if(ih.floppy_save(source_format))
- return 1;
-
- return 0;
-}
-
-static int hdwrite(int argc, char *argv[])
-{
- if(argc!=6) {
- fprintf(stderr, "Incorrect number of arguments.\n\n");
- display_usage();
- return 1;
- }
-
-
- image_handler ih;
- ih.set_on_disk_path(argv[3]);
-
- auto fs = formats.find_filesystem_format_by_key(argv[2]);
- if(!fs) {
- fprintf(stderr, "Error: Filesystem '%s' unknown\n", argv[2]);
- return 1;
- }
-
- if(!fs->m_manager || !fs->m_manager->can_read()) {
- fprintf(stderr, "Error: Filesystem '%s' does not implement reading\n", argv[2]);
- return 1;
- }
-
- if(ih.hd_mount_fs(fs)) {
- fprintf(stderr, "Error: Parsing as filesystem '%s' failed\n", fs->m_manager->name());
- return 1;
- }
-
- return generic_write(ih, argv[4], argv[5]);
-}
-
-int CLIB_DECL main(int argc, char *argv[])
-{
- formats.init();
-
- if(argc == 1) {
- display_full_usage();
- return 0;
- }
-
- try {
- if(!core_stricmp("identify", argv[1]))
- return identify(argc, argv);
- else if(!core_stricmp("flopconvert", argv[1]))
- return flopconvert(argc, argv);
- else if(!core_stricmp("flopcreate", argv[1]))
- return flopcreate(argc, argv);
- else if(!core_stricmp("flopdir", argv[1]))
- return flopdir(argc, argv);
- else if(!core_stricmp("flopread", argv[1]))
- return flopread(argc, argv);
- else if(!core_stricmp("flopwrite", argv[1]))
- return flopwrite(argc, argv);
- else if(!core_stricmp("hddir", argv[1]))
- return hddir(argc, argv);
- else if(!core_stricmp("hdread", argv[1]))
- return hdread(argc, argv);
- else if(!core_stricmp("hdwrite", argv[1]))
- return hdwrite(argc, argv);
- else {
- fprintf(stderr, "Unknown command '%s'\n\n", argv[1]);
- display_usage();
- return 1;
- }
- } catch(const emu_fatalerror &err) {
- fprintf(stderr, "Error: %s", err.what());
- return 1;
- }
-}
diff --git a/src/tools/image_handler.cpp b/src/tools/image_handler.cpp
deleted file mode 100644
index a520383..0000000
--- a/src/tools/image_handler.cpp
+++ /dev/null
@@ -1,409 +0,0 @@
-// license:BSD-3-Clause
-// copyright-holders:Olivier Galibert
-
-// Image generic handler class and helpers
-
-#include "image_handler.h"
-
-#include "formats/all.h"
-#include "formats/fsblk_vec.h"
-#include "formats/fs_unformatted.h"
-
-#include "ioprocs.h"
-#include "ioprocsfill.h"
-#include "ioprocsvec.h"
-
-
-// Fatalerror implementation
-
-emu_fatalerror::emu_fatalerror(util::format_argument_pack const &args)
- : emu_fatalerror(0, args)
-{
-}
-
-emu_fatalerror::emu_fatalerror(int _exitcode, util::format_argument_pack const &args)
- : m_text(util::string_format(args))
- , m_code(_exitcode)
-{
-}
-
-
-// Format enumeration
-
-namespace {
- struct enumerator : public mame_formats_enumerator {
- formats_table *m_table;
- std::string m_category;
-
- enumerator(formats_table *table) : mame_formats_enumerator(), m_table(table), m_category("None") {}
-
- virtual ~enumerator() = default;
- virtual void add(const cassette_image::Format *const *formats) {}
-
- virtual void category(const char *name) {
- m_category = name;
- }
-
- virtual void add(floppy_format_type format) {
- m_table->floppy_format_infos.emplace_back(std::make_unique(format(), m_category));
- }
-
- virtual void add(const filesystem_manager_t &fs) {
- m_table->filesystem_formats.emplace_back(std::make_unique(&fs, m_category));
- }
- };
-
- struct fs_enum : public filesystem_manager_t::floppy_enumerator {
- filesystem_format *m_format;
-
- fs_enum(filesystem_format *format) : m_format(format) {}
-
- virtual void add(floppy_format_type type, u32 image_size, const char *name, const char *description) override {
- m_format->m_floppy = true;
- m_format->m_floppy_create.emplace_back(std::make_unique(m_format->m_manager, type, image_size, name, description));
- }
-
- virtual void add_raw(const char *name, u32 key, const char *description) override {
- m_format->m_floppy_raw = true;
- m_format->m_floppy_create.emplace_back(std::make_unique(name, key, description));
- }
- };
-}
-
-void formats_table::init()
-{
- std::vector variants;
-
- enumerator en(this);
- mame_formats_full_list(en);
-
- for(auto &f : filesystem_formats) {
- fs_enum fen(f.get());
- f->m_manager->enumerate_f(fen, floppy_image::FF_UNKNOWN, variants);
- }
-
- for(auto &f : floppy_format_infos) {
- auto *ff = f.get();
- std::string key = ff->m_format->name();
- auto i = floppy_format_info_by_key.find(key);
- if(i != floppy_format_info_by_key.end()) {
- fprintf(stderr, "Collision on floppy format name %s between \"%s\" and \"%s\".\n",
- ff->m_format->name(),
- ff->m_format->description(),
- i->second->m_format->description());
- exit(1);
- }
-
- floppy_format_info_by_key[key] = ff;
- floppy_format_info_by_category[ff->m_category].push_back(ff);
- }
-
- for(auto &f : filesystem_formats) {
- auto *ff = f.get();
- std::string key = ff->m_manager->name();
- auto i = filesystem_format_by_key.find(key);
- if(i != filesystem_format_by_key.end()) {
- fprintf(stderr, "Collision on filesystem name %s between \"%s\" and \"%s\".\n",
- ff->m_manager->name(),
- ff->m_manager->description(),
- i->second->m_manager->description());
- exit(1);
- }
-
- filesystem_format_by_key[key] = ff;
- filesystem_format_by_category[ff->m_category].push_back(ff);
-
- for(auto &f2 : ff->m_floppy_create) {
- auto *ff2 = f2.get();
- key = ff2->m_name;
- auto i = floppy_create_info_by_key.find(key);
- if(i != floppy_create_info_by_key.end()) {
- fprintf(stderr, "Collision on floppy create name %s between \"%s\" and \"%s\".\n",
- ff2->m_name,
- ff2->m_description,
- i->second->m_description);
- exit(1);
- }
-
- floppy_create_info_by_key[key] = ff2;
- }
- }
-}
-
-const floppy_format_info *formats_table::find_floppy_format_info_by_key(const std::string &key) const
-{
- auto i = floppy_format_info_by_key.find(key);
- return i == floppy_format_info_by_key.end() ? nullptr : i->second;
-}
-
-const filesystem_format *formats_table::find_filesystem_format_by_key(const std::string &key) const
-{
- auto i = filesystem_format_by_key.find(key);
- return i == filesystem_format_by_key.end() ? nullptr : i->second;
-}
-
-const floppy_create_info *formats_table::find_floppy_create_info_by_key(const std::string &key) const
-{
- auto i = floppy_create_info_by_key.find(key);
- return i == floppy_create_info_by_key.end() ? nullptr : i->second;
-}
-
-
-// Image handling
-
-std::vector image_handler::fload(std::string path)
-{
- char msg[4096];
- sprintf(msg, "Error opening %s for reading", path.c_str());
- auto fi = fopen(path.c_str(), "rb");
- if(!fi) {
- perror(msg);
- exit(1);
- }
- fseek(fi, 0, SEEK_END);
- long size = ftell(fi);
- std::vector filedata(size);
- fseek(fi, 0, SEEK_SET);
- fread(filedata.data(), filedata.size(), 1, fi);
- fclose(fi);
-
- return filedata;
-}
-
-std::vector image_handler::fload_rsrc(std::string path)
-{
- auto filedata = fload(path);
- const u8 *head = filedata.data();
-
- if(filesystem_t::r32b(head+0x00) == 0x00051607 &&
- filesystem_t::r32b(head+0x04) == 0x00020000) {
- u16 nent = filesystem_t::r16b(head+0x18);
- for(u16 i=0; i != nent; i++) {
- const u8 *e = head + 12*i;
- if(filesystem_t::r32b(e+0) == 2) {
- u32 start = filesystem_t::r32b(e+4);
- u32 len = filesystem_t::r32b(e+8);
- filedata.erase(filedata.begin(), filedata.begin() + start);
- filedata.erase(filedata.begin() + len, filedata.end());
- return filedata;
- }
- }
- }
- filedata.clear();
- return filedata;
-}
-
-void image_handler::fsave(std::string path, const std::vector &data)
-{
- char msg[4096];
- sprintf(msg, "Error opening %s for writing", path.c_str());
- auto fo = fopen(path.c_str(), "wb");
- if(!fo) {
- perror(msg);
- exit(1);
- }
-
- fwrite(data.data(), data.size(), 1, fo);
- fclose(fo);
-}
-
-void image_handler::fsave_rsrc(std::string path, const std::vector &data)
-{
- u8 head[0x2a];
-
- filesystem_t::w32b(head+0x00, 0x00051607); // Magic
- filesystem_t::w32b(head+0x04, 0x00020000); // Version
- filesystem_t::fill(head+0x08, 0, 16); // Filler
- filesystem_t::w16b(head+0x18, 1); // Number of entries
- filesystem_t::w32b(head+0x1a, 2); // Resource fork
- filesystem_t::w32b(head+0x22, 0x2a); // Offset in the file
- filesystem_t::w32b(head+0x26, data.size()); // Length
-
- char msg[4096];
- sprintf(msg, "Error opening %s for writing", path.c_str());
- auto fo = fopen(path.c_str(), "wb");
- if(!fo) {
- perror(msg);
- exit(1);
- }
-
- fwrite(head, sizeof(head), 1, fo);
- fwrite(data.data(), data.size(), 1, fo);
- fclose(fo);
-}
-
-image_handler::image_handler() : m_floppy_image(84, 2, floppy_image::FF_UNKNOWN)
-{
-}
-
-void image_handler::set_on_disk_path(std::string path)
-{
- m_on_disk_path = path;
-}
-
-std::vector> image_handler::identify(const formats_table &formats)
-{
- std::vector> res;
- std::vector variants;
-
- FILE *f = fopen(m_on_disk_path.c_str(), "rb");
- if (!f) {
- std::string msg = util::string_format("Error opening %s for reading", m_on_disk_path);
- perror(msg.c_str());
- return res;
- }
-
- auto io = util::stdio_read(f, 0xff);
-
- for(const auto &e : formats.floppy_format_info_by_key) {
- u8 score = e.second->m_format->identify(*io, floppy_image::FF_UNKNOWN, variants);
- if(score)
- res.emplace_back(std::make_pair(score, e.second));
- }
-
- return res;
-}
-
-bool image_handler::floppy_load(const floppy_format_info *format)
-{
- std::vector variants;
- FILE *f = fopen(m_on_disk_path.c_str(), "rb");
- if (!f) {
- std::string msg = util::string_format("Error opening %s for reading", m_on_disk_path);
- perror(msg.c_str());
- return true;
- }
-
- auto io = util::stdio_read(f, 0xff);
-
- return !format->m_format->load(*io, floppy_image::FF_UNKNOWN, variants, &m_floppy_image);
-}
-
-bool image_handler::floppy_save(const floppy_format_info *format)
-{
- std::vector variants;
- std::string msg = util::string_format("Error opening %s for writing", m_on_disk_path);
- FILE *f = fopen(m_on_disk_path.c_str(), "wb");
- if (!f) {
- perror(msg.c_str());
- return true;
- }
-
- auto io = util::stdio_read_write(f, 0xff);
-
- return !format->m_format->save(*io, variants, &m_floppy_image);
-}
-
-void image_handler::floppy_create(const floppy_create_info *format, fs_meta_data meta)
-{
- if(format->m_type) {
- std::vector variants;
- std::vector img(format->m_image_size);
- fsblk_vec_t blockdev(img);
- auto fs = format->m_manager->mount(blockdev);
- fs->format(meta);
-
- auto source_format = format->m_type();
- auto io = util::ram_read(img.data(), img.size(), 0xff);
- source_format->load(*io, floppy_image::FF_UNKNOWN, variants, &m_floppy_image);
- delete source_format;
- } else {
- fs_unformatted::format(format->m_key, &m_floppy_image);
- }
-}
-
-bool image_handler::floppy_mount_fs(const filesystem_format *format)
-{
- m_floppy_fs_converter = nullptr;
- for(const auto &ci : format->m_floppy_create) {
- if(ci->m_type != m_floppy_fs_converter) {
- std::vector variants;
- m_floppy_fs_converter = ci->m_type;
- m_sector_image.clear();
- auto load_format = m_floppy_fs_converter();
- util::random_read_write_fill_wrapper, 0xff> io(m_sector_image);
- load_format->save(io, variants, &m_floppy_image);
- delete load_format;
- }
-
- if(ci->m_image_size == m_sector_image.size())
- goto success;
- }
- m_floppy_fs_converter = nullptr;
- m_sector_image.clear();
- return true;
-
- success:
- m_fsblk.reset(new fsblk_vec_t(m_sector_image));
- m_fsm = format->m_manager;
- m_fs = m_fsm->mount(*m_fsblk);
- return false;
-}
-
-bool image_handler::hd_mount_fs(const filesystem_format *format)
-{
- // Should use the chd mechanisms, one thing at a time...
-
- m_sector_image = fload(m_on_disk_path);
- m_fsblk.reset(new fsblk_vec_t(m_sector_image));
- m_fsm = format->m_manager;
- m_fs = m_fsm->mount(*m_fsblk);
- return false;
-}
-
-void image_handler::fs_to_floppy()
-{
- std::vector variants;
- auto io = util::ram_read(m_sector_image.data(), m_sector_image.size(), 0xff);
- auto format = m_floppy_fs_converter();
- format->load(*io, floppy_image::FF_UNKNOWN, variants, &m_floppy_image);
- delete format;
-}
-
-std::vector image_handler::path_split(std::string path) const
-{
- std::string opath = path;
- std::vector rpath;
- if(m_fsm->has_subdirectories()) {
- std::string element;
- char sep = m_fsm->directory_separator();
- for(char c : opath) {
- if(c == sep) {
- if(!element.empty()) {
- rpath.push_back(element);
- element.clear();
- }
- } else
- element += c;
- }
- if(!element.empty())
- rpath.push_back(element);
-
- } else
- rpath.push_back(opath);
-
- return rpath;
-}
-
-bool image_handler::fexists(std::string path)
-{
- auto f = fopen(path.c_str(), "rb");
- if(f != nullptr) {
- fclose(f);
- return true;
- }
- return false;
-}
-
-
-std::string image_handler::path_make_rsrc(std::string path)
-{
- auto p = path.end();
- while(p != path.begin() && p[-1] != '/')
- p--;
- std::string rpath(path.begin(), p);
- rpath += "._";
- rpath += std::string(p, path.end());
- return rpath;
-}
-
diff --git a/src/tools/image_handler.h b/src/tools/image_handler.h
deleted file mode 100644
index d9a861b..0000000
--- a/src/tools/image_handler.h
+++ /dev/null
@@ -1,119 +0,0 @@
-// license:BSD-3-Clause
-// copyright-holders:Olivier Galibert
-
-// Image generic handler class and helpers
-
-#ifndef MAME_TOOLS_IMAGE_HANDLER_H
-#define MAME_TOOLS_IMAGE_HANDLER_H
-
-#pragma once
-
-#include "../emu/emucore.h"
-
-#include "formats/fsmgr.h"
-
-#include
-#include