Skip to content

Instantly share code, notes, and snippets.

@jarrodnorwell
Created October 10, 2023 07:07
Show Gist options
  • Save jarrodnorwell/b04840b73fda64e0a5bd6d632a9e0f7e to your computer and use it in GitHub Desktop.
Save jarrodnorwell/b04840b73fda64e0a5bd6d632a9e0f7e to your computer and use it in GitHub Desktop.
Reads Sony license string from PS1 BIOS file (pain)
class BUS {
var cpu: CPU!
var rom: UnsafeMutablePointer<UInt8>! = nil
init() {
self.cpu = CPU(bus: self)
do {
var data = try Data(contentsOf: Bundle.main.url(forResource: "SCPH9002", withExtension: "BIN")!)
data.withUnsafeMutableBytes { pointer in
guard let bytes = pointer.bindMemory(to: UInt8.self).baseAddress else {
return
}
self.rom = bytes
}
var dst = UnsafeMutablePointer<CChar>.allocate(capacity: 0x1F) // strlen("Sony Computer Entertainment Inc") = 31 (0x1F)
memcpy(dst, self.rom + 0x108, 0x1F)
print(String(cString: dst, encoding: .utf8) ?? "")
} catch {
print(error.localizedDescription)
}
}
func tick() {
}
}
class CPU {
var bus: BUS!
init(bus: BUS) {
self.bus = bus
}
}
/*
Usage:
let bus = BUS() // will show license string
while true {
bus.tick() // unused
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment