Skip to content

Commit

Permalink
Require argument labels for Address
Browse files Browse the repository at this point in the history
  • Loading branch information
robb committed Feb 18, 2018
1 parent 471da42 commit 6ef00c0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
4 changes: 4 additions & 0 deletions NES.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
546054A31AD018CE00CFD098 /* CPU+Instructions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 546054A21AD018CE00CFD098 /* CPU+Instructions.swift */; };
546054A51AD01A5700CFD098 /* InstructionsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 546054A41AD01A5700CFD098 /* InstructionsSpec.swift */; };
5460A68D203909EF001A48F0 /* Array+Indexing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5460A68C203909EE001A48F0 /* Array+Indexing.swift */; };
5460A68F20390C02001A48F0 /* UInt16+Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5460A68E20390C02001A48F0 /* UInt16+Convenience.swift */; };
546E4ECD1CCBEA4700DD2704 /* Console.swift in Sources */ = {isa = PBXBuildFile; fileRef = 546E4ECC1CCBEA4700DD2704 /* Console.swift */; };
546E4ECF1CCBEDBA00DD2704 /* PPU.swift in Sources */ = {isa = PBXBuildFile; fileRef = 546E4ECE1CCBEDBA00DD2704 /* PPU.swift */; };
547612901ADAF8D100AEBE14 /* CPU+Step.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5476128F1ADAF8D100AEBE14 /* CPU+Step.swift */; };
Expand Down Expand Up @@ -110,6 +111,7 @@
546054A21AD018CE00CFD098 /* CPU+Instructions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CPU+Instructions.swift"; sourceTree = "<group>"; };
546054A41AD01A5700CFD098 /* InstructionsSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InstructionsSpec.swift; sourceTree = "<group>"; };
5460A68C203909EE001A48F0 /* Array+Indexing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Indexing.swift"; sourceTree = "<group>"; };
5460A68E20390C02001A48F0 /* UInt16+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt16+Convenience.swift"; sourceTree = "<group>"; };
546E4ECC1CCBEA4700DD2704 /* Console.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Console.swift; sourceTree = "<group>"; };
546E4ECE1CCBEDBA00DD2704 /* PPU.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PPU.swift; sourceTree = "<group>"; };
5476128F1ADAF8D100AEBE14 /* CPU+Step.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CPU+Step.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -223,6 +225,7 @@
54D8BDF01CEDD50800F8C3BC /* PPU+Step.swift */,
54E65A961CF35B3E00317EEC /* ScreenBuffer.swift */,
542436641CD804BA0084DDDF /* UInt8+Bitset.swift */,
5460A68E20390C02001A48F0 /* UInt16+Convenience.swift */,
548605EB1ACFFF1B00198A72 /* Supporting Files */,
);
path = NES;
Expand Down Expand Up @@ -454,6 +457,7 @@
54C21E131CC8213500B96C00 /* IO.swift in Sources */,
542BC4341CD44987000E211F /* PPU+IO.swift in Sources */,
54B1BAFF1CF49679004A1A70 /* Data+Indexing.swift in Sources */,
5460A68F20390C02001A48F0 /* UInt16+Convenience.swift in Sources */,
542436651CD804BA0084DDDF /* UInt8+Bitset.swift in Sources */,
540E001C1CD577C500C9669B /* PPU+Flags.swift in Sources */,
54C21E151CC822CD00B96C00 /* CPU+IO.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion NES/Address.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
internal typealias Address = UInt16

internal extension Address {
init(_ page: UInt8, _ offset: UInt8) {
init(page: UInt8, offset: UInt8) {
self = UInt16(page) << 8 | UInt16(offset)
}

Expand Down
10 changes: 5 additions & 5 deletions NES/CPU+AddressingModes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal extension CPU {
}

func indirectIndexed(incursPageBoundaryCost: Bool) -> Address {
let address = buggyRead16(Address(0x00, advanceProgramCounter())) &+ Address(Y)
let address = buggyRead16(Address(page: 0x00, offset: advanceProgramCounter())) &+ Address(Y)

if incursPageBoundaryCost && differentPages(address, address &- Address(Y)) {
cycles += 1
Expand All @@ -80,25 +80,25 @@ internal extension CPU {
}

func zeroPage() -> UInt8 {
let address = Address(0, advanceProgramCounter())
let address = Address(page: 0, offset: advanceProgramCounter())

return read(address)
}

func zeroPage() -> Address {
return Address(0, advanceProgramCounter())
return Address(page: 0, offset: advanceProgramCounter())
}

func zeroPageX() -> Address {
return Address(advanceProgramCounter() &+ X)
return Address(page: 0, offset: advanceProgramCounter() &+ X)
}

func zeroPageX() -> UInt8 {
return read(zeroPageX())
}

func zeroPageY() -> Address {
return Address(advanceProgramCounter() &+ Y)
return Address(page: 0, offset: advanceProgramCounter() &+ Y)
}

func zeroPageY() -> UInt8 {
Expand Down
4 changes: 2 additions & 2 deletions NES/IO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ extension IO {
let low = read(address)
let high = read(address + 1)

return UInt16(high, low)
return UInt16(high: high, low: low)
}

func buggyRead16(_ address: Address) -> UInt16 {
let low = read(address)
let high = read((address & 0xFF00) | UInt16(UInt8(address & 0xFF) &+ 1))

return UInt16(high, low)
return UInt16(high: high, low: low)
}

func write16(_ address: Address, _ value: UInt16) {
Expand Down
4 changes: 2 additions & 2 deletions NES/PPU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ internal extension PPU {

/// Must be called after the CPU has written OAMDMA.
func didWriteOAMDMA() {
for offset in 0x0000 ..< 0x0100 {
let address = Address(OAMDMA, UInt8(offset))
for offset: UInt8 in 0x00 ... 0xFF {
let address = Address(page: OAMDMA, offset: offset)

OAM[OAMADDR] = CPU.read(address)

Expand Down
7 changes: 7 additions & 0 deletions NES/UInt16+Convenience.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

internal extension UInt16 {
init(high: UInt8, low: UInt8) {
self.init(UInt16(high) << 8 | UInt16(low))
}
}

0 comments on commit 6ef00c0

Please sign in to comment.