From 751083ea26ef0dc12856483a4c8cd2362fab7b15 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 30 May 2021 18:14:55 -0400 Subject: [PATCH] remove old slot view controller code/nib --- Ample.xcodeproj/project.pbxproj | 18 - Ample/Base.lproj/SlotView.xib | 632 -------------------------------- Ample/SlotViewController.h | 50 --- Ample/SlotViewController.m | 539 --------------------------- 4 files changed, 1239 deletions(-) delete mode 100644 Ample/Base.lproj/SlotView.xib delete mode 100644 Ample/SlotViewController.h delete mode 100644 Ample/SlotViewController.m diff --git a/Ample.xcodeproj/project.pbxproj b/Ample.xcodeproj/project.pbxproj index 5418721..1c1b50c 100644 --- a/Ample.xcodeproj/project.pbxproj +++ b/Ample.xcodeproj/project.pbxproj @@ -323,10 +323,8 @@ B6004DEF24FB05D600D38596 /* LogWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = LogWindow.xib; path = Base.lproj/LogWindow.xib; sourceTree = ""; }; B608E17D2502FE0C00D53465 /* TransparentScroller.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TransparentScroller.h; sourceTree = ""; }; B608E17E2502FE0C00D53465 /* TransparentScroller.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TransparentScroller.m; sourceTree = ""; }; - B60A6E0B24ECE23F004B7EEF /* apple2gs.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = apple2gs.plist; sourceTree = ""; }; B60A6E1224EE0AE2004B7EEF /* FlippedView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FlippedView.h; sourceTree = ""; }; B60A6E1324EE0AE2004B7EEF /* FlippedView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FlippedView.m; sourceTree = ""; }; - B61099E424F5F230005CB652 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/SlotView.xib; sourceTree = ""; }; B61099E624F5F230005CB652 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MediaView.xib; sourceTree = ""; }; B61099EA24F5F36E005CB652 /* apple2e.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = apple2e.plist; sourceTree = ""; }; B61099EB24F5F36E005CB652 /* hkc8800a.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = hkc8800a.plist; sourceTree = ""; }; @@ -421,8 +419,6 @@ B65085B625B616AC00354EC9 /* maclc2.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = maclc2.plist; sourceTree = ""; }; B65085B725B616AC00354EC9 /* maclc3.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = maclc3.plist; sourceTree = ""; }; B65085B825B616AC00354EC9 /* maciici.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = maciici.plist; sourceTree = ""; }; - B65593AF24ECB61800722E0C /* SlotViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SlotViewController.h; sourceTree = ""; }; - B65593B024ECB61800722E0C /* SlotViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SlotViewController.m; sourceTree = ""; }; B65D718525E70BD5008C5F87 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; B66236A724FD9A34006CABD7 /* PreferencesWindowController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PreferencesWindowController.h; sourceTree = ""; }; B66236A824FD9A34006CABD7 /* PreferencesWindowController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PreferencesWindowController.m; sourceTree = ""; }; @@ -434,7 +430,6 @@ B6665C1B265C639900254939 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/Autocomplete.xib; sourceTree = ""; }; B66D0FE62611386B000902F1 /* SoftwareList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SoftwareList.m; sourceTree = ""; }; B66D0FE926113AA8000902F1 /* SoftwareList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SoftwareList.h; sourceTree = ""; }; - B67BD48424EE249D0073E334 /* apple1.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = apple1.plist; sourceTree = ""; }; B6841BCA251EC88E006A5C39 /* vmnet_helper.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = vmnet_helper.c; sourceTree = ""; }; B6841BD0251EC913006A5C39 /* vmnet_helper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = vmnet_helper; sourceTree = BUILT_PRODUCTS_DIR; }; B6841BDD251ECC29006A5C39 /* vmnet.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = vmnet.framework; path = System/Library/Frameworks/vmnet.framework; sourceTree = SDKROOT; }; @@ -528,8 +523,6 @@ B649798C24EEC165008ABD20 /* Recovered References */ = { isa = PBXGroup; children = ( - B67BD48424EE249D0073E334 /* apple1.plist */, - B60A6E0B24ECE23F004B7EEF /* apple2gs.plist */, ); name = "Recovered References"; sourceTree = ""; @@ -687,8 +680,6 @@ B6E9A17F25088B1B005E7525 /* NewSlotViewController.m */, B6A1A1932528EB1700DB0FD7 /* Menu.m */, B6A1A1962528EB4600DB0FD7 /* Menu.h */, - B65593B024ECB61800722E0C /* SlotViewController.m */, - B65593AF24ECB61800722E0C /* SlotViewController.h */, B64979C024EF6703008ABD20 /* MediaViewController.h */, B64979C124EF6703008ABD20 /* MediaViewController.m */, B64E15A724EA1D5300E8AD3D /* MachineViewController.h */, @@ -747,7 +738,6 @@ B6BA258324E99BEB005FB8FF /* MainMenu.xib */, B61099E524F5F230005CB652 /* MediaView.xib */, B6D6DE3724FAC8B500661A5F /* Preferences.xib */, - B61099E324F5F230005CB652 /* SlotView.xib */, B64AF1EC250EC35B00A09B9B /* DiskImages.xib */, B63C1F0925B143C50016A611 /* CheatSheet.xib */, ); @@ -1206,14 +1196,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ - B61099E324F5F230005CB652 /* SlotView.xib */ = { - isa = PBXVariantGroup; - children = ( - B61099E424F5F230005CB652 /* Base */, - ); - name = SlotView.xib; - sourceTree = ""; - }; B61099E524F5F230005CB652 /* MediaView.xib */ = { isa = PBXVariantGroup; children = ( diff --git a/Ample/Base.lproj/SlotView.xib b/Ample/Base.lproj/SlotView.xib deleted file mode 100644 index cf3cb91..0000000 --- a/Ample/Base.lproj/SlotView.xib +++ /dev/null @@ -1,632 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - NSIsNil - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Ample/SlotViewController.h b/Ample/SlotViewController.h deleted file mode 100644 index 16973de..0000000 --- a/Ample/SlotViewController.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// SlotViewController.h -// Ample -// -// Created by Kelvin Sherlock on 8/18/2020. -// Copyright © 2020 Kelvin Sherlock. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface SlotViewController : NSViewController - -@property (nonatomic) NSString *model; -@property (nonatomic) NSDictionary *machine; - -@property NSString *memory; -@property NSUInteger memoryBytes; - -@property NSString *sl0; -@property NSString *sl1; -@property NSString *sl2; -@property NSString *sl3; -@property NSString *sl4; -@property NSString *sl5; -@property NSString *sl6; -@property NSString *sl7; - -@property NSString *rs232; -@property NSString *aux; -@property NSString *exp; -@property NSString *gameio; -@property NSString *printer; -@property NSString *modem; - -@property NSSize resolution; - -@property NSArray *args; -@property NSDictionary *media; - -//-(void)setMachine: (NSDictionary *)machine; - -- (IBAction)menuChanged:(id)sender; -- (IBAction)memoryMenuChanged:(id)sender; - --(IBAction)resetSlots: (id)sender; -@end - -NS_ASSUME_NONNULL_END diff --git a/Ample/SlotViewController.m b/Ample/SlotViewController.m deleted file mode 100644 index 5e0da70..0000000 --- a/Ample/SlotViewController.m +++ /dev/null @@ -1,539 +0,0 @@ -// -// SlotViewController.m -// Ample -// -// Created by Kelvin Sherlock on 8/18/2020. -// Copyright © 2020 Kelvin Sherlock. All rights reserved. -// - -#import "SlotViewController.h" - -const unsigned kMemoryMask = 1 << 16; - -@interface SlotViewController () { - - unsigned _slots_explicit; - unsigned _slots_valid; - unsigned _slots_default; - - NSDictionary *_slot_object[14]; - NSDictionary *_slot_media[14]; - NSDictionary *_machine_media; -} - -@property (weak) IBOutlet NSPopUpButton *ram_menu; -@property (weak) IBOutlet NSPopUpButton *sl0_menu; -@property (weak) IBOutlet NSPopUpButton *sl1_menu; -@property (weak) IBOutlet NSPopUpButton *sl2_menu; -@property (weak) IBOutlet NSPopUpButton *sl3_menu; -@property (weak) IBOutlet NSPopUpButton *sl4_menu; -@property (weak) IBOutlet NSPopUpButton *sl5_menu; -@property (weak) IBOutlet NSPopUpButton *sl6_menu; -@property (weak) IBOutlet NSPopUpButton *sl7_menu; -@property (weak) IBOutlet NSPopUpButton *exp_menu; -@property (weak) IBOutlet NSPopUpButton *aux_menu; -@property (weak) IBOutlet NSPopUpButton *rs232_menu; -@property (weak) IBOutlet NSPopUpButton *game_menu; -@property (weak) IBOutlet NSPopUpButton *printer_menu; -@property (weak) IBOutlet NSPopUpButton *modem_menu; - - -@end - -@implementation SlotViewController - - -- (void)viewDidLoad { - [super viewDidLoad]; - // Do view setup here. - - //[self setModel: @"apple2gs"]; -} - --(void)reset { - -} - - --(void)setModel:(NSString *)model { - - if (model == _model) return; - if ([model isEqualToString: _model]) return; - - _model = model; - - [self loadMachine: model]; -} - --(void)resetMachine { - - [self setMachine: @{}]; -#if 0 - [self setSl0: @""]; - [self setSl1: @""]; - [self setSl2: @""]; - [self setSl3: @""]; - [self setSl4: @""]; - [self setSl5: @""]; - [self setSl6: @""]; - [self setSl7: @""]; - - [self setRs232: @""]; - [self setAux: @""]; - [self setExp: @""]; - [self setGameio: @""]; - [self setPrinter: @""]; - [self setModem: @""]; - - [self setMemory: @""]; - [self setMemoryBytes: 0]; -#endif - [self setResolution: NSMakeSize(0, 0)]; - - _slots_default = 0; - //_slots_explicit = 0; - _slots_valid = 0; - - _machine_media = nil; - - [self setArgs: @[]]; - [self setMedia: @{}]; - - -#if 0 - // retain for later? - for (unsigned i = 0; i < 14; ++i) { - _slot_media[i] = nil; - _slot_object[i] = nil; - } -#endif -} - -static NSFont *ItalicMenuFont(void) { - NSFont *font = [NSFont menuFontOfSize: 0]; - NSFontDescriptor *fd = [font fontDescriptor]; - NSFontDescriptor *fd2 = [fd fontDescriptorWithSymbolicTraits: NSFontDescriptorTraitItalic]; - return [NSFont fontWithDescriptor: fd2 size: [font pointSize]]; -} - -// entry 0 is None/Empty for slots, but populated for RAM. -static int SetDefaultMenu(NSArray *items, NSPopUpButton *button) { - - static NSDictionary *attr = nil; - if (!attr) { - attr = @{ - NSFontAttributeName: ItalicMenuFont() - }; - } - - unsigned ix = 0; - - - for (NSDictionary *d in items) { - BOOL def = [(NSNumber *)[d objectForKey: @"default"] boolValue]; - if (!def) { - ++ix; - continue; - } - - NSMenuItem *item = [button itemAtIndex: ix]; - NSString *title = [d objectForKey: @"description"]; - NSAttributedString *t = [[NSAttributedString alloc] initWithString: title attributes: attr]; - [item setAttributedTitle: t]; - return ix; - } - return 0; -} - -static void DeactivateMenus(NSArray *items, NSPopUpButton *button) { - - [button setAutoenablesItems: NO]; - unsigned ix = 0; - for (NSDictionary *d in items) { - BOOL value = [(NSNumber *)[d objectForKey: @"disabled"] boolValue]; - if (value) { - - NSMenuItem *item = [button itemAtIndex: ix]; - [item setEnabled: NO]; - } - ++ix; - } - -} - --(void)syncMemory { - - int ix = 0; - NSArray *items = [_machine objectForKey: @"ram"]; - - unsigned default_index = SetDefaultMenu(items, _ram_menu); - _slots_valid |= kMemoryMask; - _slots_default &= ~kMemoryMask; - if (default_index) _slots_default |= kMemoryMask; - - if (_slots_explicit & kMemoryMask) { - // if ram was explicitly set, try to keep it. - - for (NSDictionary *d in items) { - unsigned size = [(NSNumber *)[d objectForKey: @"intValue"] unsignedIntValue]; - if (size == _memoryBytes) { - [_ram_menu selectItemAtIndex: ix]; - [self setMemory: [d objectForKey: @"value"]]; - return; - } - ++ix; - } - } - - _slots_explicit &= ~kMemoryMask; - if (default_index) { - NSDictionary *d = [items objectAtIndex: default_index]; - - [_ram_menu selectItemAtIndex: default_index]; - [self setMemory: [d objectForKey: @"value"]]; - [self setMemoryBytes: [(NSNumber *)[d objectForKey: @"intValue"] unsignedIntValue]]; - } else { - [self setMemoryBytes: 0]; - [self setMemory: @""]; - [_ram_menu selectItemAtIndex: 0]; - } -} - --(void)resetMemory { - - NSArray *items = [_machine objectForKey: @"ram"]; - if (![items count]) return; - - unsigned ix = 0; - for (NSDictionary *d in items) { - BOOL def = [(NSNumber *)[d objectForKey: @"default"] boolValue]; - if (!def) { - ++ix; - continue; - } - // ram should always have a default. - [_ram_menu selectItemAtIndex: ix]; - [self setMemory: [d objectForKey: @"description"]]; - _slots_default |= kMemoryMask; - return; - } - // just in case - [_ram_menu selectItemAtIndex: 0]; -} - --(void)syncSlot: (NSString *)slot button: (NSPopUpButton *)button index: (unsigned)index { - - NSString *value = [self valueForKey: slot]; - NSArray *items = [_machine objectForKey: slot]; - - unsigned mask = 1 << index; - - _slots_default &= ~mask; - _slots_valid &= ~mask; - - if (![items count]) { - //[self setValue: @"" forKey: slot]; // retain for later. - //_slots_explicit &= ~mask; - - return; - } - _slots_valid |= mask; - - DeactivateMenus(items, button); - unsigned default_index = SetDefaultMenu(items, button); - - if (default_index) _slots_default |= mask; - - - if (_slots_explicit & mask) { - int ix = 0; - for (NSDictionary *d in items) { - if ([value isEqualToString: [d objectForKey: @"value"]]) { - - [button selectItemAtIndex: ix]; - _slot_object[index] = d; - _slot_media[index] = [d objectForKey: @"media"]; - return; - } - ++ix; - } - } - _slots_explicit &= ~mask; - - if (default_index) { - NSDictionary *d = [items objectAtIndex: default_index]; - [button selectItemAtIndex: default_index]; - [self setValue: [d objectForKey: @"value"] forKey: slot]; - _slot_object[index] = d; - _slot_media[index] = [d objectForKey: @"media"]; - } else { - [button selectItemAtIndex: 0]; - [self setValue: @"" forKey: slot]; - _slot_object[index] = nil; - _slot_media[index] = nil; - } -} - --(void)resetSlot: (NSString *)slot button: (NSPopUpButton *)button index: (unsigned)index { - - NSArray *items = [_machine objectForKey: slot]; - if (![items count]) return; - - unsigned ix = 0; - for (NSDictionary *d in items) { - BOOL def = [(NSNumber *)[d objectForKey: @"default"] boolValue]; - if (!def) { - ++ix; - continue; - } - [button selectItemAtIndex: ix]; - [self setValue: [d objectForKey: @"value"] forKey: slot]; - _slot_object[index] = d; - _slot_media[index] = [d objectForKey: @"media"]; - - _slots_default |= (1 << index); - return; - } - // just in case - NSDictionary *d = [items firstObject]; - - [button selectItemAtIndex: 0]; - [self setValue: [d objectForKey: @"value"] forKey: slot]; - _slot_object[index] = d; - _slot_media[index] = [d objectForKey: @"media"]; -} - --(void)syncSlots { - - [self syncMemory]; - [self syncSlot: @"sl0" button: _sl0_menu index: 0]; - [self syncSlot: @"sl1" button: _sl1_menu index: 1]; - [self syncSlot: @"sl2" button: _sl2_menu index: 2]; - [self syncSlot: @"sl3" button: _sl3_menu index: 3]; - [self syncSlot: @"sl4" button: _sl4_menu index: 4]; - [self syncSlot: @"sl5" button: _sl5_menu index: 5]; - [self syncSlot: @"sl6" button: _sl6_menu index: 6]; - [self syncSlot: @"sl7" button: _sl7_menu index: 7]; - [self syncSlot: @"exp" button: _exp_menu index: 8]; - [self syncSlot: @"aux" button: _aux_menu index: 9]; - [self syncSlot: @"rs232" button: _rs232_menu index: 10]; - [self syncSlot: @"gameio" button: _game_menu index: 11]; - [self syncSlot: @"printer" button: _printer_menu index: 12]; - [self syncSlot: @"modem" button: _modem_menu index: 13]; -} - --(void)loadMachine: (NSString *)model { - - if (!model) { - [self resetMachine]; - return; - } - - NSBundle *bundle = [NSBundle mainBundle]; - NSURL *url= [bundle URLForResource: model withExtension: @"plist"]; - - NSDictionary *d = [NSDictionary dictionaryWithContentsOfURL: url]; - - if (!d) { - [self resetMachine]; - return; - } - - NSArray *r = [d objectForKey: @"resolution"]; - NSSize res = NSMakeSize(0, 0); - if (r) { - res.width = [(NSNumber *)[r objectAtIndex: 0 /*@"width"*/] doubleValue]; - res.height = [(NSNumber *)[r objectAtIndex: 1 /*@"height"*/] doubleValue]; - } - [self setResolution: res]; - - _machine_media = [d objectForKey: @"media"]; - - // n.b. - does content binding propogate immediately? - [self setMachine: d]; - [self syncSlots]; - [self rebuildArgs]; - [self rebuildMedia]; -} - -static NSString *SlotNames[] = { - - @"sl0", @"sl1", @"sl2", @"sl3", - @"sl4", @"sl5", @"sl6", @"sl7", - @"exp", @"aux", @"rs232", - @"gameio", @"printer", @"modem", -}; - -unsigned SlotCount = 14; - -- (IBAction)menuChanged:(NSPopUpButton *)sender { - - - - NSInteger tag = [sender tag]; - -// NSInteger ix = [sender indexOfSelectedItem]; - - NSString *key = SlotNames[tag]; - - _slots_explicit |= (1 << tag); - - NSDictionary *o = [[sender selectedItem] representedObject]; - - [self setValue: [o objectForKey: @"value"] forKey: key]; - - _slot_object[tag] = o; - NSDictionary *newMedia = [o objectForKey: @"media"]; - NSDictionary *oldMedia = _slot_media[tag]; - - if (newMedia != oldMedia) { - _slot_media[tag] = newMedia; - [self rebuildMedia]; - } - - - [self rebuildArgs]; -} - -- (IBAction)memoryMenuChanged:(NSPopUpButton *)sender { - - // - NSDictionary *o = [[sender selectedItem] representedObject]; - NSString *title = [o objectForKey: @"description"]; - [self setMemory: title]; - [self setMemoryBytes: [(NSNumber *)[o objectForKey: @"value"] unsignedIntValue]]; - - _slots_explicit |= kMemoryMask; - - // if pull-down menu - if ([sender pullsDown]) - [sender setTitle: title]; - - [self rebuildArgs]; -} - --(IBAction)resetSlots:(id)sender { - /* reset slots to default */ - - _slots_explicit = 0; - _slots_default = 0; - for (unsigned i = 0 ; i < SlotCount; ++i) { - [self setValue: @"" forKey: SlotNames[i]]; - _slot_media[i] = nil; - _slot_object[i] = nil; - } - _memory = @""; - _memoryBytes = 0; - - [self resetMemory]; - [self resetSlot: @"sl0" button: _sl0_menu index: 0]; - [self resetSlot: @"sl1" button: _sl1_menu index: 1]; - [self resetSlot: @"sl2" button: _sl2_menu index: 2]; - [self resetSlot: @"sl3" button: _sl3_menu index: 3]; - [self resetSlot: @"sl4" button: _sl4_menu index: 4]; - [self resetSlot: @"sl5" button: _sl5_menu index: 5]; - [self resetSlot: @"sl6" button: _sl6_menu index: 6]; - [self resetSlot: @"sl7" button: _sl7_menu index: 7]; - [self resetSlot: @"exp" button: _exp_menu index: 8]; - [self resetSlot: @"aux" button: _aux_menu index: 9]; - [self resetSlot: @"rs232" button: _rs232_menu index: 10]; - [self resetSlot: @"gameio" button: _game_menu index: 11]; - [self resetSlot: @"printer" button: _printer_menu index: 12]; - [self resetSlot: @"modem" button: _modem_menu index: 13]; - - [self rebuildArgs]; - [self rebuildMedia]; -} - -static BOOL should_add_arg(unsigned slot, unsigned valid_slots, unsigned explicit_slots, unsigned default_slots, NSString *value) { - - unsigned mask = 1 << slot; - if (~valid_slots & mask) return NO; - - if (default_slots & mask) { - if (explicit_slots & mask) - return YES; - return NO; - } - return [value length]; -} - --(void)rebuildArgs { - - NSMutableArray *args = [NSMutableArray new]; - - - /* if there IS a default card for the slot and nothing is selected, need to -sl0 "" it. */ - - - #define _(ix, a, b) \ - if (should_add_arg(ix, _slots_valid, _slots_explicit, _slots_default, a)) { \ - [args addObject: b]; [args addObject: a]; \ - } \ - - _(16, _memory, @"-ramsize") - - _(0, _sl0, @"-sl0") - _(1, _sl1, @"-sl1") - _(2, _sl2, @"-sl2") - _(3, _sl3, @"-sl3") - _(4, _sl4, @"-sl4") - _(5, _sl5, @"-sl5") - _(6, _sl6, @"-sl6") - _(7, _sl7, @"-sl7") - _(8, _exp, @"-exp") - _(9, _aux, @"-aux") - _(10, _rs232, @"-rs232") - _(11, _gameio, @"-gameio") - _(12, _printer, @"-printer") - _(13, _modem, @"-modem") -#undef _ - [self setArgs: args]; -} - - --(void)rebuildMedia { - - -#define _(var, o) var += [[o objectForKey: @ # var ] unsignedIntValue] - - unsigned cass = 0; - unsigned cdrm = 0; - unsigned hard = 0; - unsigned flop_5_25 = 0; - unsigned flop_3_5 = 0; - - unsigned mask = 1; - for (unsigned i = 0; i < 14; ++i, mask <<= 1) { - - if (_slots_valid & mask) { - NSDictionary *tmp = _slot_media[i]; - if (tmp) { - _(cass, tmp); - _(cdrm, tmp); - _(hard, tmp); - _(flop_5_25, tmp); - _(flop_3_5, tmp); - } - } - } - NSDictionary *tmp = _machine_media; - if (tmp) { - _(cass, tmp); - _(cdrm, tmp); - _(hard, tmp); - _(flop_5_25, tmp); - _(flop_3_5, tmp); - } - - [self setMedia: @{ - @"cass": @(cass), - @"cdrm": @(cdrm), - @"hard": @(hard), - @"flop_5_25": @(flop_5_25), - @"flop_3_5": @(flop_3_5), - }]; -} - - -@end