added illegal NOP decoding so ProDOS 2.4 boots (at least to a screen saying there's not enough memory)

This commit is contained in:
Luigi Thirty 2017-08-08 18:48:03 -04:00
parent 9ffc814961
commit 92a77fc3d5
3 changed files with 89 additions and 39 deletions

View File

@ -124,19 +124,19 @@ class DiskII: NSObject, Peripheral, HasROM {
softswitches.Phase0 = true
if(motorPhase == .Phase1) {
motorPhase = .Phase0
if(currentTrack % 2 == 0 && currentTrack > 0)
//if(currentTrack % 2 == 0 && currentTrack > 0)
if(currentTrack > 0)
{
currentTrack -= 1
}
if(debug) { print("Drive now on track \(currentTrack)") }
//updateCurrentTrackDisplay(drive: softswitches.DriveSelect)
} else if(motorPhase == .Phase3) {
motorPhase = .Phase0
if(currentTrack % 2 == 1 && currentTrack < 34) {
//if(currentTrack % 2 == 1 && currentTrack < 34) {
if(currentTrack < 34) {
currentTrack += 1
}
if(debug) { print("Drive now on track \(currentTrack)") }
//updateCurrentTrackDisplay(drive: softswitches.DriveSelect)
}
case 2:
softswitches.Phase1 = false
@ -155,14 +155,12 @@ class DiskII: NSObject, Peripheral, HasROM {
currentTrack -= 1
}
if(debug) { print("Drive now on track \(currentTrack)") }
//updateCurrentTrackDisplay(drive: softswitches.DriveSelect)
} else if(motorPhase == .Phase1) {
motorPhase = .Phase2
if(currentTrack % 2 == 0 && currentTrack < 34) {
currentTrack += 1;
}
if(debug) { print("Drive now on track \(currentTrack)") }
//updateCurrentTrackDisplay(drive: softswitches.DriveSelect)
}
case 6:
softswitches.Phase3 = false
@ -209,9 +207,38 @@ class DiskII: NSObject, Peripheral, HasROM {
if(debug) { print("Drive 2 selected") }
case 12:
softswitches.Q6 = false
let trk = CPU.sharedInstance.memoryInterface.readByte(offset: 0xB7EC, bypassOverrides: true)
let sec = CPU.sharedInstance.memoryInterface.readByte(offset: 0xB7ED, bypassOverrides: true)
let mode = CPU.sharedInstance.memoryInterface.readByte(offset: 0xB7F4, bypassOverrides: true)
let trk: UInt8
let sec: UInt8
let mode: UInt8
let blkLo: UInt8
let blkHi: UInt8
if(diskImage!.image is Dos33Image) {
trk = CPU.sharedInstance.memoryInterface.readByte(offset: 0xB7EC, bypassOverrides: true)
sec = CPU.sharedInstance.memoryInterface.readByte(offset: 0xB7ED, bypassOverrides: true)
mode = CPU.sharedInstance.memoryInterface.readByte(offset: 0xB7F4, bypassOverrides: true)
blkLo = 0
blkHi = 0
}
else if(diskImage!.image is ProdosImage) {
trk = CPU.sharedInstance.memoryInterface.readByte(offset: 0x41, bypassOverrides: true)
sec = CPU.sharedInstance.memoryInterface.readByte(offset: 0x3D, bypassOverrides: true)
mode = CPU.sharedInstance.memoryInterface.readByte(offset: 0x42, bypassOverrides: true)
blkLo = CPU.sharedInstance.memoryInterface.readByte(offset: 0x46, bypassOverrides: true)
blkHi = CPU.sharedInstance.memoryInterface.readByte(offset: 0x47, bypassOverrides: true)
} else {
trk = 0
sec = 0
mode = 0
blkLo = 0
blkHi = 0
}
if(trk == 2 && sec == 4 && mode == 1)
{
_ = 1
@ -229,7 +256,22 @@ class DiskII: NSObject, Peripheral, HasROM {
default:
modeString = "???"
}
if(debug) { print("Head is at nibble \(mediaPosition) of track \(currentTrack). DOS is trying to \(modeString) T\(trk) S\(sec).") }
if(debug)
{
if(diskImage!.image is Dos33Image) {
print("Head is at nibble \(mediaPosition) of track \(currentTrack). DOS is trying to \(modeString) T\(trk) S\(sec).")
} else if(diskImage!.image is ProdosImage) {
print("Head is at nibble \(mediaPosition) of track \(currentTrack). ProDOS is trying to \(modeString) Block $\(blkHi.asHexString())\(blkLo.asHexString()) (T\(trk) S\(sec)).")
if(mode == 1) {
let bufLo = CPU.sharedInstance.memoryInterface.readByte(offset: 0x44, bypassOverrides: true)
let bufHi = CPU.sharedInstance.memoryInterface.readByte(offset: 0x45, bypassOverrides: true)
print("I/O buffer is located at $\(bufHi.asHexString())\(bufLo.asHexString())")
}
}
}
updateCurrentTrackSectorDisplay(drive: softswitches.DriveSelect, track: currentTrack, sector: Int(sec))
if(softswitches.Q7 == false && byte == nil) {

View File

@ -53,6 +53,16 @@ class ProdosImage: DiskImageFormat {
static let SECTOR_ORDER = [0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15]
//static let SECTOR_ORDER = [0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 15]
static func readTrackAndSector(imageData: [UInt8], trackNum: Int, sectorNum: Int) -> [UInt8] {
//Find the track in our disk.
let trackOffset = trackNum * ProdosImage.BYTES_PER_TRACK
//Find the sector in this track.
let sectorOffset = sectorNum * BYTES_PER_SECTOR
let offset = trackOffset + sectorOffset
return Array<UInt8>(imageData[offset ..< offset + BYTES_PER_SECTOR])
}
static func readBlock(imageData: [UInt8], blockNum: Int) -> [UInt8] {
var blockData = [UInt8]()
@ -67,34 +77,35 @@ class ProdosImage: DiskImageFormat {
switch blockOffset8 {
case 0:
sector1 = 0
sector2 = 2
sector2 = 0xE
case 1:
sector1 = 4
sector2 = 6
sector1 = 0xD
sector2 = 0xC
case 2:
sector1 = 8
sector1 = 0xB
sector2 = 0xA
case 3:
sector1 = 0xC
sector2 = 0xE
sector1 = 0x9
sector2 = 0x8
case 4:
sector1 = 1
sector2 = 3
sector1 = 0x7
sector2 = 0x6
case 5:
sector1 = 5
sector2 = 7
sector1 = 0x5
sector2 = 0x4
case 6:
sector1 = 9
sector2 = 0xB
sector1 = 0x3
sector2 = 0x2
case 7:
sector1 = 0xD
sector1 = 0x1
sector2 = 0xF
default:
print("should never happen")
}
blockData.append(contentsOf: [UInt8](imageData[blockNum * 0x200 ... (blockNum * 0x200) + 0x1FF]))
blockData.append(contentsOf: [UInt8](readTrackAndSector(imageData: imageData, trackNum: track, sectorNum: sector1)))
blockData.append(contentsOf: [UInt8](readTrackAndSector(imageData: imageData, trackNum: track, sectorNum: sector2)))
return blockData
}
@ -146,14 +157,11 @@ class DiskImage: NSObject {
var blks = [UInt8]()
var nbls = [UInt8]()
/*
for track in encodedTracks {
full.append(contentsOf: track)
nbls.append(contentsOf: track)
}
*/
blks.append(contentsOf: ProdosImage.readBlock(imageData: rawData!, blockNum: 0))
nbls.append(contentsOf: encodedTracks[0])
blks.append(contentsOf: ProdosImage.readBlock(imageData: rawData!, blockNum: 7))
var ptr = UnsafeBufferPointer(start: blks, count: blks.count)
var data = Data(buffer: ptr)
@ -259,15 +267,12 @@ class DiskImage: NSObject {
case 0x00:
let block = ProdosImage.readBlock(imageData: imageData, blockNum: (8 * index) + 0)
encodedData.append(contentsOf: EncodeSectorSixAndTwo(sector: [UInt8](block[0x000...0x0FF])))
/*
case 1:
let block = ProdosImage.readBlock(imageData: imageData, blockNum: (8 * index) + 4)
encodedData.append(contentsOf: EncodeSectorSixAndTwo(sector: [UInt8](block[0x000...0x0FF])))
*/
case 0x0D:
case 0x02:
let block = ProdosImage.readBlock(imageData: imageData, blockNum: (8 * index) + 0)
encodedData.append(contentsOf: EncodeSectorSixAndTwo(sector: [UInt8](block[0x100...0x1FF])))
/*
case 3:
let block = ProdosImage.readBlock(imageData: imageData, blockNum: (8 * index) + 4)
encodedData.append(contentsOf: EncodeSectorSixAndTwo(sector: [UInt8](block[0x100...0x1FF])))
@ -308,13 +313,8 @@ class DiskImage: NSObject {
let block = ProdosImage.readBlock(imageData: imageData, blockNum: (8 * index) + 7)
encodedData.append(contentsOf: EncodeSectorSixAndTwo(sector: [UInt8](block[0x100...0x1FF])))
default:
print("should never happen")
encodedData.append(contentsOf: EncodeSectorSixAndTwo(sector: [UInt8](repeating: 0x4C, count: 343)))
}
*/
default:
encodedData.append(contentsOf: EncodeSectorSixAndTwo(sector: [UInt8](repeating: 0xFF, count: 256)))
}
}
encodedData.append(contentsOf: dataEpilogue)

View File

@ -221,4 +221,12 @@ let InstructionTable: [UInt8:CPUInstruction] = [
0x00: CPUInstruction(mnemonic: "BRK", cycles: 7, bytes: 1, addressingMode: .implied, action: Opcodes.BRK),
0xEA: CPUInstruction(mnemonic: "NOP", cycles: 2, bytes: 1, addressingMode: .implied, action: Opcodes.NOP),
//Illegal opcodes
0x1A: CPUInstruction(mnemonic: "NOP", cycles: 2, bytes: 1, addressingMode: .implied, action: Opcodes.NOP),
0x3A: CPUInstruction(mnemonic: "NOP", cycles: 2, bytes: 1, addressingMode: .implied, action: Opcodes.NOP),
0x5A: CPUInstruction(mnemonic: "NOP", cycles: 2, bytes: 1, addressingMode: .implied, action: Opcodes.NOP),
0x7A: CPUInstruction(mnemonic: "NOP", cycles: 2, bytes: 1, addressingMode: .implied, action: Opcodes.NOP),
0xDA: CPUInstruction(mnemonic: "NOP", cycles: 2, bytes: 1, addressingMode: .implied, action: Opcodes.NOP),
0xFA: CPUInstruction(mnemonic: "NOP", cycles: 2, bytes: 1, addressingMode: .implied, action: Opcodes.NOP),
]