diff --git a/desmume/src/frontend/cocoa/cocoa_core.mm b/desmume/src/frontend/cocoa/cocoa_core.mm index cc988a525..947e78ab0 100644 --- a/desmume/src/frontend/cocoa/cocoa_core.mm +++ b/desmume/src/frontend/cocoa/cocoa_core.mm @@ -724,8 +724,7 @@ volatile bool execute = true; - (NSString *) firmwareMACAddressSelectionString { // TODO: Also handle the case of returning the correct MAC address of external firmware. - //return [NSString stringWithFormat:@"Firmware %@", [[self cdsFirmware] MACAddressString]]; - return @"Firmware 00:09:BF:FF:FF:FF"; + return [NSString stringWithFormat:@"Firmware %@", [[self cdsFirmware] MACAddressString]]; } - (pthread_rwlock_t *) rwlockCoreExecute @@ -745,8 +744,7 @@ volatile bool execute = true; newMACAddress[4] = (macValue >> 8) & 0x000000FF; newMACAddress[5] = (macValue >> 16) & 0x000000FF; - //[[self cdsFirmware] setMACAddress:newMACAddress]; - + [[self cdsFirmware] setMACAddress:newMACAddress]; [self setFirmwareMACAddressSelectionString:NULL]; } diff --git a/desmume/src/frontend/cocoa/cocoa_firmware.h b/desmume/src/frontend/cocoa/cocoa_firmware.h index 9e2b1aa49..74e8d5785 100644 --- a/desmume/src/frontend/cocoa/cocoa_firmware.h +++ b/desmume/src/frontend/cocoa/cocoa_firmware.h @@ -1,6 +1,6 @@ /* Copyright (C) 2011 Roger Manuel - Copyright (C) 2012-2015 DeSmuME team + Copyright (C) 2012-2018 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,38 +24,153 @@ CocoaDSFirmware - OBJECTIVE-C CLASS This is an Objective-C wrapper class for DeSmuME's firmware struct. - - If this object is instantiated through any init method other than initWithFirmwareData:, - this object allocate memory for its own internal firmware struct. This memory is then - freed upon the release of this object. - - If this object is instantiated using initWithFirmwareData:, or if a firmware struct is - assigned through the data property, the firmware struct is not freed upon the release - of this object. This is by design. Thread Safety: All methods are thread-safe. ********************************************************************************************/ @interface CocoaDSFirmware : NSObject { - struct NDS_fw_config_data *data; struct NDS_fw_config_data *internalData; - NSUInteger birth_year; + NSUInteger _birth_year; + uint8_t _MACAddress[6]; + + NSInteger ipv4Address_AP1_1; + NSInteger ipv4Address_AP1_2; + NSInteger ipv4Address_AP1_3; + NSInteger ipv4Address_AP1_4; + NSInteger ipv4Gateway_AP1_1; + NSInteger ipv4Gateway_AP1_2; + NSInteger ipv4Gateway_AP1_3; + NSInteger ipv4Gateway_AP1_4; + NSInteger ipv4PrimaryDNS_AP1_1; + NSInteger ipv4PrimaryDNS_AP1_2; + NSInteger ipv4PrimaryDNS_AP1_3; + NSInteger ipv4PrimaryDNS_AP1_4; + NSInteger ipv4SecondaryDNS_AP1_1; + NSInteger ipv4SecondaryDNS_AP1_2; + NSInteger ipv4SecondaryDNS_AP1_3; + NSInteger ipv4SecondaryDNS_AP1_4; + NSInteger subnetMask_AP1; + NSString *subnetMaskString_AP1; + + NSInteger ipv4Address_AP2_1; + NSInteger ipv4Address_AP2_2; + NSInteger ipv4Address_AP2_3; + NSInteger ipv4Address_AP2_4; + NSInteger ipv4Gateway_AP2_1; + NSInteger ipv4Gateway_AP2_2; + NSInteger ipv4Gateway_AP2_3; + NSInteger ipv4Gateway_AP2_4; + NSInteger ipv4PrimaryDNS_AP2_1; + NSInteger ipv4PrimaryDNS_AP2_2; + NSInteger ipv4PrimaryDNS_AP2_3; + NSInteger ipv4PrimaryDNS_AP2_4; + NSInteger ipv4SecondaryDNS_AP2_1; + NSInteger ipv4SecondaryDNS_AP2_2; + NSInteger ipv4SecondaryDNS_AP2_3; + NSInteger ipv4SecondaryDNS_AP2_4; + NSInteger subnetMask_AP2; + NSString *subnetMaskString_AP2; + + NSInteger ipv4Address_AP3_1; + NSInteger ipv4Address_AP3_2; + NSInteger ipv4Address_AP3_3; + NSInteger ipv4Address_AP3_4; + NSInteger ipv4Gateway_AP3_1; + NSInteger ipv4Gateway_AP3_2; + NSInteger ipv4Gateway_AP3_3; + NSInteger ipv4Gateway_AP3_4; + NSInteger ipv4PrimaryDNS_AP3_1; + NSInteger ipv4PrimaryDNS_AP3_2; + NSInteger ipv4PrimaryDNS_AP3_3; + NSInteger ipv4PrimaryDNS_AP3_4; + NSInteger ipv4SecondaryDNS_AP3_1; + NSInteger ipv4SecondaryDNS_AP3_2; + NSInteger ipv4SecondaryDNS_AP3_3; + NSInteger ipv4SecondaryDNS_AP3_4; + NSInteger subnetMask_AP3; + NSString *subnetMaskString_AP3; + + NSInteger backlightLevel; + pthread_mutex_t mutex; } -@property (assign) struct NDS_fw_config_data *data; +@property (readonly) struct NDS_fw_config_data *internalData; + +// WiFi Info +@property (assign) NSString *MACAddressString; + +// Access Point Settings +@property (assign) NSInteger ipv4Address_AP1_1; +@property (assign) NSInteger ipv4Address_AP1_2; +@property (assign) NSInteger ipv4Address_AP1_3; +@property (assign) NSInteger ipv4Address_AP1_4; +@property (assign) NSInteger ipv4Gateway_AP1_1; +@property (assign) NSInteger ipv4Gateway_AP1_2; +@property (assign) NSInteger ipv4Gateway_AP1_3; +@property (assign) NSInteger ipv4Gateway_AP1_4; +@property (assign) NSInteger ipv4PrimaryDNS_AP1_1; +@property (assign) NSInteger ipv4PrimaryDNS_AP1_2; +@property (assign) NSInteger ipv4PrimaryDNS_AP1_3; +@property (assign) NSInteger ipv4PrimaryDNS_AP1_4; +@property (assign) NSInteger ipv4SecondaryDNS_AP1_1; +@property (assign) NSInteger ipv4SecondaryDNS_AP1_2; +@property (assign) NSInteger ipv4SecondaryDNS_AP1_3; +@property (assign) NSInteger ipv4SecondaryDNS_AP1_4; +@property (assign) NSInteger subnetMask_AP1; +@property (retain) NSString *subnetMaskString_AP1; + +@property (assign) NSInteger ipv4Address_AP2_1; +@property (assign) NSInteger ipv4Address_AP2_2; +@property (assign) NSInteger ipv4Address_AP2_3; +@property (assign) NSInteger ipv4Address_AP2_4; +@property (assign) NSInteger ipv4Gateway_AP2_1; +@property (assign) NSInteger ipv4Gateway_AP2_2; +@property (assign) NSInteger ipv4Gateway_AP2_3; +@property (assign) NSInteger ipv4Gateway_AP2_4; +@property (assign) NSInteger ipv4PrimaryDNS_AP2_1; +@property (assign) NSInteger ipv4PrimaryDNS_AP2_2; +@property (assign) NSInteger ipv4PrimaryDNS_AP2_3; +@property (assign) NSInteger ipv4PrimaryDNS_AP2_4; +@property (assign) NSInteger ipv4SecondaryDNS_AP2_1; +@property (assign) NSInteger ipv4SecondaryDNS_AP2_2; +@property (assign) NSInteger ipv4SecondaryDNS_AP2_3; +@property (assign) NSInteger ipv4SecondaryDNS_AP2_4; +@property (assign) NSInteger subnetMask_AP2; +@property (retain) NSString *subnetMaskString_AP2; + +@property (assign) NSInteger ipv4Address_AP3_1; +@property (assign) NSInteger ipv4Address_AP3_2; +@property (assign) NSInteger ipv4Address_AP3_3; +@property (assign) NSInteger ipv4Address_AP3_4; +@property (assign) NSInteger ipv4Gateway_AP3_1; +@property (assign) NSInteger ipv4Gateway_AP3_2; +@property (assign) NSInteger ipv4Gateway_AP3_3; +@property (assign) NSInteger ipv4Gateway_AP3_4; +@property (assign) NSInteger ipv4PrimaryDNS_AP3_1; +@property (assign) NSInteger ipv4PrimaryDNS_AP3_2; +@property (assign) NSInteger ipv4PrimaryDNS_AP3_3; +@property (assign) NSInteger ipv4PrimaryDNS_AP3_4; +@property (assign) NSInteger ipv4SecondaryDNS_AP3_1; +@property (assign) NSInteger ipv4SecondaryDNS_AP3_2; +@property (assign) NSInteger ipv4SecondaryDNS_AP3_3; +@property (assign) NSInteger ipv4SecondaryDNS_AP3_4; +@property (assign) NSInteger subnetMask_AP3; +@property (retain) NSString *subnetMaskString_AP3; + +// User Settings @property (assign) NSInteger consoleType; @property (copy) NSString *nickname; @property (copy) NSString *message; @property (assign) NSInteger favoriteColor; @property (assign) NSDate *birthday; @property (assign) NSInteger language; +@property (assign) NSInteger backlightLevel; + +- (void) setMACAddress:(const uint8_t *)inMACAddress; +- (uint8_t *) MACAddress; -- (id) initWithDictionary:(NSDictionary *)dataDict; -- (id) initWithFirmwareData:(struct NDS_fw_config_data *)fwData; - (void) update; -- (void) setDataWithDictionary:(NSDictionary *)fwDataDict; -- (NSDictionary *) dataDictionary; @end diff --git a/desmume/src/frontend/cocoa/cocoa_firmware.mm b/desmume/src/frontend/cocoa/cocoa_firmware.mm index b04615952..b6de0cf10 100644 --- a/desmume/src/frontend/cocoa/cocoa_firmware.mm +++ b/desmume/src/frontend/cocoa/cocoa_firmware.mm @@ -1,6 +1,6 @@ /* Copyright (C) 2011 Roger Manuel - Copyright (C) 2012-2015 DeSmuME team + Copyright (C) 2012-2018 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,25 +19,82 @@ #import "cocoa_firmware.h" #include "../../NDSSystem.h" #include "../../firmware.h" +#include "../../MMU.h" #undef BOOL @implementation CocoaDSFirmware -@synthesize data; +@synthesize internalData; + +@dynamic MACAddressString; + +@synthesize ipv4Address_AP1_1; +@synthesize ipv4Address_AP1_2; +@synthesize ipv4Address_AP1_3; +@synthesize ipv4Address_AP1_4; +@synthesize ipv4Gateway_AP1_1; +@synthesize ipv4Gateway_AP1_2; +@synthesize ipv4Gateway_AP1_3; +@synthesize ipv4Gateway_AP1_4; +@synthesize ipv4PrimaryDNS_AP1_1; +@synthesize ipv4PrimaryDNS_AP1_2; +@synthesize ipv4PrimaryDNS_AP1_3; +@synthesize ipv4PrimaryDNS_AP1_4; +@synthesize ipv4SecondaryDNS_AP1_1; +@synthesize ipv4SecondaryDNS_AP1_2; +@synthesize ipv4SecondaryDNS_AP1_3; +@synthesize ipv4SecondaryDNS_AP1_4; +@dynamic subnetMask_AP1; +@synthesize subnetMaskString_AP1; + +@synthesize ipv4Address_AP2_1; +@synthesize ipv4Address_AP2_2; +@synthesize ipv4Address_AP2_3; +@synthesize ipv4Address_AP2_4; +@synthesize ipv4Gateway_AP2_1; +@synthesize ipv4Gateway_AP2_2; +@synthesize ipv4Gateway_AP2_3; +@synthesize ipv4Gateway_AP2_4; +@synthesize ipv4PrimaryDNS_AP2_1; +@synthesize ipv4PrimaryDNS_AP2_2; +@synthesize ipv4PrimaryDNS_AP2_3; +@synthesize ipv4PrimaryDNS_AP2_4; +@synthesize ipv4SecondaryDNS_AP2_1; +@synthesize ipv4SecondaryDNS_AP2_2; +@synthesize ipv4SecondaryDNS_AP2_3; +@synthesize ipv4SecondaryDNS_AP2_4; +@dynamic subnetMask_AP2; +@synthesize subnetMaskString_AP2; + +@synthesize ipv4Address_AP3_1; +@synthesize ipv4Address_AP3_2; +@synthesize ipv4Address_AP3_3; +@synthesize ipv4Address_AP3_4; +@synthesize ipv4Gateway_AP3_1; +@synthesize ipv4Gateway_AP3_2; +@synthesize ipv4Gateway_AP3_3; +@synthesize ipv4Gateway_AP3_4; +@synthesize ipv4PrimaryDNS_AP3_1; +@synthesize ipv4PrimaryDNS_AP3_2; +@synthesize ipv4PrimaryDNS_AP3_3; +@synthesize ipv4PrimaryDNS_AP3_4; +@synthesize ipv4SecondaryDNS_AP3_1; +@synthesize ipv4SecondaryDNS_AP3_2; +@synthesize ipv4SecondaryDNS_AP3_3; +@synthesize ipv4SecondaryDNS_AP3_4; +@dynamic subnetMask_AP3; +@synthesize subnetMaskString_AP3; + @dynamic consoleType; @dynamic nickname; @dynamic message; @dynamic favoriteColor; @dynamic birthday; @dynamic language; +@synthesize backlightLevel; - (id)init -{ - return [self initWithDictionary:nil]; -} - -- (id) initWithDictionary:(NSDictionary *)fwDataDict { self = [super init]; if (self == nil) @@ -45,54 +102,84 @@ return self; } - pthread_mutex_init(&mutex, NULL); - - // Allocate our own firmware struct since we weren't provided with one. internalData = (struct NDS_fw_config_data *)malloc(sizeof(struct NDS_fw_config_data)); if (internalData == nil) { - pthread_mutex_destroy(&mutex); [self release]; return nil; } NDS_FillDefaultFirmwareConfigData(internalData); - data = internalData; + _MACAddress[0] = 0x00; + _MACAddress[1] = 0x09; + _MACAddress[2] = 0xBF; + _MACAddress[3] = 0x12; + _MACAddress[4] = 0x34; + _MACAddress[5] = 0x56; - [self setDataWithDictionary:fwDataDict]; + _birth_year = 1970; + backlightLevel = 3; - return self; -} - -- (id) initWithFirmwareData:(struct NDS_fw_config_data *)fwData -{ - self = [super init]; - if (self == nil) - { - return self; - } + ipv4Address_AP1_1 = 0; + ipv4Address_AP1_2 = 0; + ipv4Address_AP1_3 = 0; + ipv4Address_AP1_4 = 0; + ipv4Gateway_AP1_1 = 0; + ipv4Gateway_AP1_2 = 0; + ipv4Gateway_AP1_3 = 0; + ipv4Gateway_AP1_4 = 0; + ipv4PrimaryDNS_AP1_1 = 0; + ipv4PrimaryDNS_AP1_2 = 0; + ipv4PrimaryDNS_AP1_3 = 0; + ipv4PrimaryDNS_AP1_4 = 0; + ipv4SecondaryDNS_AP1_1 = 0; + ipv4SecondaryDNS_AP1_2 = 0; + ipv4SecondaryDNS_AP1_3 = 0; + ipv4SecondaryDNS_AP1_4 = 0; + subnetMask_AP1 = 0; + subnetMaskString_AP1 = @"0.0.0.0"; + + ipv4Address_AP2_1 = 0; + ipv4Address_AP2_2 = 0; + ipv4Address_AP2_3 = 0; + ipv4Address_AP2_4 = 0; + ipv4Gateway_AP2_1 = 0; + ipv4Gateway_AP2_2 = 0; + ipv4Gateway_AP2_3 = 0; + ipv4Gateway_AP2_4 = 0; + ipv4PrimaryDNS_AP2_1 = 0; + ipv4PrimaryDNS_AP2_2 = 0; + ipv4PrimaryDNS_AP2_3 = 0; + ipv4PrimaryDNS_AP2_4 = 0; + ipv4SecondaryDNS_AP2_1 = 0; + ipv4SecondaryDNS_AP2_2 = 0; + ipv4SecondaryDNS_AP2_3 = 0; + ipv4SecondaryDNS_AP2_4 = 0; + subnetMask_AP2 = 0; + subnetMaskString_AP2 = @"0.0.0.0"; + + ipv4Address_AP3_1 = 0; + ipv4Address_AP3_2 = 0; + ipv4Address_AP3_3 = 0; + ipv4Address_AP3_4 = 0; + ipv4Gateway_AP3_1 = 0; + ipv4Gateway_AP3_2 = 0; + ipv4Gateway_AP3_3 = 0; + ipv4Gateway_AP3_4 = 0; + ipv4PrimaryDNS_AP3_1 = 0; + ipv4PrimaryDNS_AP3_2 = 0; + ipv4PrimaryDNS_AP3_3 = 0; + ipv4PrimaryDNS_AP3_4 = 0; + ipv4SecondaryDNS_AP3_1 = 0; + ipv4SecondaryDNS_AP3_2 = 0; + ipv4SecondaryDNS_AP3_3 = 0; + ipv4SecondaryDNS_AP3_4 = 0; + subnetMask_AP3 = 0; + subnetMaskString_AP3 = @"0.0.0.0"; pthread_mutex_init(&mutex, NULL); - if (fwData == nil) - { - pthread_mutex_destroy(&mutex); - [self release]; - return nil; - } - - // Set birth_year to the current year. - NSDate *now = [[NSDate alloc] init]; - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setDateFormat:@"Y"]; - birth_year = [[dateFormatter stringFromDate:now] integerValue]; - [dateFormatter release]; - [now release]; - - internalData = NULL; - data = fwData; - return self; } @@ -103,20 +190,165 @@ pthread_mutex_destroy(&mutex); + [self setSubnetMaskString_AP1:nil]; + [self setSubnetMaskString_AP2:nil]; + [self setSubnetMaskString_AP3:nil]; + [super dealloc]; } +- (void) setMACAddress:(const uint8_t *)inMACAddress +{ + if (inMACAddress == NULL) + { + return; + } + + pthread_mutex_lock(&mutex); + _MACAddress[0] = 0x00; + _MACAddress[1] = 0x09; + _MACAddress[2] = 0xBF; + _MACAddress[3] = inMACAddress[3]; + _MACAddress[4] = inMACAddress[4]; + _MACAddress[5] = inMACAddress[5]; + pthread_mutex_unlock(&mutex); + + [self setMACAddressString:NULL]; +} + +- (uint8_t *) MACAddress +{ + return _MACAddress; +} + +- (void) setMACAddressString:(NSString *)theMACAddressString +{ + // Do nothing. This is here for KVO-compliance only. +} + +- (NSString *) MACAddressString +{ + pthread_mutex_lock(&mutex); + NSString *theMACAddressString = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", + _MACAddress[0], _MACAddress[1], _MACAddress[2], _MACAddress[3], _MACAddress[4], _MACAddress[5]]; + pthread_mutex_unlock(&mutex); + + return theMACAddressString; +} + +- (void) setSubnetMask_AP1:(NSInteger)subnetMask +{ + if (subnetMask > 28) + { + subnetMask = 28; + } + else if (subnetMask < 0) + { + subnetMask = 0; + } + + pthread_mutex_lock(&mutex); + subnetMask_AP1 = subnetMask; + const uint32_t subnetMaskValue = (subnetMask_AP1 == 0) ? 0 : (0xFFFFFFFF << (32 - subnetMask_AP1)); + pthread_mutex_unlock(&mutex); + + NSString *subnetMaskString = [NSString stringWithFormat:@"%d.%d.%d.%d", + (subnetMaskValue >> 24) & 0x000000FF, + (subnetMaskValue >> 16) & 0x000000FF, + (subnetMaskValue >> 8) & 0x000000FF, + (subnetMaskValue >> 0) & 0x000000FF]; + + [self setSubnetMaskString_AP1:subnetMaskString]; +} + +- (NSInteger) subnetMask_AP1 +{ + pthread_mutex_lock(&mutex); + const NSInteger subnetMask = subnetMask_AP1; + pthread_mutex_unlock(&mutex); + + return subnetMask; +} + +- (void) setSubnetMask_AP2:(NSInteger)subnetMask +{ + if (subnetMask > 28) + { + subnetMask = 28; + } + else if (subnetMask < 0) + { + subnetMask = 0; + } + + pthread_mutex_lock(&mutex); + subnetMask_AP2 = subnetMask; + const uint32_t subnetMaskValue = (subnetMask_AP2 == 0) ? 0 : (0xFFFFFFFF << (32 - subnetMask_AP2)); + pthread_mutex_unlock(&mutex); + + NSString *subnetMaskString = [NSString stringWithFormat:@"%d.%d.%d.%d", + (subnetMaskValue >> 24) & 0x000000FF, + (subnetMaskValue >> 16) & 0x000000FF, + (subnetMaskValue >> 8) & 0x000000FF, + (subnetMaskValue >> 0) & 0x000000FF]; + + [self setSubnetMaskString_AP2:subnetMaskString]; +} + +- (NSInteger) subnetMask_AP2 +{ + pthread_mutex_lock(&mutex); + const NSInteger subnetMask = subnetMask_AP2; + pthread_mutex_unlock(&mutex); + + return subnetMask; +} + +- (void) setSubnetMask_AP3:(NSInteger)subnetMask +{ + if (subnetMask > 28) + { + subnetMask = 28; + } + else if (subnetMask < 0) + { + subnetMask = 0; + } + + pthread_mutex_lock(&mutex); + subnetMask_AP3 = subnetMask; + const uint32_t subnetMaskValue = (subnetMask_AP3 == 0) ? 0 : (0xFFFFFFFF << (32 - subnetMask_AP3)); + pthread_mutex_unlock(&mutex); + + NSString *subnetMaskString = [NSString stringWithFormat:@"%d.%d.%d.%d", + (subnetMaskValue >> 24) & 0x000000FF, + (subnetMaskValue >> 16) & 0x000000FF, + (subnetMaskValue >> 8) & 0x000000FF, + (subnetMaskValue >> 0) & 0x000000FF]; + + [self setSubnetMaskString_AP3:subnetMaskString]; +} + +- (NSInteger) subnetMask_AP3 +{ + pthread_mutex_lock(&mutex); + const NSInteger subnetMask = subnetMask_AP3; + pthread_mutex_unlock(&mutex); + + return subnetMask; +} + - (void) setConsoleType:(NSInteger)theType { pthread_mutex_lock(&mutex); - data->ds_type = (NDS_CONSOLE_TYPE)theType; + internalData->ds_type = (NDS_CONSOLE_TYPE)theType; pthread_mutex_unlock(&mutex); } - (NSInteger) consoleType { pthread_mutex_lock(&mutex); - NSInteger theType = data->ds_type; + NSInteger theType = internalData->ds_type; pthread_mutex_unlock(&mutex); return theType; @@ -135,7 +367,7 @@ characterRange.length = MAX_FW_NICKNAME_LENGTH; } - [theNickname getBytes:&data->nickname[0] + [theNickname getBytes:&internalData->nickname[0] maxLength:(sizeof(UInt16) * characterRange.length) usedLength:NULL encoding:NSUTF16LittleEndianStringEncoding @@ -143,12 +375,12 @@ range:characterRange remainingRange:NULL]; - data->nickname_len = (u8)characterRange.length; + internalData->nickname_len = (u8)characterRange.length; } else { - memset(&data->nickname[0], 0, sizeof(data->nickname)); - data->nickname_len = 0; + memset(&internalData->nickname[0], 0, sizeof(internalData->nickname)); + internalData->nickname_len = 0; } pthread_mutex_unlock(&mutex); @@ -157,7 +389,7 @@ - (NSString *) nickname { pthread_mutex_lock(&mutex); - NSString *theNickname = [[[NSString alloc] initWithBytes:&data->nickname[0] length:(sizeof(UInt16) * data->nickname_len) encoding:NSUTF16LittleEndianStringEncoding] autorelease]; + NSString *theNickname = [[[NSString alloc] initWithBytes:&internalData->nickname[0] length:(sizeof(UInt16) * internalData->nickname_len) encoding:NSUTF16LittleEndianStringEncoding] autorelease]; pthread_mutex_unlock(&mutex); return theNickname; @@ -176,7 +408,7 @@ characterRange.length = MAX_FW_MESSAGE_LENGTH; } - [theMessage getBytes:&data->message[0] + [theMessage getBytes:&internalData->message[0] maxLength:(sizeof(UInt16) * characterRange.length) usedLength:NULL encoding:NSUTF16LittleEndianStringEncoding @@ -184,12 +416,12 @@ range:characterRange remainingRange:NULL]; - data->message_len = (u8)characterRange.length; + internalData->message_len = (u8)characterRange.length; } else { - memset(&data->message[0], 0, sizeof(data->message)); - data->message_len = 0; + memset(&internalData->message[0], 0, sizeof(internalData->message)); + internalData->message_len = 0; } pthread_mutex_unlock(&mutex); @@ -198,7 +430,7 @@ - (NSString *) message { pthread_mutex_lock(&mutex); - NSString *theMessage = [[[NSString alloc] initWithBytes:&data->message[0] length:(sizeof(UInt16) * data->message_len) encoding:NSUTF16LittleEndianStringEncoding] autorelease]; + NSString *theMessage = [[[NSString alloc] initWithBytes:&internalData->message[0] length:(sizeof(UInt16) * internalData->message_len) encoding:NSUTF16LittleEndianStringEncoding] autorelease]; pthread_mutex_unlock(&mutex); return theMessage; @@ -207,14 +439,14 @@ - (void) setFavoriteColor:(NSInteger)colorID { pthread_mutex_lock(&mutex); - data->fav_colour = (u8)colorID; + internalData->fav_colour = (u8)colorID; pthread_mutex_unlock(&mutex); } - (NSInteger) favoriteColor { pthread_mutex_lock(&mutex); - NSInteger theFavoriteColorID = data->fav_colour; + NSInteger theFavoriteColorID = internalData->fav_colour; pthread_mutex_unlock(&mutex); return theFavoriteColorID; @@ -239,15 +471,15 @@ [dateFormatter release]; - data->birth_month = (u8)theMonth; - data->birth_day = (u8)theDay; - birth_year = theYear; + internalData->birth_month = (u8)theMonth; + internalData->birth_day = (u8)theDay; + _birth_year = theYear; } else { - data->birth_month = 1; - data->birth_day = 1; - birth_year = 1970; + internalData->birth_month = 1; + internalData->birth_day = 1; + _birth_year = 1970; } pthread_mutex_unlock(&mutex); @@ -256,7 +488,7 @@ - (NSDate *) birthday { pthread_mutex_lock(&mutex); - NSDate *theBirthday = [NSDate dateWithString:[NSString stringWithFormat:@"%ld-%ld-%ld 12:00:00 +0000", (unsigned long)birth_year, (unsigned long)data->birth_month, (unsigned long)data->birth_day]]; + NSDate *theBirthday = [NSDate dateWithString:[NSString stringWithFormat:@"%ld-%ld-%ld 12:00:00 +0000", (unsigned long)_birth_year, (unsigned long)internalData->birth_month, (unsigned long)internalData->birth_day]]; pthread_mutex_unlock(&mutex); return theBirthday; @@ -265,55 +497,145 @@ - (void) setLanguage:(NSInteger)languageID { pthread_mutex_lock(&mutex); - data->language = (u8)languageID; + internalData->language = (u8)languageID; pthread_mutex_unlock(&mutex); } - (NSInteger) language { pthread_mutex_lock(&mutex); - NSInteger theLanguageID = data->language; + NSInteger theLanguageID = internalData->language; pthread_mutex_unlock(&mutex); return theLanguageID; } +// TODO: Remove this function after firmware.cpp is reworked. +// This is just a direct copy-paste of the function from there. +static u32 calc_CRC16( u32 start, const u8 *data, int count) +{ + int i,j; + u32 crc = start & 0xffff; + const u16 val[8] = { 0xC0C1,0xC181,0xC301,0xC601,0xCC01,0xD801,0xF001,0xA001 }; + for(i = 0; i < count; i++) + { + crc = crc ^ data[i]; + + for(j = 0; j < 8; j++) { + int do_bit = 0; + + if ( crc & 0x1) + do_bit = 1; + + crc = crc >> 1; + + if ( do_bit) { + crc = crc ^ (val[j] << (7-j)); + } + } + } + return crc; +} + - (void) update { // Write the attributes to the DS via the data struct. // We have make a copy of the struct and send that so that the firmware // changes get saved in CommonSettings.InternalFirmwareConf. pthread_mutex_lock(&mutex); - struct NDS_fw_config_data newFirmwareData = *data; + + struct NDS_fw_config_data newFirmwareData = *internalData; NDS_CreateDummyFirmware(&newFirmwareData); + + // WiFi Info + MMU.fw.data[0x36] = _MACAddress[0]; + MMU.fw.data[0x37] = _MACAddress[1]; + MMU.fw.data[0x38] = _MACAddress[2]; + MMU.fw.data[0x39] = _MACAddress[3]; + MMU.fw.data[0x3A] = _MACAddress[4]; + MMU.fw.data[0x3B] = _MACAddress[5]; + *(u16 *)&MMU.fw.data[0x2A] = calc_CRC16(0, &MMU.fw.data[0x2C], 0x138); + + // Access Point Settings + MMU.fw.data[0x3FA40] = 'S'; + MMU.fw.data[0x3FA41] = 'o'; + MMU.fw.data[0x3FA42] = 'f'; + MMU.fw.data[0x3FA43] = 't'; + MMU.fw.data[0x3FA44] = 'A'; + MMU.fw.data[0x3FA45] = 'P'; + MMU.fw.data[0x3FAC0] = ipv4Address_AP1_1; + MMU.fw.data[0x3FAC1] = ipv4Address_AP1_2; + MMU.fw.data[0x3FAC2] = ipv4Address_AP1_3; + MMU.fw.data[0x3FAC3] = ipv4Address_AP1_4; + MMU.fw.data[0x3FAC4] = ipv4Gateway_AP1_1; + MMU.fw.data[0x3FAC5] = ipv4Gateway_AP1_2; + MMU.fw.data[0x3FAC6] = ipv4Gateway_AP1_3; + MMU.fw.data[0x3FAC7] = ipv4Gateway_AP1_4; + MMU.fw.data[0x3FAC8] = ipv4PrimaryDNS_AP1_1; + MMU.fw.data[0x3FAC9] = ipv4PrimaryDNS_AP1_2; + MMU.fw.data[0x3FACA] = ipv4PrimaryDNS_AP1_3; + MMU.fw.data[0x3FACB] = ipv4PrimaryDNS_AP1_4; + MMU.fw.data[0x3FACC] = ipv4SecondaryDNS_AP1_1; + MMU.fw.data[0x3FACD] = ipv4SecondaryDNS_AP1_2; + MMU.fw.data[0x3FACE] = ipv4SecondaryDNS_AP1_3; + MMU.fw.data[0x3FACF] = ipv4SecondaryDNS_AP1_4; + MMU.fw.data[0x3FAD0] = subnetMask_AP1; + MMU.fw.data[0x3FAE7] = 0; + *(u16 *)&MMU.fw.data[0x3FAFE] = calc_CRC16(0, &MMU.fw.data[0x3FA00], 0xFE); + + MMU.fw.data[0x3FB40] = 'S'; + MMU.fw.data[0x3FB41] = 'o'; + MMU.fw.data[0x3FB42] = 'f'; + MMU.fw.data[0x3FB43] = 't'; + MMU.fw.data[0x3FB44] = 'A'; + MMU.fw.data[0x3FB45] = 'P'; + MMU.fw.data[0x3FBC0] = ipv4Address_AP2_1; + MMU.fw.data[0x3FBC1] = ipv4Address_AP2_2; + MMU.fw.data[0x3FBC2] = ipv4Address_AP2_3; + MMU.fw.data[0x3FBC3] = ipv4Address_AP2_4; + MMU.fw.data[0x3FBC4] = ipv4Gateway_AP2_1; + MMU.fw.data[0x3FBC5] = ipv4Gateway_AP2_2; + MMU.fw.data[0x3FBC6] = ipv4Gateway_AP2_3; + MMU.fw.data[0x3FBC7] = ipv4Gateway_AP2_4; + MMU.fw.data[0x3FBC8] = ipv4PrimaryDNS_AP2_1; + MMU.fw.data[0x3FBC9] = ipv4PrimaryDNS_AP2_2; + MMU.fw.data[0x3FBCA] = ipv4PrimaryDNS_AP2_3; + MMU.fw.data[0x3FBCB] = ipv4PrimaryDNS_AP2_4; + MMU.fw.data[0x3FBCC] = ipv4SecondaryDNS_AP2_1; + MMU.fw.data[0x3FBCD] = ipv4SecondaryDNS_AP2_2; + MMU.fw.data[0x3FBCE] = ipv4SecondaryDNS_AP2_3; + MMU.fw.data[0x3FBCF] = ipv4SecondaryDNS_AP2_4; + MMU.fw.data[0x3FBD0] = subnetMask_AP2; + MMU.fw.data[0x3FBE7] = 0; + *(u16 *)&MMU.fw.data[0x3FBFE] = calc_CRC16(0, &MMU.fw.data[0x3FB00], 0xFE); + + MMU.fw.data[0x3FC40] = 'S'; + MMU.fw.data[0x3FC41] = 'o'; + MMU.fw.data[0x3FC42] = 'f'; + MMU.fw.data[0x3FC43] = 't'; + MMU.fw.data[0x3FC44] = 'A'; + MMU.fw.data[0x3FC45] = 'P'; + MMU.fw.data[0x3FCC0] = ipv4Address_AP3_1; + MMU.fw.data[0x3FCC1] = ipv4Address_AP3_2; + MMU.fw.data[0x3FCC2] = ipv4Address_AP3_3; + MMU.fw.data[0x3FCC3] = ipv4Address_AP3_4; + MMU.fw.data[0x3FCC4] = ipv4Gateway_AP3_1; + MMU.fw.data[0x3FCC5] = ipv4Gateway_AP3_2; + MMU.fw.data[0x3FCC6] = ipv4Gateway_AP3_3; + MMU.fw.data[0x3FCC7] = ipv4Gateway_AP3_4; + MMU.fw.data[0x3FCC8] = ipv4PrimaryDNS_AP3_1; + MMU.fw.data[0x3FCC9] = ipv4PrimaryDNS_AP3_2; + MMU.fw.data[0x3FCCA] = ipv4PrimaryDNS_AP3_3; + MMU.fw.data[0x3FCCB] = ipv4PrimaryDNS_AP3_4; + MMU.fw.data[0x3FCCC] = ipv4SecondaryDNS_AP3_1; + MMU.fw.data[0x3FCCD] = ipv4SecondaryDNS_AP3_2; + MMU.fw.data[0x3FCCE] = ipv4SecondaryDNS_AP3_3; + MMU.fw.data[0x3FCCF] = ipv4SecondaryDNS_AP3_4; + MMU.fw.data[0x3FCD0] = subnetMask_AP3; + MMU.fw.data[0x3FCE7] = 0; + *(u16 *)&MMU.fw.data[0x3FCFE] = calc_CRC16(0, &MMU.fw.data[0x3FC00], 0xFE); + pthread_mutex_unlock(&mutex); } -- (void) setDataWithDictionary:(NSDictionary *)dataDict -{ - if (dataDict == nil) - { - return; - } - - [self setConsoleType:[(NSNumber *)[dataDict valueForKey:@"ConsoleType"] integerValue]]; - [self setNickname:(NSString *)[dataDict valueForKey:@"Nickname"]]; - [self setMessage:(NSString *)[dataDict valueForKey:@"Message"]]; - [self setFavoriteColor:[(NSNumber *)[dataDict valueForKey:@"FavoriteColor"] integerValue]]; - [self setBirthday:(NSDate *)[dataDict valueForKey:@"Birthday"]]; - [self setLanguage:[(NSNumber *)[dataDict valueForKey:@"Language"] integerValue]]; -} - -- (NSDictionary *) dataDictionary -{ - return [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithInteger:[self consoleType]], @"ConsoleType", - [self nickname], @"Nickname", - [self message], @"Message", - [NSNumber numberWithInteger:[self favoriteColor]], @"FavoriteColor", - [self birthday], @"Birthday", - [NSNumber numberWithInteger:[self language]], @"Language", - nil]; -} - @end diff --git a/desmume/src/frontend/cocoa/userinterface/WifiSettingsPanel.mm b/desmume/src/frontend/cocoa/userinterface/WifiSettingsPanel.mm index c799d6a0b..1b47c1b7d 100644 --- a/desmume/src/frontend/cocoa/userinterface/WifiSettingsPanel.mm +++ b/desmume/src/frontend/cocoa/userinterface/WifiSettingsPanel.mm @@ -93,7 +93,9 @@ { if (theSelection == 0) { - wifiHandler->SetFirmwareMACMode(FirmwareMACMode_ReadFromFirmware); + //wifiHandler->SetFirmwareMACMode(FirmwareMACMode_ReadFromFirmware); + wifiHandler->SetMACModeForComm(WifiCommInterfaceID_AdHoc, WifiMACMode_ReadFromFirmware); + wifiHandler->SetMACModeForComm(WifiCommInterfaceID_Infrastructure, WifiMACMode_ReadFromFirmware); } else if ( (theSelection >= 1) && (theSelection <= 4) ) { @@ -102,7 +104,9 @@ const uint8_t myMAC6 = (_myMACAddressValue >> 16) & 0x000000F0; wifiHandler->SetUserMACValues(myMAC4, myMAC5, myMAC6 + theSelection); - wifiHandler->SetFirmwareMACMode(FirmwareMACMode_Manual); + //wifiHandler->SetFirmwareMACMode(FirmwareMACMode_Manual); + wifiHandler->SetMACModeForComm(WifiCommInterfaceID_AdHoc, WifiMACMode_Manual); + wifiHandler->SetMACModeForComm(WifiCommInterfaceID_Infrastructure, WifiMACMode_Manual); } addressSelection = theSelection; diff --git a/desmume/src/frontend/cocoa/userinterface/appDelegate.h b/desmume/src/frontend/cocoa/userinterface/appDelegate.h index 9c9609ee6..bd7a57251 100644 --- a/desmume/src/frontend/cocoa/userinterface/appDelegate.h +++ b/desmume/src/frontend/cocoa/userinterface/appDelegate.h @@ -21,6 +21,7 @@ @class InputPrefsView; @class FileMigrationDelegate; @class MacAVCaptureToolDelegate; +@class WifiSettingsPanelDelegate; #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 @@ -37,6 +38,7 @@ NSObjectController *cdsCoreController; FileMigrationDelegate *migrationDelegate; MacAVCaptureToolDelegate *avCaptureToolDelegate; + WifiSettingsPanelDelegate *wifiSettingsPanelDelegate; NSWindow *prefWindow; NSWindow *troubleshootingWindow; @@ -57,6 +59,7 @@ @property (readonly) IBOutlet NSObjectController *cdsCoreController; @property (readonly) IBOutlet FileMigrationDelegate *migrationDelegate; @property (readonly) IBOutlet MacAVCaptureToolDelegate *avCaptureToolDelegate; +@property (readonly) IBOutlet WifiSettingsPanelDelegate *wifiSettingsPanelDelegate; @property (readonly) IBOutlet NSWindow *prefWindow; @property (readonly) IBOutlet NSWindow *troubleshootingWindow; @property (readonly) IBOutlet NSMenu *mLoadStateSlot; diff --git a/desmume/src/frontend/cocoa/userinterface/appDelegate.mm b/desmume/src/frontend/cocoa/userinterface/appDelegate.mm index 06e30596e..d67bd1910 100644 --- a/desmume/src/frontend/cocoa/userinterface/appDelegate.mm +++ b/desmume/src/frontend/cocoa/userinterface/appDelegate.mm @@ -21,6 +21,7 @@ #import "EmuControllerDelegate.h" #import "FileMigrationDelegate.h" #import "MacAVCaptureTool.h" +#import "WifiSettingsPanel.h" #import "preferencesWindowDelegate.h" #import "troubleshootingWindowDelegate.h" #import "cheatWindowDelegate.h" @@ -50,6 +51,7 @@ @synthesize prefWindowController; @synthesize cdsCoreController; @synthesize avCaptureToolDelegate; +@synthesize wifiSettingsPanelDelegate; @synthesize migrationDelegate; @synthesize isAppRunningOnIntel; @@ -136,6 +138,8 @@ return; } + srandom(time(NULL)); + [CocoaDSFile setupAllFilePaths]; // On macOS v10.13 and later, some unwanted menu items will show up in the View menu. @@ -188,6 +192,9 @@ [avCaptureToolDelegate setCdsCore:newCore]; [avCaptureToolDelegate setExecControl:[newCore execControl]]; + [wifiSettingsPanelDelegate setExecControl:[newCore execControl]]; + [wifiSettingsPanelDelegate fillLibpcapDeviceMenu]; + // Init the DS speakers. CocoaDSSpeaker *newSpeaker = [[[CocoaDSSpeaker alloc] init] autorelease]; [newCore addOutput:newSpeaker]; @@ -198,6 +205,7 @@ [prefWindowController setContent:[prefWindowDelegate bindings]]; [emuControl appInit]; + [prefWindowDelegate markUnsupportedOpenGLMSAAMenuItems]; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification @@ -459,15 +467,13 @@ [cdsCore setIsCheatingEnabled:[[NSUserDefaults standardUserDefaults] boolForKey:@"CoreControl_EnableCheats"]]; // Set up the firmware per user preferences. - NSMutableDictionary *newFWDict = [NSMutableDictionary dictionaryWithObjectsAndKeys: - [[NSUserDefaults standardUserDefaults] objectForKey:@"FirmwareConfig_Nickname"], @"Nickname", - [[NSUserDefaults standardUserDefaults] objectForKey:@"FirmwareConfig_Message"], @"Message", - [[NSUserDefaults standardUserDefaults] objectForKey:@"FirmwareConfig_FavoriteColor"], @"FavoriteColor", - [[NSUserDefaults standardUserDefaults] objectForKey:@"FirmwareConfig_Birthday"], @"Birthday", - [[NSUserDefaults standardUserDefaults] objectForKey:@"FirmwareConfig_Language"], @"Language", - nil]; + CocoaDSFirmware *newFirmware = [[[CocoaDSFirmware alloc] init] autorelease]; + [newFirmware setNickname:[[NSUserDefaults standardUserDefaults] objectForKey:@"FirmwareConfig_Nickname"]]; + [newFirmware setMessage:[[NSUserDefaults standardUserDefaults] objectForKey:@"FirmwareConfig_Message"]]; + [newFirmware setFavoriteColor:[[NSUserDefaults standardUserDefaults] integerForKey:@"FirmwareConfig_FavoriteColor"]]; + [newFirmware setBirthday:[[NSUserDefaults standardUserDefaults] objectForKey:@"FirmwareConfig_Birthday"]]; + [newFirmware setLanguage:[[NSUserDefaults standardUserDefaults] integerForKey:@"FirmwareConfig_Language"]]; - CocoaDSFirmware *newFirmware = [[[CocoaDSFirmware alloc] initWithDictionary:newFWDict] autorelease]; [newFirmware update]; [emuControl setCdsFirmware:newFirmware]; @@ -517,6 +523,7 @@ // Set up the rest of the emulation-related user defaults. [emuControl readUserDefaults]; + [wifiSettingsPanelDelegate readUserDefaults]; // Set up the preferences window. [prefWindowDelegate setupUserDefaults];