mirror of
https://github.com/Luigi30/FruitMachine-Swift.git
synced 2024-11-23 02:33:00 +00:00
carry flag problem
This commit is contained in:
parent
16ad485931
commit
4efe09ad30
@ -22,6 +22,7 @@
|
|||||||
2A6DC7F01F30495D0066FE0D /* ScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6DC7EF1F30495D0066FE0D /* ScreenView.swift */; };
|
2A6DC7F01F30495D0066FE0D /* ScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6DC7EF1F30495D0066FE0D /* ScreenView.swift */; };
|
||||||
2A7665781F2F05F600135518 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A7665761F2F05F600135518 /* PreferencesWindowController.swift */; };
|
2A7665781F2F05F600135518 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A7665761F2F05F600135518 /* PreferencesWindowController.swift */; };
|
||||||
2A7665791F2F05F600135518 /* PreferencesWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2A7665771F2F05F600135518 /* PreferencesWindow.xib */; };
|
2A7665791F2F05F600135518 /* PreferencesWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2A7665771F2F05F600135518 /* PreferencesWindow.xib */; };
|
||||||
|
2A86FB971F316CB500AD0C68 /* KeyboardController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A86FB961F316CB500AD0C68 /* KeyboardController.swift */; };
|
||||||
2A91852A1F2EA84D00A9E5BE /* BitmapPixels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9185291F2EA84D00A9E5BE /* BitmapPixels.swift */; };
|
2A91852A1F2EA84D00A9E5BE /* BitmapPixels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9185291F2EA84D00A9E5BE /* BitmapPixels.swift */; };
|
||||||
2AA8B5F81F2A8889002B350F /* AppleI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5F71F2A8889002B350F /* AppleI.swift */; };
|
2AA8B5F81F2A8889002B350F /* AppleI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5F71F2A8889002B350F /* AppleI.swift */; };
|
||||||
2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */; };
|
2AA8B5FC1F2A8EAD002B350F /* Terminal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */; };
|
||||||
@ -62,6 +63,7 @@
|
|||||||
2A6DC7EF1F30495D0066FE0D /* ScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenView.swift; sourceTree = "<group>"; };
|
2A6DC7EF1F30495D0066FE0D /* ScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenView.swift; sourceTree = "<group>"; };
|
||||||
2A7665761F2F05F600135518 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
|
2A7665761F2F05F600135518 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
|
||||||
2A7665771F2F05F600135518 /* PreferencesWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PreferencesWindow.xib; sourceTree = "<group>"; };
|
2A7665771F2F05F600135518 /* PreferencesWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PreferencesWindow.xib; sourceTree = "<group>"; };
|
||||||
|
2A86FB961F316CB500AD0C68 /* KeyboardController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardController.swift; sourceTree = "<group>"; };
|
||||||
2A9185291F2EA84D00A9E5BE /* BitmapPixels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitmapPixels.swift; sourceTree = "<group>"; };
|
2A9185291F2EA84D00A9E5BE /* BitmapPixels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitmapPixels.swift; sourceTree = "<group>"; };
|
||||||
2AA8B5F71F2A8889002B350F /* AppleI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleI.swift; sourceTree = "<group>"; };
|
2AA8B5F71F2A8889002B350F /* AppleI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleI.swift; sourceTree = "<group>"; };
|
||||||
2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Terminal.swift; sourceTree = "<group>"; };
|
2AA8B5FB1F2A8EAD002B350F /* Terminal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Terminal.swift; sourceTree = "<group>"; };
|
||||||
@ -163,6 +165,7 @@
|
|||||||
children = (
|
children = (
|
||||||
2A6DC7EE1F30492E0066FE0D /* Video */,
|
2A6DC7EE1F30492E0066FE0D /* Video */,
|
||||||
2AB6CACC1F3041A200DECAC0 /* AppleII.swift */,
|
2AB6CACC1F3041A200DECAC0 /* AppleII.swift */,
|
||||||
|
2A86FB961F316CB500AD0C68 /* KeyboardController.swift */,
|
||||||
2A6C2D161F31216700B8DC60 /* SoftswitchOverrides.swift */,
|
2A6C2D161F31216700B8DC60 /* SoftswitchOverrides.swift */,
|
||||||
);
|
);
|
||||||
path = AppleII;
|
path = AppleII;
|
||||||
@ -358,6 +361,7 @@
|
|||||||
2AD6D5841F26E6BF008F3CF5 /* DebuggerCommands.swift in Sources */,
|
2AD6D5841F26E6BF008F3CF5 /* DebuggerCommands.swift in Sources */,
|
||||||
2AE5BA041F23DE4400FAA343 /* Disassembly.swift in Sources */,
|
2AE5BA041F23DE4400FAA343 /* Disassembly.swift in Sources */,
|
||||||
2A6DC7EB1F3045C90066FE0D /* EmulatedSystem.swift in Sources */,
|
2A6DC7EB1F3045C90066FE0D /* EmulatedSystem.swift in Sources */,
|
||||||
|
2A86FB971F316CB500AD0C68 /* KeyboardController.swift in Sources */,
|
||||||
2AE42E3A1F28628300C4900E /* AppleIViewController.swift in Sources */,
|
2AE42E3A1F28628300C4900E /* AppleIViewController.swift in Sources */,
|
||||||
2AD458E51F2070DF00F05121 /* Opcodes.swift in Sources */,
|
2AD458E51F2070DF00F05121 /* Opcodes.swift in Sources */,
|
||||||
2AE42E081F2850F400C4900E /* ReadOverride.swift in Sources */,
|
2AE42E081F2850F400C4900E /* ReadOverride.swift in Sources */,
|
||||||
|
@ -14,6 +14,7 @@ class AppleII: NSObject, EmulatedSystem {
|
|||||||
var frameCounter: Int = 0
|
var frameCounter: Int = 0
|
||||||
|
|
||||||
let cg = A2CharacterGenerator(romPath: "/Users/luigi/apple2/a2.chr");
|
let cg = A2CharacterGenerator(romPath: "/Users/luigi/apple2/a2.chr");
|
||||||
|
let keyboardController = KeyboardController()
|
||||||
|
|
||||||
var CPU_FREQUENCY: Double
|
var CPU_FREQUENCY: Double
|
||||||
var FRAMES_PER_SECOND: Double
|
var FRAMES_PER_SECOND: Double
|
||||||
@ -30,6 +31,7 @@ class AppleII: NSObject, EmulatedSystem {
|
|||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
loadROMs()
|
loadROMs()
|
||||||
|
setupMemory(ramConfig: .sixteenK)
|
||||||
|
|
||||||
emuScreenLayer.shouldRasterize = true
|
emuScreenLayer.shouldRasterize = true
|
||||||
emuScreenLayer.delegate = emulatorViewDelegate
|
emuScreenLayer.delegate = emulatorViewDelegate
|
||||||
@ -42,14 +44,21 @@ class AppleII: NSObject, EmulatedSystem {
|
|||||||
|
|
||||||
installOverrides()
|
installOverrides()
|
||||||
|
|
||||||
|
doReset()
|
||||||
|
}
|
||||||
|
|
||||||
|
func doReset() {
|
||||||
CPU.sharedInstance.performReset()
|
CPU.sharedInstance.performReset()
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadROMs() {
|
func loadROMs() {
|
||||||
|
/*
|
||||||
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple2/341-0001-00.e0", offset: 0xE000, length: 0x800)
|
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple2/341-0001-00.e0", offset: 0xE000, length: 0x800)
|
||||||
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple2/341-0002-00.e8", offset: 0xE800, length: 0x800)
|
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple2/341-0002-00.e8", offset: 0xE800, length: 0x800)
|
||||||
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple2/341-0003-00.f0", offset: 0xF000, length: 0x800)
|
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple2/341-0003-00.f0", offset: 0xF000, length: 0x800)
|
||||||
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple2/341-0004-00.f8", offset: 0xF800, length: 0x800)
|
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/apple2/341-0004-00.f8", offset: 0xF800, length: 0x800)
|
||||||
|
*/
|
||||||
|
CPU.sharedInstance.memoryInterface.loadBinary(path: "/Users/luigi/6502/test.bin", offset: 0x0000, length: 0x10000)
|
||||||
}
|
}
|
||||||
|
|
||||||
func installOverrides() {
|
func installOverrides() {
|
||||||
@ -89,4 +98,33 @@ class AppleII: NSObject, EmulatedSystem {
|
|||||||
emulatorView.setNeedsDisplay(emulatorView.frame)
|
emulatorView.setNeedsDisplay(emulatorView.frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum MemoryConfiguration {
|
||||||
|
case fourK
|
||||||
|
case sixteenK
|
||||||
|
case fortyeightK
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupMemory(ramConfig: MemoryConfiguration) {
|
||||||
|
let ramPages: Int
|
||||||
|
|
||||||
|
switch ramConfig {
|
||||||
|
case .fourK:
|
||||||
|
ramPages = 4096 / 256
|
||||||
|
case .sixteenK:
|
||||||
|
ramPages = 16384 / 256
|
||||||
|
case .fortyeightK:
|
||||||
|
ramPages = 49152 / 256
|
||||||
|
}
|
||||||
|
|
||||||
|
for page in 0 ..< ramPages {
|
||||||
|
CPU.sharedInstance.memoryInterface.pages[page] = MemoryInterface.pageMode.rw //RAM
|
||||||
|
}
|
||||||
|
for page in ramPages ..< 192 {
|
||||||
|
CPU.sharedInstance.memoryInterface.pages[page] = MemoryInterface.pageMode.null //not connected
|
||||||
|
}
|
||||||
|
for page in 224 ..< 256 {
|
||||||
|
CPU.sharedInstance.memoryInterface.pages[page] = MemoryInterface.pageMode.ro //not connected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
14
FruitMachine/AppleII/KeyboardController.swift
Normal file
14
FruitMachine/AppleII/KeyboardController.swift
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//
|
||||||
|
// KeyboardController.swift
|
||||||
|
// FruitMachine
|
||||||
|
//
|
||||||
|
// Created by Christopher Rohl on 8/1/17.
|
||||||
|
// Copyright © 2017 Christopher Rohl. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
class KeyboardController: NSObject {
|
||||||
|
var KEYBOARD: UInt8 = 0x00
|
||||||
|
var STROBE: UInt8 = 0x00
|
||||||
|
}
|
@ -13,11 +13,10 @@ extension AppleII {
|
|||||||
class SoftswitchOverrides: NSObject {
|
class SoftswitchOverrides: NSObject {
|
||||||
static let readKeyboard = ReadOverride(start: 0xC000, end: 0xC000, readAnyway: false, action: SoftswitchOverrides.actionReadKeyboard)
|
static let readKeyboard = ReadOverride(start: 0xC000, end: 0xC000, readAnyway: false, action: SoftswitchOverrides.actionReadKeyboard)
|
||||||
static func actionReadKeyboard(dummy: AnyObject, byte: UInt8?) -> UInt8? {
|
static func actionReadKeyboard(dummy: AnyObject, byte: UInt8?) -> UInt8? {
|
||||||
let b = CPU.sharedInstance.memoryInterface.readByte(offset: 0xC000, bypassOverrides: true)
|
//let b = CPU.sharedInstance.memoryInterface.readByte(offset: 0xC000, bypassOverrides: true)
|
||||||
|
//CPU.sharedInstance.memoryInterface.writeByte(offset: 0xC000, value: b)
|
||||||
CPU.sharedInstance.memoryInterface.writeByte(offset: 0xC000, value: b)
|
//return b
|
||||||
|
return AppleII.sharedInstance.keyboardController.KEYBOARD
|
||||||
return b
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static let clearKeypressStrobeR = ReadOverride(start: 0xC010, end: 0xC010, readAnyway: false, action: SoftswitchOverrides.actionClearKeypressStrobe)
|
static let clearKeypressStrobeR = ReadOverride(start: 0xC010, end: 0xC010, readAnyway: false, action: SoftswitchOverrides.actionClearKeypressStrobe)
|
||||||
@ -25,10 +24,14 @@ extension AppleII {
|
|||||||
static func actionClearKeypressStrobe(dummy: AnyObject, byte: UInt8?) -> UInt8? {
|
static func actionClearKeypressStrobe(dummy: AnyObject, byte: UInt8?) -> UInt8? {
|
||||||
//Clears b7 of $C000 on write.
|
//Clears b7 of $C000 on write.
|
||||||
|
|
||||||
let b = CPU.sharedInstance.memoryInterface.readByte(offset: 0xC000, bypassOverrides: true)
|
//let b = CPU.sharedInstance.memoryInterface.readByte(offset: 0xC000, bypassOverrides: true)
|
||||||
CPU.sharedInstance.memoryInterface.writeByte(offset: 0xC000, value: b & 0x7F, bypassOverrides: true)
|
//CPU.sharedInstance.memoryInterface.writeByte(offset: 0xC000, value: b & 0x7F, bypassOverrides: true)
|
||||||
//CPU.sharedInstance.memoryInterface.writeByte(offset: 0xC010, value: b & 0x7F, bypassOverrides: true)
|
//CPU.sharedInstance.memoryInterface.writeByte(offset: 0xC010, value: b & 0x7F, bypassOverrides: true)
|
||||||
|
|
||||||
|
//return b
|
||||||
|
let b = AppleII.sharedInstance.keyboardController.KEYBOARD
|
||||||
|
AppleII.sharedInstance.keyboardController.KEYBOARD = b & 0x7F
|
||||||
|
AppleII.sharedInstance.keyboardController.STROBE = b & 0x7F
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,15 @@ class AppleIIViewController: NSViewController {
|
|||||||
|
|
||||||
self.view.addSubview(computer.emulatorView)
|
self.view.addSubview(computer.emulatorView)
|
||||||
|
|
||||||
|
/*
|
||||||
self.frameTimer = Timer.scheduledTimer(timeInterval: 1.0/60.0,
|
self.frameTimer = Timer.scheduledTimer(timeInterval: 1.0/60.0,
|
||||||
target: self,
|
target: self,
|
||||||
selector: #selector(runEmulation),
|
selector: #selector(runEmulation),
|
||||||
userInfo: nil,
|
userInfo: nil,
|
||||||
repeats: true)
|
repeats: true)
|
||||||
|
*/
|
||||||
|
|
||||||
|
CPU.sharedInstance.program_counter = 0x400
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func runEmulation() {
|
@objc func runEmulation() {
|
||||||
@ -49,6 +53,10 @@ class AppleIIViewController: NSViewController {
|
|||||||
preferencesWindowController.loadWindow()
|
preferencesWindowController.loadWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IBAction func doReset(_ sender: Any) {
|
||||||
|
computer.doReset()
|
||||||
|
}
|
||||||
|
|
||||||
override func keyDown(with event: NSEvent) {
|
override func keyDown(with event: NSEvent) {
|
||||||
let c = returnChar(theEvent: event)
|
let c = returnChar(theEvent: event)
|
||||||
|
|
||||||
@ -56,8 +64,8 @@ class AppleIIViewController: NSViewController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//Poke the ASCII byte into $C000.
|
//Set the keyboard input register accordingly. Set b7 so the OS knows there's a keypress waiting
|
||||||
CPU.sharedInstance.memoryInterface.writeByte(offset: 0xC000, value: UInt8((ascii32 | 0x80) & 0x000000FF))
|
computer.keyboardController.KEYBOARD = UInt8((ascii32 | 0x80) & 0x000000FF)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func returnChar(theEvent: NSEvent) -> Character?{
|
private func returnChar(theEvent: NSEvent) -> Character?{
|
||||||
|
@ -64,60 +64,9 @@
|
|||||||
<modifierMask key="keyEquivalentModifierMask"/>
|
<modifierMask key="keyEquivalentModifierMask"/>
|
||||||
<menu key="submenu" title="File" id="bib-Uj-vzu">
|
<menu key="submenu" title="File" id="bib-Uj-vzu">
|
||||||
<items>
|
<items>
|
||||||
<menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
|
<menuItem title="Reset" keyEquivalent="r" id="aTl-1u-JFS">
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="newDocument:" target="Ady-hI-5gd" id="4Si-XN-c54"/>
|
<action selector="doReset:" target="Ady-hI-5gd" id="7dg-B5-6Ok"/>
|
||||||
</connections>
|
|
||||||
</menuItem>
|
|
||||||
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
|
|
||||||
<connections>
|
|
||||||
<action selector="openDocument:" target="Ady-hI-5gd" id="bVn-NM-KNZ"/>
|
|
||||||
</connections>
|
|
||||||
</menuItem>
|
|
||||||
<menuItem title="Open Recent" id="tXI-mr-wws">
|
|
||||||
<modifierMask key="keyEquivalentModifierMask"/>
|
|
||||||
<menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
|
|
||||||
<items>
|
|
||||||
<menuItem title="Clear Menu" id="vNY-rz-j42">
|
|
||||||
<modifierMask key="keyEquivalentModifierMask"/>
|
|
||||||
<connections>
|
|
||||||
<action selector="clearRecentDocuments:" target="Ady-hI-5gd" id="Daa-9d-B3U"/>
|
|
||||||
</connections>
|
|
||||||
</menuItem>
|
|
||||||
</items>
|
|
||||||
</menu>
|
|
||||||
</menuItem>
|
|
||||||
<menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
|
|
||||||
<menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
|
|
||||||
<connections>
|
|
||||||
<action selector="performClose:" target="Ady-hI-5gd" id="HmO-Ls-i7Q"/>
|
|
||||||
</connections>
|
|
||||||
</menuItem>
|
|
||||||
<menuItem title="Save…" keyEquivalent="s" id="pxx-59-PXV">
|
|
||||||
<connections>
|
|
||||||
<action selector="saveDocument:" target="Ady-hI-5gd" id="teZ-XB-qJY"/>
|
|
||||||
</connections>
|
|
||||||
</menuItem>
|
|
||||||
<menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
|
|
||||||
<connections>
|
|
||||||
<action selector="saveDocumentAs:" target="Ady-hI-5gd" id="mDf-zr-I0C"/>
|
|
||||||
</connections>
|
|
||||||
</menuItem>
|
|
||||||
<menuItem title="Revert to Saved" keyEquivalent="r" id="KaW-ft-85H">
|
|
||||||
<connections>
|
|
||||||
<action selector="revertDocumentToSaved:" target="Ady-hI-5gd" id="iJ3-Pv-kwq"/>
|
|
||||||
</connections>
|
|
||||||
</menuItem>
|
|
||||||
<menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
|
|
||||||
<menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK">
|
|
||||||
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
|
|
||||||
<connections>
|
|
||||||
<action selector="runPageLayout:" target="Ady-hI-5gd" id="Din-rz-gC5"/>
|
|
||||||
</connections>
|
|
||||||
</menuItem>
|
|
||||||
<menuItem title="Print…" keyEquivalent="p" id="aTl-1u-JFS">
|
|
||||||
<connections>
|
|
||||||
<action selector="print:" target="Ady-hI-5gd" id="qaZ-4w-aoO"/>
|
|
||||||
</connections>
|
</connections>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
</items>
|
</items>
|
||||||
|
@ -46,7 +46,7 @@ class DebuggerViewController: NSViewController {
|
|||||||
text_CPU_SR.stringValue = String(format:"%02X", cpuInstance.stack_pointer)
|
text_CPU_SR.stringValue = String(format:"%02X", cpuInstance.stack_pointer)
|
||||||
text_CPU_Flags.stringValue = String(cpuInstance.status_register.asString())
|
text_CPU_Flags.stringValue = String(cpuInstance.status_register.asString())
|
||||||
|
|
||||||
disassembly = cpuInstance.disassemble(fromAddress: CPU.sharedInstance.program_counter, length: 256)
|
disassembly = cpuInstance.disassemble(fromAddress: CPU.sharedInstance.program_counter &- 16, length: 256)
|
||||||
debuggerTableView.reloadData()
|
debuggerTableView.reloadData()
|
||||||
highlightCurrentInstruction()
|
highlightCurrentInstruction()
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ class DebuggerViewController: NSViewController {
|
|||||||
debuggerTableView.dataSource = self
|
debuggerTableView.dataSource = self
|
||||||
|
|
||||||
updateCPUStatusFields()
|
updateCPUStatusFields()
|
||||||
disassembly = cpuInstance.disassemble(fromAddress: CPU.sharedInstance.program_counter, length: 256)
|
disassembly = cpuInstance.disassemble(fromAddress: CPU.sharedInstance.program_counter &- 16, length: 256)
|
||||||
debuggerTableView.reloadData()
|
debuggerTableView.reloadData()
|
||||||
|
|
||||||
// Do any additional setup after loading the view.
|
// Do any additional setup after loading the view.
|
||||||
|
@ -9,20 +9,31 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
final class MemoryInterface: NSObject {
|
final class MemoryInterface: NSObject {
|
||||||
|
enum pageMode {
|
||||||
|
case ro
|
||||||
|
case rw
|
||||||
|
case null
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fileprivate var memory: [UInt8]
|
fileprivate var memory: [UInt8]
|
||||||
|
|
||||||
var read_overrides: [ReadOverride]
|
var read_overrides: [ReadOverride]
|
||||||
var write_overrides: [WriteOverride]
|
var write_overrides: [WriteOverride]
|
||||||
|
|
||||||
|
var pages: [pageMode] = [pageMode](repeating: .null, count: 256)
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
memory = [UInt8](repeating: 0x00, count: 65536)
|
memory = [UInt8](repeating: 0x00, count: 65536)
|
||||||
read_overrides = [ReadOverride]()
|
read_overrides = [ReadOverride]()
|
||||||
write_overrides = [WriteOverride]()
|
write_overrides = [WriteOverride]()
|
||||||
}
|
}
|
||||||
|
|
||||||
func readByte(offset: UInt16, bypassOverrides: Bool = false) -> UInt8 {
|
func getPage(offset: UInt16) -> UInt8 {
|
||||||
|
return UInt8(offset >> 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
func readByte(offset: UInt16, bypassOverrides: Bool = false) -> UInt8 {
|
||||||
if(!bypassOverrides) {
|
if(!bypassOverrides) {
|
||||||
for override in read_overrides {
|
for override in read_overrides {
|
||||||
if case override.rangeStart ... override.rangeEnd = offset {
|
if case override.rangeStart ... override.rangeEnd = offset {
|
||||||
@ -34,6 +45,11 @@ final class MemoryInterface: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If no override, check if there's memory here.
|
||||||
|
if(pages[Int(getPage(offset: offset))] == pageMode.null) {
|
||||||
|
return 0x00
|
||||||
|
}
|
||||||
|
|
||||||
//No match.
|
//No match.
|
||||||
return memory[Int(offset)]
|
return memory[Int(offset)]
|
||||||
}
|
}
|
||||||
@ -51,6 +67,11 @@ final class MemoryInterface: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If no override, check if there's memory here to write.
|
||||||
|
if(pages[Int(getPage(offset: offset))] != pageMode.rw) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
memory[Int(offset)] = value
|
memory[Int(offset)] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,8 @@ final class Opcodes: NSObject {
|
|||||||
if(state.status_register.decimal == true) {
|
if(state.status_register.decimal == true) {
|
||||||
t16 = UInt16(hex2bcd(hex: state.accumulator) + hex2bcd(hex: operand) + (state.status_register.carry ? UInt8(1) : UInt8(0)))
|
t16 = UInt16(hex2bcd(hex: state.accumulator) + hex2bcd(hex: operand) + (state.status_register.carry ? UInt8(1) : UInt8(0)))
|
||||||
} else {
|
} else {
|
||||||
state.status_register.carry = t8 <= 127 ? true : false
|
//carry flag isn't being set properly
|
||||||
|
state.status_register.carry = (t8 >= 127) ? true : false
|
||||||
}
|
}
|
||||||
|
|
||||||
state.accumulator = t8
|
state.accumulator = t8
|
||||||
|
Loading…
Reference in New Issue
Block a user