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

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

A8e4760b4a4b9227a12bcd37476987fd?s=128

Tomochika Hara

September 06, 2019
Tweet

Transcript

  1. 2.
  2. 3.
  3. 4.
  4. 6.
  5. 7.
  6. 8.
  7. 11.

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

    UInt32 / Int32 • ͜ΕΒ͕ͳ͚Ε͹ɺANDԋࢉͩΒ͚ʹͳΔ • Javaܥͱ͔LLͱ͔͸͜Ε͕͠ΜͲ͍͔΋
  8. 17.

    ϏοτϚεΫఆٛ 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) }
  9. 18.

    ҙਤ͕Θ͔Γ΍͍͢Ϗοτԋࢉ // 0b1001100 var cpuStatus: Status = [.V, .D, .I]

    // 0b1001100 & ~0b00001101 = 0b1000000 cpuStatus.remove([.C, .D, .I]) // 0b1000000 | 0b0000001 = 0b1000001 cpuStatus.formUnion(.C)
  10. 26.

    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
  11. 27.

    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)) }
  12. 30.