Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swiftでつくるファミコンエミュレータのススメ

Tomochika Hara
September 06, 2019

 Swiftでつくるファミコンエミュレータのススメ

Tomochika Hara

September 06, 2019
Tweet

More Decks by Tomochika Hara

Other Decks in Programming

Transcript

  1. ݻఆ௕੔਺ܕ • UInt8 / Int8 • UInt16 / Int16 •

    UInt32 / Int32 • ͜ΕΒ͕ͳ͚Ε͹ɺANDԋࢉͩΒ͚ʹͳΔ • Javaܥͱ͔LLͱ͔͸͜Ε͕͠ΜͲ͍͔΋
  2. ϏοτϚεΫఆٛ struct Status: OptionSet { let rawValue: UInt8 /// Negative

    static let N = Status(rawValue: 1 << 7) /// Overflow static let V = Status(rawValue: 1 << 6) /// Decimal mode static let D = Status(rawValue: 1 << 3) /// IRQ prevention static let I = Status(rawValue: 1 << 2) /// Zero static let Z = Status(rawValue: 1 << 1) /// Carry static let C = Status(rawValue: 1 << 0) /// The B flag static let B = Status(rawValue: 0b00110000) }
  3. ҙਤ͕Θ͔Γ΍͍͢Ϗοτԋࢉ // 0b1001100 var cpuStatus: Status = [.V, .D, .I]

    // 0b1001100 & ~0b00001101 = 0b1000000 cpuStatus.remove([.C, .D, .I]) // 0b1000000 | 0b0000001 = 0b1000001 cpuStatus.formUnion(.C)
  4. PureSwift/SDL public func copy(_ texture: SDLTexture, source: SDL_Rect? = nil,

    destination: SDL_Rect? = nil) throws { let srcPtr: UnsafePointer<SDL_Rect>? if let rect = source { srcPtr = withUnsafePointer(to: rect) { $0 } } else { srcPtr = nil } ... try SDL_RenderCopy(ptr, texture.ptr, sourcePointer, destPtr).sdlThrow(... } https://github.com/PureSwift/SDL
  5. thara/SDL public func copy(_ texture: SDLTexture, _ s: inout SDL_Rect,

    _ d: inout SDL_Rect) throws { try SDL_RenderCopy(ptr, texture.ptr, &s, &d).sdlThrow(type: type(of: self)) } public func copy(_ texture: SDLTexture, _ s: inout SDL_Rect) throws { try SDL_RenderCopy(ptr, texture.ptr, &s, nil).sdlThrow(type: type(of: self)) } public func copy(_ texture: SDLTexture, _ d: inout SDL_Rect) throws { try SDL_RenderCopy(ptr, texture.ptr, nil, &d).sdlThrow(type: type(of: self)) }