Skip to content

Commit

Permalink
Update Swift version
Browse files Browse the repository at this point in the history
  • Loading branch information
robb committed Feb 18, 2018
1 parent a00836c commit 777907d
Show file tree
Hide file tree
Showing 25 changed files with 149 additions and 114 deletions.
4 changes: 2 additions & 2 deletions Emulator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import SpriteKit
@IBOutlet weak var view: SKView!
@IBOutlet weak var window: NSWindow!

func applicationDidFinishLaunching(aNotification: NSNotification) {
@objc func applicationDidFinishLaunching(_ notification: Notification) {
window.contentAspectRatio = NESScene.screenSize
window.contentMinSize = NESScene.screenSize
window.setContentSize(NESScene.screenSize)

window.center()
}

func application(sender: NSApplication, openFile filename: String) -> Bool {
@objc func application(_ sender: NSApplication, openFile filename: String) -> Bool {
let scene = NESScene(file: filename)

view!.presentScene(scene)
Expand Down
4 changes: 3 additions & 1 deletion Emulator/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
<array>
<string>nes</string>
</array>
<key>CFBundleTypeName</key>
<string>NES Game</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<string>Viewer</string>
</dict>
</array>
<key>CFBundleExecutable</key>
Expand Down
10 changes: 5 additions & 5 deletions Emulator/NESScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class NESScene: SKScene {
static let screenSize = CGSize(width: 256, height: 240)

init(file: String) {
let cartridge = Cartridge.load(file)!
let cartridge = Cartridge.load(path: file)!

console = Console(cartridge: cartridge)

Expand All @@ -23,7 +23,7 @@ class NESScene: SKScene {

super.init(size: NESScene.screenSize)

scaleMode = .AspectFit
scaleMode = .aspectFit

addChild(node)
}
Expand All @@ -32,14 +32,14 @@ class NESScene: SKScene {
fatalError("init(coder:) has not been implemented")
}

override func update(currentTime: CFTimeInterval) {
override func update(_ currentTime: CFTimeInterval) {
let delta = currentTime - (lastTime ?? currentTime)

console.step(time: delta)

if console.frames > lastFrame {
let texture = SKTexture(data: console.screenData, size: NESScene.screenSize, flipped: true)
texture.filteringMode = .Nearest
let texture = SKTexture(data: console.screenData as Data, size: NESScene.screenSize, flipped: true)
texture.filteringMode = .nearest

node.texture = texture

Expand Down
2 changes: 1 addition & 1 deletion NES Tests/DummyMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
internal class DummyMapper: IO {
private var memory: Array<UInt8> = Array(count: 0x10000, repeatedValue: 0xFF)

func read(address: Address) -> UInt8 {
func read(_ address: Address) -> UInt8 {
return memory[address]
}

Expand Down
31 changes: 28 additions & 3 deletions NES.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Robert Böhnke";
TargetAttributes = {
548605E71ACFFF1B00198A72 = {
CreatedOnToolsVersion = 6.3;
LastSwiftMigration = 0900;
};
548605F21ACFFF1C00198A72 = {
CreatedOnToolsVersion = 6.3;
LastSwiftMigration = 0900;
};
54E65A9B1CF35F0000317EEC = {
CreatedOnToolsVersion = 7.3;
Expand Down Expand Up @@ -524,13 +526,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -558,6 +568,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -571,13 +582,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
Expand All @@ -596,6 +615,8 @@
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -621,6 +642,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -644,6 +666,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -666,6 +689,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -683,18 +707,19 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.robertboehnke.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
54E65AAB1CF35F0000317EEC /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = Emulator/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
Expand All @@ -706,11 +731,11 @@
54E65AAC1CF35F0000317EEC /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = Emulator/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -45,6 +46,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -35,6 +35,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -52,8 +53,9 @@
</TestAction>
<LaunchAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
4 changes: 3 additions & 1 deletion NES.xcodeproj/xcshareddata/xcschemes/NES.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -69,6 +70,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion NES/Address.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ internal extension Address {
}
}

internal func differentPages(a: Address, _ b: Address) -> Bool {
internal func differentPages(_ a: Address, _ b: Address) -> Bool {
return a.page != b.page
}
6 changes: 3 additions & 3 deletions NES/CPU+AddressingModes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal extension CPU {
}

func absoluteX(incursPageBoundaryCost: Bool) -> UInt8 {
return read(absoluteX(incursPageBoundaryCost))
return read(absoluteX(incursPageBoundaryCost: incursPageBoundaryCost))
}

func absoluteY(incursPageBoundaryCost: Bool) -> Address {
Expand All @@ -34,7 +34,7 @@ internal extension CPU {
}

func absoluteY(incursPageBoundaryCost: Bool) -> UInt8 {
return read(absoluteY(incursPageBoundaryCost))
return read(absoluteY(incursPageBoundaryCost: incursPageBoundaryCost))
}

func accumulator() -> Void {
Expand Down Expand Up @@ -72,7 +72,7 @@ internal extension CPU {
}

func indirectIndexed(incursPageBoundaryCost: Bool) -> UInt8 {
return read(indirectIndexed(incursPageBoundaryCost))
return read(indirectIndexed(incursPageBoundaryCost: incursPageBoundaryCost))
}

func relative() -> UInt8 {
Expand Down
4 changes: 2 additions & 2 deletions NES/CPU+Flags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ internal extension CPU {

/// A convenience method for setting the A register as well as the Zero and
/// Negative flags.
func updateAZN(value: UInt8) {
func updateAZN(_ value: UInt8) {
A = value
Z = value == 0
N = value & 0x80 != 0
}

/// A convenience method for setting the Zero and Negative flags.
func updateZN(value: UInt8) {
func updateZN(_ value: UInt8) {
Z = value == 0
N = value & 0x80 != 0
}
Expand Down
12 changes: 6 additions & 6 deletions NES/CPU+IO.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

extension CPU: IO {
func read(address: Address) -> UInt8 {
func read(_ address: Address) -> UInt8 {
switch address {
case 0x0000 ..< 0x2000:
return RAM[address % 0x0800]
Expand All @@ -16,7 +16,7 @@ extension CPU: IO {
}
}

func write(address: Address, _ value: UInt8) {
func write(_ address: Address, _ value: UInt8) {
switch Int(address) {
case 0x0000 ..< 0x2000:
RAM[address % 0x0800] = value
Expand Down Expand Up @@ -62,12 +62,12 @@ internal extension CPU {
internal extension CPU {
static let StackOffset: Address = 0x0100

func push(byte: UInt8) {
func push(_ byte: UInt8) {
write(CPU.StackOffset | UInt16(SP), byte)
SP = SP &- 1
}

func push16(value: UInt16) {
func push16(_ value: UInt16) {
push(UInt8(value >> 8))
push(UInt8(value & 0xFF))
}
Expand Down Expand Up @@ -116,7 +116,7 @@ internal extension Address {

/// Maps CPU memory addresses to PPU registers.
private extension PPU {
func readRegister(address: Address) -> UInt8 {
func readRegister(_ address: Address) -> UInt8 {
switch address {
case Address.PPUSTATUSAddress:
defer { didReadPPUSTATUS() }
Expand All @@ -133,7 +133,7 @@ private extension PPU {
}
}

func writeRegister(address: Address, value: UInt8) {
func writeRegister(_ address: Address, value: UInt8) {
register = value

switch address {
Expand Down
Loading

0 comments on commit 777907d

Please sign in to comment.