diff --git a/MA2ME/AppDelegate.m b/MA2ME/AppDelegate.m index 583f0b4..6b03077 100644 --- a/MA2ME/AppDelegate.m +++ b/MA2ME/AppDelegate.m @@ -115,6 +115,7 @@ static NSString *kMyContext = @"kMyContext"; -(void)buildCommandLine { + static NSString *EmptyArg = @"\"\""; if (!_mameROM) { [self setCommandLine: @""]; @@ -154,10 +155,14 @@ static NSString *kMyContext = @"kMyContext"; } } + NSArray *args = [_slotController args]; - if ([args count]) { - [argv addObjectsFromArray: args]; + for (NSString *x in args) { + [argv addObject: [x length] ? x : EmptyArg]; } +// if ([args count]) { +// [argv addObjectsFromArray: args]; +// } if (_mameNoThrottle) [argv addObject: @"-nothrottle"]; diff --git a/MA2ME/Base.lproj/MainMenu.xib b/MA2ME/Base.lproj/MainMenu.xib index d941b7c..273494c 100644 --- a/MA2ME/Base.lproj/MainMenu.xib +++ b/MA2ME/Base.lproj/MainMenu.xib @@ -763,13 +763,6 @@ - - - - - - - diff --git a/MA2ME/MA2ME/Base.lproj/MediaView.xib b/MA2ME/MA2ME/Base.lproj/MediaView.xib index 0447cf8..abe9772 100644 --- a/MA2ME/MA2ME/Base.lproj/MediaView.xib +++ b/MA2ME/MA2ME/Base.lproj/MediaView.xib @@ -21,7 +21,7 @@ - + @@ -78,11 +78,18 @@ - + + + + + + + + - - - - - - - + + + + + + @@ -127,6 +133,7 @@ + diff --git a/MA2ME/MediaViewController.m b/MA2ME/MediaViewController.m index 10206b3..7ab22cf 100644 --- a/MA2ME/MediaViewController.m +++ b/MA2ME/MediaViewController.m @@ -58,15 +58,6 @@ return YES; } - --(void)prepareCell: (id)cell { - [(NSTextFieldCell *)cell setTitle: _title]; -} - --(Class)cellClass { - return [NSTextFieldCell class]; -} - -(NSString *)viewIdentifier { return @"CategoryView"; } @@ -114,15 +105,7 @@ return NO; } --(void)prepareCell: (id)cell { - [(NSPathCell *)cell setURL: _url]; - [(NSPathCell *)cell setPathStyle: NSPathStylePopUp]; -// [(NSTextFieldCell *)cell setTitle: @"xxx"]; -} --(Class)cellClass { - return [NSPathCell class]; -} -(NSString *)viewIdentifier { return @"ItemView"; @@ -131,19 +114,6 @@ -(void)prepareView: (TablePathView *)view { NSPathControl *pc = [view pathControl]; -#if 0 - Class pcClass = [NSPathControl class]; - if (!pc) { - for (NSView *v in [view subviews]) { - if ([v isKindOfClass: pcClass]) { - pc = v; - [view setPathControl: pc]; - break; - } - } - } - if (!pc) return; -#endif [pc setURL: _url]; //??? will binding take care of it? [pc unbind: @"value"]; [pc bind: @"value" toObject: self withKeyPath: @"url" options: nil]; @@ -244,14 +214,11 @@ } - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item { - return [item isGroupItem]; + return NO; //[item isGroupItem]; } -- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item { - [item prepareCell: cell]; -} - (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item { return NO; diff --git a/SlotViewController.m b/SlotViewController.m index 7a1a4f3..749002f 100644 --- a/SlotViewController.m +++ b/SlotViewController.m @@ -8,8 +8,13 @@ #import "SlotViewController.h" +const unsigned kMemoryMask = 1 << 16; + @interface SlotViewController () { + unsigned _slots_explicit; + unsigned _slots_valid; + unsigned _slots_default; } @property (weak) IBOutlet NSPopUpButton *ram_menu; @@ -80,7 +85,10 @@ [self setMemoryBytes: 0]; [self setResolution: NSMakeSize(0, 0)]; - + _slots_default = 0; + _slots_explicit = 0; + _slots_valid = 0; + [self setArgs: @[]]; } @@ -91,7 +99,8 @@ static NSFont *ItalicMenuFont(void) { return [NSFont fontWithDescriptor: fd2 size: [font pointSize]]; } -static void SetDefaultMenu(NSArray *items, NSPopUpButton *button) { +// entry 0 will always be empty. +static int SetDefaultMenu(NSArray *items, NSPopUpButton *button) { static NSDictionary *attr = nil; if (!attr) { @@ -114,9 +123,9 @@ static void SetDefaultMenu(NSArray *items, NSPopUpButton *button) { NSString *title = [d objectForKey: @"description"]; NSAttributedString *t = [[NSAttributedString alloc] initWithString: title attributes: attr]; [item setAttributedTitle: t]; - return; + return ix; } - + return 0; } -(void)syncMemory { @@ -124,70 +133,101 @@ static void SetDefaultMenu(NSArray *items, NSPopUpButton *button) { int ix = 0; NSArray *items = [_machine objectForKey: @"RAM"]; - SetDefaultMenu(items, _ram_menu); + unsigned default_index = SetDefaultMenu(items, _ram_menu); + _slots_valid |= kMemoryMask; + _slots_default &= ~kMemoryMask; + if (default_index) _slots_default |= kMemoryMask; - for (NSDictionary *d in items) { - unsigned size = [(NSNumber *)[d objectForKey: @"value"] unsignedIntValue]; - if (size == _memoryBytes) { - [_ram_menu selectItemAtIndex: ix]; - [self setMemory: [d objectForKey: @"description"]]; - return; - } - ++ix; - } + if (_slots_explicit & kMemoryMask) { + // if ram was explicitly set, try to keep it. - [self setMemoryBytes: 0]; - [self setMemory: @""]; - [_ram_menu selectItemAtIndex: 0]; - /* set to default */ + for (NSDictionary *d in items) { + unsigned size = [(NSNumber *)[d objectForKey: @"value"] unsignedIntValue]; + if (size == _memoryBytes) { + [_ram_menu selectItemAtIndex: ix]; + [self setMemory: [d objectForKey: @"description"]]; + return; + } + ++ix; + } + } + _slots_explicit &= ~kMemoryMask; + if (default_index) { + NSDictionary *d = [items objectAtIndex: default_index]; + + [_ram_menu selectItemAtIndex: default_index]; + [self setMemory: [d objectForKey: @"description"]]; + [self setMemoryBytes: [(NSNumber *)[d objectForKey: @"value"] unsignedIntValue]]; + } else { + [self setMemoryBytes: 0]; + [self setMemory: @""]; + [_ram_menu selectItemAtIndex: 0]; + } } --(void)syncSlot: (NSString *)slot button: (NSPopUpButton *)button { +-(void)syncSlot: (NSString *)slot button: (NSPopUpButton *)button index: (unsigned)index { NSString *value = [self valueForKey: slot]; NSArray *items = [_machine objectForKey: slot]; - SetDefaultMenu(items, button); - - if (![value length]) return; + unsigned mask = 1 << index; + _slots_default &= ~mask; if (![items count]) { [self setValue: @"" forKey: slot]; + _slots_explicit &= ~mask; + _slots_valid &= ~mask; return; } + _slots_valid |= mask; - int ix = 0; - for (NSDictionary *d in items) { - if ([value isEqualToString: [d objectForKey: @"value"]]) { + unsigned default_index = SetDefaultMenu(items, button); - [button selectItemAtIndex: ix]; - return; + 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]; + return; + } + ++ix; } - ++ix; } - [self setValue: @"" forKey: slot]; - [button selectItemAtIndex: 0]; + _slots_explicit &= ~mask; + if (default_index) { + NSDictionary *d = [items objectAtIndex: default_index]; + [button selectItemAtIndex: default_index]; + [self setValue: [d objectForKey: @"value"] forKey: slot]; + } else { + + [self setValue: @"" forKey: slot]; + [button selectItemAtIndex: 0]; + } } -(void)syncSlots { [self syncMemory]; - [self syncSlot: @"sl0" button: _sl0_menu]; - [self syncSlot: @"sl1" button: _sl1_menu]; - [self syncSlot: @"sl2" button: _sl2_menu]; - [self syncSlot: @"sl3" button: _sl3_menu]; - [self syncSlot: @"sl4" button: _sl4_menu]; - [self syncSlot: @"sl5" button: _sl5_menu]; - [self syncSlot: @"sl6" button: _sl6_menu]; - [self syncSlot: @"sl7" button: _sl7_menu]; - [self syncSlot: @"rs232" button: _rs232_menu]; - [self syncSlot: @"aux" button: _aux_menu]; - [self syncSlot: @"exp" button: _exp_menu]; - [self syncSlot: @"gameio" button: _game_menu]; - [self syncSlot: @"modem" button: _modem_menu]; - [self syncSlot: @"printer" button: _printer_menu]; + [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: @"rs232" button: _rs232_menu index: 8]; + [self syncSlot: @"aux" button: _aux_menu index: 9]; + [self syncSlot: @"exp" button: _exp_menu index: 10]; + [self syncSlot: @"gameio" button: _game_menu index: 11]; + [self syncSlot: @"modem" button: _modem_menu index: 12]; + [self syncSlot: @"printer" button: _printer_menu index: 13]; } -(void)loadMachine: (NSString *)model { @@ -232,6 +272,8 @@ static void SetDefaultMenu(NSArray *items, NSPopUpButton *button) { // NSInteger ix = [sender indexOfSelectedItem]; NSString *key = Names[tag]; + + _slots_explicit |= (1 << tag); NSDictionary *o = [[sender selectedItem] representedObject]; @@ -248,6 +290,8 @@ static void SetDefaultMenu(NSArray *items, NSPopUpButton *button) { [self setMemory: title]; [self setMemoryBytes: [(NSNumber *)[o objectForKey: @"value"] unsignedIntValue]]; + _slots_explicit |= kMemoryMask; + // if pull-down menu if ([sender pullsDown]) [sender setTitle: title]; @@ -255,29 +299,49 @@ static void SetDefaultMenu(NSArray *items, NSPopUpButton *button) { [self rebuildArgs]; } +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]; -#define _(a, b) if ([a length]) { [args addObject: b]; [args addObject: a]; } + + /* if there IS a default card for the slot and nothing is selected, need to -sl0 "" it. */ + - _(_memory, @"-ramsize") + #define _(ix, a, b) \ + if (should_add_arg(ix, _slots_valid, _slots_explicit, _slots_default, a)) { \ + [args addObject: b]; [args addObject: a]; \ + } \ - _(_sl0, @"-sl0") - _(_sl1, @"-sl1") - _(_sl2, @"-sl2") - _(_sl3, @"-sl3") - _(_sl4, @"-sl4") - _(_sl5, @"-sl5") - _(_sl6, @"-sl6") - _(_sl7, @"-sl7") + _(16, _memory, @"-ramsize") - _(_rs232, @"-rs232") - _(_aux, @"-aux") - _(_exp, @"-exp") - _(_gameio, @"-gameio") - _(_printer, @"-printer") - _(_modem, @"-modem") + _(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, _rs232, @"-rs232") + _(9, _aux, @"-aux") + _(10, _exp, @"-exp") + _(11, _gameio, @"-gameio") + _(12, _printer, @"-printer") + _(13, _modem, @"-modem") [self setArgs: args];