From b9e86401781f3fdde6fa6de47e78ff26bf395b7e Mon Sep 17 00:00:00 2001 From: Tamas Rudnai Date: Sun, 8 Sep 2019 14:52:52 -0700 Subject: [PATCH] - Fixed CMP - Fixed SBC - Fixed RAM access from Swift --- A2Mac/ViewController.swift | 16 ++++++++++------ A2Mac/common.h | 2 +- A2Mac/instructions/6502_instr_arithmetic.h | 5 +---- A2Mac/instructions/6502_instr_load_store.h | 1 - 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift index 4458b97..712f611 100644 --- a/A2Mac/ViewController.swift +++ b/A2Mac/ViewController.swift @@ -13,9 +13,13 @@ class ViewController: NSViewController { @IBOutlet weak var display: NSTextFieldCell! func check() { - let ram = UnsafeRawBufferPointer(start: &RAM+0x400, count: 0x400) - let string = String(bytes: ram, encoding: .utf8) - print(string) + let textBufferPointer = UnsafeRawBufferPointer(start: &RAM+0x400, count: 0x400) +// let string = String(bytes: ram, encoding: .utf8) +// print(string) + + for (index, byte) in textBufferPointer.enumerated() { + print("byte \(index): \(byte)") + } } @@ -63,9 +67,9 @@ class ViewController: NSViewController { // } - DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: { - self.check() - }) +// DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: { +// self.check() +// }) } diff --git a/A2Mac/common.h b/A2Mac/common.h index 93600ab..cf55131 100644 --- a/A2Mac/common.h +++ b/A2Mac/common.h @@ -65,7 +65,7 @@ static inline void set_flags_NVZ( uint8_t test ) { static inline void set_flags_NZC( int test ) { set_flags_NZ(test); - m6502.flags.C = (unsigned)test > 0xFF; + m6502.flags.C = test >= 0; } static inline void set_flags_NZCV( int test ) { diff --git a/A2Mac/instructions/6502_instr_arithmetic.h b/A2Mac/instructions/6502_instr_arithmetic.h index 1990d78..6e63cb3 100644 --- a/A2Mac/instructions/6502_instr_arithmetic.h +++ b/A2Mac/instructions/6502_instr_arithmetic.h @@ -53,10 +53,7 @@ static inline void ADC( uint8_t imm ) { (indirect),Y SBC (oper),Y F1 2 5* **/ static inline void SBC( uint8_t imm ) { - int tmp = (int)m6502.A - imm - m6502.flags.C; - dbgPrintf("SBC A:%02X - i:%02X - C:%u = %02X", m6502.A, imm, m6502.flags.C, tmp); - m6502.A = (uint8_t)tmp; - set_flags_NZCV( tmp ); + ADC( ~imm ); } #endif // __6502_INSTR_ARITHMETIC_H__ diff --git a/A2Mac/instructions/6502_instr_load_store.h b/A2Mac/instructions/6502_instr_load_store.h index b1a1393..d325a54 100644 --- a/A2Mac/instructions/6502_instr_load_store.h +++ b/A2Mac/instructions/6502_instr_load_store.h @@ -93,7 +93,6 @@ static inline void STR( uint8_t * dst, uint8_t imm ) { *dst = imm; // uint16_t v = dst - RAM; - // if ( ( v >= 0x400 ) && ( v < 0x800 ) ) { // char c = charConv[imm]; // if (( imm > ' ' ) && ( c < 0x7F ))