use an enum to identify special slots types (ram, bios, floppy disk controller)

This commit is contained in:
Kelvin Sherlock 2023-11-04 13:51:44 -04:00
parent 9b3223478c
commit 6ef3911da7
3 changed files with 28 additions and 5 deletions

View File

@ -15,6 +15,12 @@
@class Slot, SlotOption, SlotTableCellView;
typedef enum SlotType {
kSlotRAM = 1,
kSlotBIOS,
kSlotFDC,
} SlotType;
@interface Slot : NSObject<NSCopying>
@property NSInteger defaultIndex;
@ -24,6 +30,7 @@
@property (readonly) NSString *name;
@property (readonly) NSString *title;
@property (readonly) NSArray *menuItems;
@property (readonly) SlotType type;
@property (readonly) SlotOption *selectedItem;
@property (readonly) NSString *selectedValue;

View File

@ -72,6 +72,18 @@ static NSArray *DeepCopyArray(NSArray *src) {
@implementation Slot
@synthesize type = _type;
static NSDictionary *TypeMap = nil;
+(void)load {
TypeMap = @{
@"ramsize": @(kSlotRAM),
@"smartport": @(kSlotFDC),
@"bios": @(kSlotBIOS),
};
}
-(void)reset {
[self setSelectedIndex: _defaultIndex >= 0 ? _defaultIndex : 0];
@ -129,7 +141,7 @@ static NSArray *DeepCopyArray(NSArray *src) {
// { 'sl3' : 'uthernet' }
// special case for smartport since the name isn't used.
if ([_name isEqualToString: @"-smartport"]) {
if (_type == kSlotFDC) {
SlotOption *option = [_options objectAtIndex: _selectedIndex];
[option reserialize: dict];
return;
@ -264,7 +276,11 @@ static NSArray *DeepCopyArray(NSArray *src) {
_name = [data objectForKey: @"name"];
_title = [data objectForKey: @"description"];
NSNumber *x = [TypeMap objectForKey: _name];
if (x) _type = [x intValue];
if (index < 0x10000) {
topLevel = YES;
_name = [@"-" stringByAppendingString: _name];
@ -340,7 +356,7 @@ static NSArray *DeepCopyArray(NSArray *src) {
// [menu setItemArray: ] doesn't work prior to 10.14, apparently.
[menu removeAllItems];
if ([_name isEqualToString: @"-smartport"]) {
if (_type == kSlotFDC) {
//[menu setItemArray: @[]];
[button setHidden: YES];
} else {

View File

@ -112,7 +112,7 @@ static unsigned RootKey = 0;
NSInteger index = [item index] - 1;
if (index < 0 || index >= MAX_SLOTS) continue;
if ([name isEqualToString: @"-bios"]) continue;
if ([item type] == kSlotBIOS) continue;
NSString *v = [_slotValues objectForKey: name];
if (v) {
@ -191,7 +191,7 @@ static unsigned RootKey = 0;
SlotOption *o = [[sender selectedItem] representedObject];
Slot *item = [_root objectAtIndex: index];
if (direct) {
if (direct && [item type] != kSlotBIOS) {
NSString *name = [item name];
NSString *value = [o value];
[_slotValues setObject: value forKey: name];