- Disassembler

- HiRes graphics
This commit is contained in:
Tamas Rudnai 2019-09-22 01:31:09 -07:00
parent 8f914756eb
commit 1e455a011e
21 changed files with 511 additions and 80 deletions

View File

@ -32,12 +32,15 @@
32C453242331FED90000EBA1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32BFFB5E22EACC660003B53F /* Assets.xcassets */; };
32C453252331FED90000EBA1 /* apple.rom in Resources */ = {isa = PBXBuildFile; fileRef = 32439F8422ECD8AD0077AAE0 /* apple.rom */; };
32C453272331FED90000EBA1 /* 6502_functional_test.bin in Resources */ = {isa = PBXBuildFile; fileRef = 326ED2EE232D7A0000A41337 /* 6502_functional_test.bin */; };
32C4532E233345430000EBA1 /* QuietView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C4532D233345420000EBA1 /* QuietView.swift */; };
32C4532F233345820000EBA1 /* QuietView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C4532D233345420000EBA1 /* QuietView.swift */; };
32C45330233345820000EBA1 /* QuietView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C4532D233345420000EBA1 /* QuietView.swift */; };
32C4532E233345430000EBA1 /* MonitorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C4532D233345420000EBA1 /* MonitorView.swift */; };
32C4532F233345820000EBA1 /* MonitorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C4532D233345420000EBA1 /* MonitorView.swift */; };
32C45330233345820000EBA1 /* MonitorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C4532D233345420000EBA1 /* MonitorView.swift */; };
32C4533123335E560000EBA1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32BFFB6022EACC660003B53F /* Main.storyboard */; };
32C4533223335E570000EBA1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32BFFB6022EACC660003B53F /* Main.storyboard */; };
32C4533323335E570000EBA1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32BFFB6022EACC660003B53F /* Main.storyboard */; };
32DBF7642334657900DD50E7 /* HiRes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DBF7632334657900DD50E7 /* HiRes.swift */; };
32DBF7652334657900DD50E7 /* HiRes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DBF7632334657900DD50E7 /* HiRes.swift */; };
32DBF7662334657900DD50E7 /* HiRes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DBF7632334657900DD50E7 /* HiRes.swift */; };
32EDB7A223272CA80073AF2D /* fail1.txt in Resources */ = {isa = PBXBuildFile; fileRef = 32EDB7A123272CA80073AF2D /* fail1.txt */; };
/* End PBXBuildFile section */
@ -101,7 +104,9 @@
32C4531A2331F7220000EBA1 /* A2Mac copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "A2Mac copy-Info.plist"; path = "/Users/trudnai/Projects/A2Mac/A2Mac copy-Info.plist"; sourceTree = "<absolute>"; };
32C4532B2331FED90000EBA1 /* Functiontest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Functiontest.app; sourceTree = BUILT_PRODUCTS_DIR; };
32C4532C2331FEDA0000EBA1 /* A2Mac copy2-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "A2Mac copy2-Info.plist"; path = "/Users/trudnai/Projects/A2Mac/A2Mac copy2-Info.plist"; sourceTree = "<absolute>"; };
32C4532D233345420000EBA1 /* QuietView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuietView.swift; sourceTree = "<group>"; };
32C4532D233345420000EBA1 /* MonitorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonitorView.swift; sourceTree = "<group>"; };
32DBF7632334657900DD50E7 /* HiRes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HiRes.swift; sourceTree = "<group>"; };
32DBF76723373FB400DD50E7 /* disassembler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = disassembler.h; sourceTree = "<group>"; };
32EDB7A123272CA80073AF2D /* fail1.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = fail1.txt; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -194,8 +199,9 @@
isa = PBXGroup;
children = (
32439F7522ECD8AD0077AAE0 /* instructions */,
32439F7422ECD8AD0077AAE0 /* 6502.c */,
32439F8522ECD8AD0077AAE0 /* 6502.h */,
32439F7422ECD8AD0077AAE0 /* 6502.c */,
32DBF76723373FB400DD50E7 /* disassembler.h */,
32439F8422ECD8AD0077AAE0 /* apple.rom */,
326ED2EE232D7A0000A41337 /* 6502_functional_test.bin */,
32439F7322ECD8AD0077AAE0 /* Apple2_mmio.h */,
@ -203,7 +209,8 @@
32439F8622ECD8AD0077AAE0 /* common.h */,
32BFFB5A22EACC630003B53F /* AppDelegate.swift */,
32BFFB5C22EACC630003B53F /* ViewController.swift */,
32C4532D233345420000EBA1 /* QuietView.swift */,
32C4532D233345420000EBA1 /* MonitorView.swift */,
32DBF7632334657900DD50E7 /* HiRes.swift */,
32C453072331C0910000EBA1 /* NSLayoutManager-Extension.swift */,
32C45305232E3EEF0000EBA1 /* RepeatingTimer.swift */,
32EDB7A123272CA80073AF2D /* fail1.txt */,
@ -429,8 +436,9 @@
buildActionMask = 2147483647;
files = (
32439F8722ECD8AD0077AAE0 /* 6502.c in Sources */,
32DBF7642334657900DD50E7 /* HiRes.swift in Sources */,
32BFFB5D22EACC630003B53F /* ViewController.swift in Sources */,
32C4532E233345430000EBA1 /* QuietView.swift in Sources */,
32C4532E233345430000EBA1 /* MonitorView.swift in Sources */,
32BFFB5B22EACC630003B53F /* AppDelegate.swift in Sources */,
32C45306232E3EEF0000EBA1 /* RepeatingTimer.swift in Sources */,
);
@ -457,8 +465,9 @@
buildActionMask = 2147483647;
files = (
32C4530B2331F7220000EBA1 /* 6502.c in Sources */,
32DBF7652334657900DD50E7 /* HiRes.swift in Sources */,
32C4530C2331F7220000EBA1 /* ViewController.swift in Sources */,
32C4532F233345820000EBA1 /* QuietView.swift in Sources */,
32C4532F233345820000EBA1 /* MonitorView.swift in Sources */,
32C4530D2331F7220000EBA1 /* AppDelegate.swift in Sources */,
32C4530E2331F7220000EBA1 /* RepeatingTimer.swift in Sources */,
);
@ -469,8 +478,9 @@
buildActionMask = 2147483647;
files = (
32C4531D2331FED90000EBA1 /* 6502.c in Sources */,
32DBF7662334657900DD50E7 /* HiRes.swift in Sources */,
32C4531E2331FED90000EBA1 /* ViewController.swift in Sources */,
32C45330233345820000EBA1 /* QuietView.swift in Sources */,
32C45330233345820000EBA1 /* MonitorView.swift in Sources */,
32C4531F2331FED90000EBA1 /* AppDelegate.swift in Sources */,
32C453202331FED90000EBA1 /* RepeatingTimer.swift in Sources */,
);

View File

@ -20,7 +20,6 @@
#endif
#include "common.h"
#include "Apple2_mmio.h"
#define SOFTRESET_VECTOR 0x3F2
@ -47,6 +46,13 @@ INLINE unsigned long long rdtsc(void)
}
m6502_t m6502 = { 0, 0, 0, 0, 0, 0, 0, NO_DEBUG, HLT };
disassembly_t disassembly;
#include "disassembler.h"
#include "Apple2_mmio.h"
/**
Instruction Implementations
@ -56,12 +62,9 @@ INLINE unsigned long long rdtsc(void)
**/
#include "6502_instructions.h"
/////
unsigned long long int clktime = 0;
m6502_t m6502 = { 0, 0, 0, 0, 0, 0, 0, HLT };
INLINE int m6502_Step() {
@ -274,8 +277,11 @@ INLINE int m6502_Step() {
break;
}
#endif
disNewInstruction();
switch ( fetch() ) {
case 0x00: BRK(); return 2; // BRK
case 0x00: BRK(); return 7; // BRK
case 0x01: ORA( src_X_ind() ); return 6; // ORA X,ind
// case 0x02: // t jams
// case 0x03: // SLO* (undocumented)
@ -387,7 +393,7 @@ INLINE int m6502_Step() {
case 0x6D: ADC( src_abs() ); return 4; // ADC abs
case 0x6E: ROR( dest_abs() ); return 6; // ROR abs
// case 0x6F: RRA abs 6
case 0x70: BVS( rel_addr() ); break; // BVS rel
case 0x70: BVS( rel_addr() ); return 2; // BVS rel
case 0x71: ADC( src_ind_Y() ); return 5; // ADC ind,Y
// case 0x72:
// case 0x73:
@ -523,7 +529,7 @@ INLINE int m6502_Step() {
case 0xF5: SBC( src_zp_X() ); return 4; // SBC zpg,X
case 0xF6: INC( dest_zp_X() ); return 6; // INC zpg,X
// case 0xF7:
case 0xF8: SED(); break; // SED
case 0xF8: SED(); return 2; // SED
case 0xF9: SBC( src_abs_Y() ); return 4; // SBC abs,Y
// case 0xFA:
// case 0xFB:
@ -538,7 +544,7 @@ INLINE int m6502_Step() {
}
// } // fetch16
return 4;
return 2;
}
unsigned long long ee = 0;
@ -594,7 +600,8 @@ void m6502_Run() {
dbgPrintf("%llu %04X: ", clktime, m6502.PC);
clktime += clk = m6502_Step();
printDisassembly();
dbgPrintf("\nA:%02X X:%02X Y:%02X SP:%02X %c%c%c%c%c%c%c%c\n",
m6502.A,
m6502.X,
@ -796,8 +803,7 @@ void m6502_Reset() {
// memcpy( RAM + 0x1000, counter_fast, sizeof(counter));
// m6502.pc = 0x1000;
// m6502.PC = 0x1000;
}

View File

@ -12,7 +12,8 @@
#import "stdint.h"
#ifdef DEBUG
#define dbgPrintf(format, ...) printf (format, ## __VA_ARGS__)
//#define dbgPrintf(format, ...) printf (format, ## __VA_ARGS__)
#define dbgPrintf(format, ...)
#define dbgPrintf2(format, ...) printf (format, ## __VA_ARGS__)
#else
#define dbgPrintf(format, ...)
@ -27,6 +28,13 @@ typedef enum {
SOFTRESET,
} interrupt_t;
typedef enum {
NO_DEBUG,
DISASSEMBLY,
DEBUGBRK,
STEPBYSTEP,
} debugLevel_t;
typedef struct m6502_s {
uint8_t A; // Accumulator
uint8_t X; // X index register
@ -55,6 +63,7 @@ typedef struct m6502_s {
uint16_t PC; // Program Counter
uint8_t SP; // Stack Pointer ( stack addr = 0x01 + sp )
unsigned clk; // Clock Counter
debugLevel_t dbgLevel; // 0: No Debug, 1: Disassembly Only, 2: Run till BRK, 3: StepByStep
union {
unsigned int IF; // interrut flag
@ -63,14 +72,26 @@ typedef struct m6502_s {
} m6502_t;
typedef struct disassembly_s {
char codeAddr[5]; // 4 digits + \0
char hex[4 * 3 + 1]; // max 4 bytes * (2 digits + 1 space) + \0
char * pHex;
char inst[6 + 1]; // 3 char (unknown instr? -- give it 6 chars) + \0
char addr[4 + 2 + 1 + 1 + 1]; // 4 digits + 2 brackets + 1 comma + 1 index + \0
char comment[256]; // to be able to add some comments
} disassembly_t;
extern m6502_t m6502;
extern uint8_t RAM[ 64 * 1024 ];
extern double mips;
extern double mhz;
extern const unsigned int fps;
extern void tst6502();
extern void m6502_Reset();
extern void m6502_Run();
extern void kbdInput ( uint8_t code );
#endif /* __6502_H__ */

View File

@ -75,11 +75,12 @@ INLINE uint8_t ioRead( uint16_t addr ) {
// printf("mmio read:%04X\n", addr);
switch (addr) {
case io_KBD:
// if ( RAM[io_KBD] > 0x7F ) printf("io_KBD:%04X\n", addr);
return RAM[io_KBD];
case io_KBDSTRB:
// TODO: This is very slow!
dbgPrintf("io_KBDSTRB\n");
// printf("io_KBDSTRB\n");
return RAM[io_KBD] &= 0x7F;
default:
@ -88,7 +89,33 @@ INLINE uint8_t ioRead( uint16_t addr ) {
return 0;
}
INLINE void ioWrite( uint16_t addr ) {
void kbdInput ( uint8_t code ) {
// printf("kbdInput: %02X ('%c')\n", code, isprint(code) ? code : ' ');
switch ( code ) {
// case '\n':
// code = 0x0D;
// break;
//
case 0x7F: // BackSlash
code = 0x08;
break;
default:
break;
}
code |= 0x80;
while ( RAM[io_KBD] > 0x7F ) {
usleep(10);
}
RAM[io_KBD] = code;
}
INLINE void ioWrite( uint16_t addr, uint8_t val ) {
// printf("mmio:%04X\n", addr);
switch (addr) {
case io_KBD:
@ -133,7 +160,7 @@ INLINE uint8_t memread( uint16_t addr ) {
// }
if ( (addr >= 0xC000) && (addr < 0xD000) ) {
ioRead(addr);
return ioRead(addr);
}
return RAM[ addr ];
@ -195,7 +222,7 @@ static void memwrite( uint16_t addr, uint8_t byte ) {
increase pc by one
**/
INLINE uint8_t fetch() {
dbgPrintf("%02X ", RAM[m6502.PC]);
disHexB( disassembly.pHex, RAM[m6502.PC] );
return memread( m6502.PC++ );
}
@ -204,9 +231,9 @@ INLINE uint8_t fetch() {
increase pc by one
**/
INLINE uint16_t fetch16() {
dbgPrintf("%04X ", memread16(m6502.PC));
uint16_t word = memread16( m6502.PC );
m6502.PC += 2;
disHexW( disassembly.pHex, word );
return word;
}
@ -216,6 +243,7 @@ INLINE uint16_t fetch16() {
**/
INLINE uint16_t addr_abs() {
dbgPrintf("abs:%04X(%02X) ", *((uint16_t*)&RAM[m6502.PC]), RAM[*((uint16_t*)&RAM[m6502.PC])]);
disPrintf(disassembly.addr, "$%04X", memread16(m6502.PC))
return fetch16();
}
INLINE uint8_t src_abs() {
@ -227,12 +255,15 @@ INLINE uint8_t * dest_abs() {
INLINE int8_t rel_addr() {
disPrintf(disassembly.addr, "$%04X", m6502.PC + 1 + (int)memread8(m6502.PC))
return fetch();
}
INLINE uint16_t abs_addr() {
disPrintf(disassembly.addr, "$%04X", memread16(m6502.PC))
return fetch16();
}
INLINE uint16_t ind_addr() {
disPrintf(disassembly.addr, "($%04X)", memread16(m6502.PC))
return memread16( fetch16() );
}
@ -242,6 +273,7 @@ INLINE uint16_t ind_addr() {
**/
INLINE uint16_t addr_abs_X() {
dbgPrintf("abs,X:%04X(%02X) ", *((uint16_t*)&RAM[m6502.PC]) + m6502.X, RAM[*((uint16_t*)&RAM[m6502.PC]) + m6502.X]);
disPrintf(disassembly.addr, "$%04X,X", memread16(m6502.PC))
return fetch16() + m6502.X;
}
INLINE uint8_t src_abs_X() {
@ -258,6 +290,7 @@ INLINE uint8_t * dest_abs_X() {
**/
INLINE uint16_t addr_abs_Y() {
dbgPrintf("abs,Y:%04X(%02X) ", *((uint16_t*)&RAM[m6502.PC]) + m6502.Y, RAM[*((uint16_t*)&RAM[m6502.PC]) + m6502.Y]);
disPrintf(disassembly.addr, "$%04X,Y", memread16(m6502.PC))
return abs_addr() + m6502.Y;
}
INLINE uint8_t src_abs_Y() {
@ -268,6 +301,7 @@ INLINE uint8_t * dest_abs_Y() {
}
INLINE uint16_t imm() {
disPrintf(disassembly.addr, "#$%02X", memread8(m6502.PC))
return fetch();
}
@ -278,6 +312,7 @@ INLINE uint16_t imm() {
**/
INLINE uint8_t addr_zp() {
dbgPrintf("zp:%02X(%02X) ", RAM[m6502.PC], RAM[ RAM[m6502.PC]] );
disPrintf(disassembly.addr, "$%02X", memread8(m6502.PC))
return fetch();
}
INLINE uint8_t src_zp() {
@ -292,6 +327,7 @@ INLINE uint8_t * dest_zp() {
**/
INLINE uint16_t addr_zp_ind( uint8_t addr ) {
dbgPrintf("zpi:%02X:%04X(%02X) ", RAM[m6502.PC], *((uint16_t*)&RAM[m6502.PC]), RAM[*((uint16_t*)&RAM[m6502.PC])]);
disPrintf(disassembly.addr, "($%02X)", memread8(m6502.PC))
return memread16(addr);
}
@ -302,7 +338,8 @@ INLINE uint16_t addr_zp_ind( uint8_t addr ) {
**/
INLINE uint16_t addr_X_ind() {
dbgPrintf("zpXi:%02X:%04X(%02X) ", RAM[m6502.PC], *((uint16_t*)&RAM[m6502.PC]) + m6502.X, RAM[*((uint16_t*)&RAM[m6502.PC]) + m6502.X]);
return addr_zp_ind( addr_zp() + m6502.X );
disPrintf(disassembly.addr, "($%02X,X)", memread8(m6502.PC))
return addr_zp_ind( fetch() + m6502.X );
}
INLINE uint8_t src_X_ind() {
return memread8( addr_X_ind() );
@ -319,7 +356,8 @@ INLINE uint8_t * dest_X_ind() {
INLINE uint16_t addr_ind_Y() {
// uint8_t a = fetch();
// dbgPrintf("addr_ind_Y: %04X + %02X = %04X ", addr_zpg_ind( a ), m6502.Y, addr_zpg_ind( a ) + m6502.Y);
return addr_zp_ind( addr_zp() ) + m6502.Y;
disPrintf(disassembly.addr, "($%02X),Y", memread8(m6502.PC))
return addr_zp_ind( fetch() ) + m6502.Y;
}
INLINE uint8_t src_ind_Y() {
return memread8( addr_ind_Y() );
@ -340,7 +378,8 @@ INLINE uint8_t * dest_ind_Y() {
effective address is address incremented by X without carry **
**/
INLINE uint8_t addr_zp_X() {
return addr_zp() + m6502.X;
disPrintf(disassembly.addr, "$%02X,X", memread8(m6502.PC))
return fetch() + m6502.X;
}
INLINE uint8_t src_zp_X() {
return memread_zp(addr_zp_X());
@ -355,7 +394,8 @@ INLINE uint8_t * dest_zp_X() {
effective address is address incremented by Y without carry **
**/
INLINE uint8_t addr_zp_Y() {
return addr_zp() + m6502.Y;
disPrintf(disassembly.addr, "$%02X,Y", memread8(m6502.PC))
return fetch() + m6502.Y;
}
INLINE uint8_t src_zp_Y() {
return memread_zp(addr_zp_Y());

View File

@ -2,6 +2,7 @@
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="System colors introduced in macOS 10.14" minToolsVersion="10.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@ -709,25 +710,25 @@
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" mirrorLayoutDirectionWhenInternationalizing="never" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iIF-Q5-Onc">
<rect key="frame" x="0.0" y="0.0" width="584" height="400"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" enabled="NO" allowsUndo="NO" sendsActionOnEndEditing="YES" state="on" baseWritingDirection="leftToRight" drawsBackground="YES" id="cIa-Sd-4OZ">
<rect key="frame" x="0.0" y="0.0" width="592" height="400"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" enabled="NO" allowsUndo="NO" sendsActionOnEndEditing="YES" state="on" baseWritingDirection="leftToRight" title="Display Background" drawsBackground="YES" id="cIa-Sd-4OZ">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" red="0.12549019610000001" green="0.18039215689999999" blue="0.12549019610000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" red="0.078431372549019607" green="0.10980392156862745" blue="0.078431372549019607" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.078431372549019607" green="0.10980392156862745" blue="0.078431372549019607" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<allowedInputSourceLocales>
<string>NSAllRomanInputSourcesLocaleIdentifier</string>
</allowedInputSourceLocales>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" mirrorLayoutDirectionWhenInternationalizing="never" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SEL-hl-0c0">
<rect key="frame" x="6" y="8" width="572" height="384"/>
<rect key="frame" x="14" y="8" width="572" height="384"/>
<constraints>
<constraint firstAttribute="width" constant="568" id="uez-Mi-0Sh"/>
<constraint firstAttribute="height" constant="384" id="zl6-au-oZj"/>
</constraints>
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" allowsUndo="NO" sendsActionOnEndEditing="YES" state="on" baseWritingDirection="leftToRight" alignment="center" id="pIk-RC-s5g">
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" allowsUndo="NO" sendsActionOnEndEditing="YES" state="on" baseWritingDirection="leftToRight" id="pIk-RC-s5g">
<font key="font" size="16" name="PrintChar21"/>
<mutableString key="title">1234567890123456789012345678901234567890
<string key="title">1234567890123456789012345678901234567890
@@@@@@@@@1@@@@@@@@@2@@@@@@@@@3@@@@@@@@@4
@@@@@@@@@@@@@@@@@@@3@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@4@@@@@@@@@@@@@@@@@@@@
@ -750,16 +751,16 @@
@@@@@@@@@@@@@@@@@@21@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@22@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@23@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@24@@@@@@@@@@@@@@@@@@@@</mutableString>
@@@@@@@@@@@@@@@@@@24@@@@@@@@@@@@@@@@@@@@</string>
<color key="textColor" name="systemGreenColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="selectedTextBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="alternatingContentBackgroundColor" catalog="System" colorSpace="catalog"/>
<allowedInputSourceLocales>
<string>NSAllRomanInputSourcesLocaleIdentifier</string>
</allowedInputSourceLocales>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="mfd-12-bcR">
<rect key="frame" x="586" y="362" width="90" height="32"/>
<rect key="frame" x="594" y="362" width="82" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="t2i-0h-wau"/>
</constraints>
@ -772,7 +773,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rR3-9T-NFu">
<rect key="frame" x="586" y="331" width="90" height="32"/>
<rect key="frame" x="594" y="331" width="82" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="sbX-nh-SV3"/>
</constraints>
@ -795,6 +796,10 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<customView hidden="YES" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LlM-EV-ruZ" customClass="HiRes" customModule="A2Mac" customModuleProvider="target">
<rect key="frame" x="16" y="8" width="568" height="384"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="mfd-12-bcR" secondAttribute="trailing" constant="10" id="3NC-0i-OPC"/>
@ -805,7 +810,7 @@
<constraint firstItem="rR3-9T-NFu" firstAttribute="leading" secondItem="iIF-Q5-Onc" secondAttribute="trailing" constant="8" id="ON4-IE-HmP"/>
<constraint firstAttribute="trailing" secondItem="FZk-VW-alq" secondAttribute="trailing" constant="10" id="Q0s-uC-GPT"/>
<constraint firstItem="SEL-hl-0c0" firstAttribute="bottom" secondItem="iIF-Q5-Onc" secondAttribute="bottom" constant="-8" id="Q2B-a3-gBp"/>
<constraint firstItem="SEL-hl-0c0" firstAttribute="leading" secondItem="iIF-Q5-Onc" secondAttribute="leading" constant="8" id="QGx-a9-RR9"/>
<constraint firstItem="SEL-hl-0c0" firstAttribute="leading" secondItem="iIF-Q5-Onc" secondAttribute="leading" constant="16" id="QGx-a9-RR9"/>
<constraint firstItem="SEL-hl-0c0" firstAttribute="top" secondItem="iIF-Q5-Onc" secondAttribute="top" constant="8" id="aWz-Ad-PIM"/>
<constraint firstAttribute="bottom" secondItem="iIF-Q5-Onc" secondAttribute="bottom" id="acb-Dy-fu5"/>
<constraint firstItem="SEL-hl-0c0" firstAttribute="trailing" secondItem="iIF-Q5-Onc" secondAttribute="trailing" constant="-8" id="cmY-Vb-ckJ"/>
@ -815,6 +820,7 @@
</constraints>
</view>
<connections>
<outlet property="HiRes" destination="LlM-EV-ruZ" id="E60-pA-HM1"/>
<outlet property="display" destination="pIk-RC-s5g" id="Hvd-DI-h6z"/>
<outlet property="displayField" destination="SEL-hl-0c0" id="4Pc-hG-qQf"/>
<outlet property="speedometer" destination="FBZ-dh-6Fs" id="L0v-RY-xwB"/>

186
A2Mac/HiRes.swift Normal file
View File

@ -0,0 +1,186 @@
//
// HiRes.swift
// A2Mac
//
// Created by Tamas Rudnai on 9/19/19.
// Copyright © 2019 GameAlloy. All rights reserved.
//
//import Foundation
import AppKit
class HiRes: NSView {
static let PageSize = 0x2000
static let Page1Addr = 0x2000
static let Page2Addr = 0x4000
static let PixelWidth = 280
static let PixelMixedHeight = 160
static let PixelHeight = 192
static let LineBlocks = 40
let HiResBufferPointer = UnsafeRawBufferPointer(start: &RAM + Page1Addr, count: PageSize * 2)
// holds the starting addresses for each lines minus the screen page starting address
var HiResLineAddrTbl = [UInt16](repeating: 0, count: PixelHeight)
func initHiResLineAddresses() {
var i = 0
for x : UInt16 in stride(from: 0, through: 0x50, by: 0x28) {
for y : UInt16 in stride(from: 0, through: 0x380, by: 0x80) {
for z : UInt16 in stride(from: 0, through: 0x1C00, by: 0x400) {
HiResLineAddrTbl[i] = x + y + z
i += 1
}
}
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initHiResLineAddresses()
let scaleSizeW = Double((frame.size).width) / Double(HiRes.PixelWidth)
let scaleSizeH = Double((frame.size).height) / Double(HiRes.PixelHeight)
scaleUnitSquare(to: NSSize(width: scaleSizeW, height: scaleSizeH))
}
override init(frame: CGRect) {
super.init(frame: frame)
}
static func createBitmapContext(pixelsWide: Int, _ pixelsHigh: Int) -> CGContext? {
let bytesPerPixel = 4
let bytesPerRow = bytesPerPixel * pixelsWide
let bitsPerComponent = 8
let byteCount = (bytesPerRow * pixelsHigh)
guard let colorSpace = CGColorSpace(name: CGColorSpace.linearSRGB) else { return nil }
let pixels = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: byteCount)
let bitmapInfo = CGImageAlphaInfo.premultipliedFirst.rawValue | CGBitmapInfo.byteOrder32Little.rawValue
let context = CGContext(data: pixels, width: pixelsWide, height: pixelsHigh, bitsPerComponent: bitsPerComponent, bytesPerRow: bytesPerRow, space: colorSpace, bitmapInfo: bitmapInfo)
return context
}
// override func draw(_ rect: CGRect) {
// let width = 200
// let height = 300
// let boundingBox = CGRect(x: 0, y: 0, width: CGFloat(width), height: CGFloat(height))
// let context = createBitmapContext(pixelsWide: width, height)
//
// let data = context?.data
// var currentPixel: [UInt32] = unsafeBitCast(data, to: [UInt32].self)
//
// var n = 0
// for _ in 0..<height {
// for _ in 0..<width {
// currentPixel[n] = 0
// n += 1
// }
// }
//
// guard let image = context?.makeImage() else { return }
// context?.draw(image, in: boundingBox)
// }
private var currentContext : CGContext? {
get {
if #available(OSX 10.10, *) {
return NSGraphicsContext.current?.cgContext
} else if let contextPointer = NSGraphicsContext.current?.graphicsPort {
let context: CGContext = Unmanaged.fromOpaque(contextPointer).takeUnretainedValue()
return context
}
return nil
}
}
static let byteCount = (HiRes.PixelWidth * HiRes.PixelHeight * 4)
static let context = createBitmapContext(pixelsWide: HiRes.PixelWidth, HiRes.PixelHeight)
static let pixels = UnsafeMutableRawBufferPointer(start: context?.data, count: byteCount) // UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: byteCount)
let R = 2
let G = 1
let B = 0
let A = 3
var shadowScreen = [Int](repeating: 1, count: PageSize)
override func draw(_ rect: CGRect) {
var pixelAddr = 0
var minX = 0
var minY = 0
var maxX = 0
var maxY = 0
var x = 0
var y = 0
for lineAddr in HiResLineAddrTbl {
for blockAddr in 0..<UInt16(HiRes.LineBlocks) {
let block = Int(HiResBufferPointer[ Int(lineAddr + blockAddr) ])
let screenIdx = y * HiRes.LineBlocks + x
if ( shadowScreen[ screenIdx ] != block ) {
shadowScreen[ screenIdx ] = block
for bit in stride(from: 0, through: 6, by: 1) {
let bitMask = 1 << bit
if (block & bitMask) == 0 {
HiRes.pixels[pixelAddr + R] = 0x00;
HiRes.pixels[pixelAddr + G] = 0x00;
HiRes.pixels[pixelAddr + B] = 0x00;
HiRes.pixels[pixelAddr + A] = 0x00;
}
else { // 28CD41
HiRes.pixels[pixelAddr + R] = 0x08;
HiRes.pixels[pixelAddr + G] = 0xA2;
HiRes.pixels[pixelAddr + B] = 0x12;
HiRes.pixels[pixelAddr + A] = 0xFF;
}
if ( minX == 0 ) { minX = x }
if ( minY == 0 ) { minY = y }
if ( maxX < x ) { maxX = x }
if ( maxY < y ) { maxY = y }
pixelAddr += 4
x += 1
}
}
else {
pixelAddr += 4 * 7
x += 7
}
}
y += 1
x = 0
}
guard let image = HiRes.context?.makeImage() else { return }
if let currentContext: CGContext = currentContext {
// UIImagePNGRepresentation(UIImage(CGImage:image!))?.writeToFile("/Users/admin/Desktop/aaaaa.png", atomically: true)
// if ( maxX > minX ) && ( maxY > minY ) {
let boundingBox = CGRect(x: 0, y: 0, width: CGFloat(HiRes.PixelWidth), height: CGFloat(HiRes.PixelHeight))
// let boundingBox = CGRect(x: minX, y: minY, width: maxX - minX, height: maxY - minY)
currentContext.draw (image, in: boundingBox)
// }
}
}
}

View File

@ -13,6 +13,7 @@ class ViewController: NSViewController {
@IBOutlet weak var displayField: NSTextField!
@IBOutlet weak var display: NSTextFieldCell!
@IBOutlet weak var speedometer: NSTextFieldCell!
@IBOutlet weak var HiRes: HiRes!
// static let charConvStr : String =
// "@🄰🄱🄲🄳🄴🄵🄶🄷🄸🄹🄺🄻🄼🄽🄾🄿🅀🅁🅂🅃🅄🅅🅆🅇🅈🅉[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" +
@ -35,16 +36,19 @@ class ViewController: NSViewController {
static let charConvStrFlashOff : String =
"\u{E140}\u{E141}\u{E142}\u{E143}\u{E144}\u{E145}\u{E146}\u{E147}\u{E148}\u{E149}\u{E14A}\u{E14B}\u{E14C}\u{E14D}\u{E14E}\u{E14F}\u{E150}\u{E151}\u{E152}\u{E153}\u{E154}\u{E155}\u{E156}\u{E157}\u{E158}\u{E159}\u{E15A}\u{E15B}\u{E15C}\u{E15D}\u{E15E}\u{E15F}\u{E120}\u{E121}\u{E122}\u{E123}\u{E124}\u{E125}\u{E126}\u{E127}\u{E128}\u{E129}\u{E12A}\u{E12B}\u{E12C}\u{E12D}\u{E12E}\u{E12F}\u{E130}\u{E131}\u{E132}\u{E133}\u{E134}\u{E135}\u{E136}\u{E137}\u{E138}\u{E139}\u{E13A}\u{E13B}\u{E13C}\u{E13D}\u{E13E}\u{E13F}" +
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" + // FL
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\u{E0A0}!\"#$%&'()*+,-./0123456789:;<=>?" +
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" +
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~?"
static let charConvStrFlashOn : String =
"\u{E140}\u{E141}\u{E142}\u{E143}\u{E144}\u{E145}\u{E146}\u{E147}\u{E148}\u{E149}\u{E14A}\u{E14B}\u{E14C}\u{E14D}\u{E14E}\u{E14F}\u{E150}\u{E151}\u{E152}\u{E153}\u{E154}\u{E155}\u{E156}\u{E157}\u{E158}\u{E159}\u{E15A}\u{E15B}\u{E15C}\u{E15D}\u{E15E}\u{E15F}\u{E120}\u{E121}\u{E122}\u{E123}\u{E124}\u{E125}\u{E126}\u{E127}\u{E128}\u{E129}\u{E12A}\u{E12B}\u{E12C}\u{E12D}\u{E12E}\u{E12F}\u{E130}\u{E131}\u{E132}\u{E133}\u{E134}\u{E135}\u{E136}\u{E137}\u{E138}\u{E139}\u{E13A}\u{E13B}\u{E13C}\u{E13D}\u{E13E}\u{E13F}" +
"\u{E140}\u{E141}\u{E142}\u{E143}\u{E144}\u{E145}\u{E146}\u{E147}\u{E148}\u{E149}\u{E14A}\u{E14B}\u{E14C}\u{E14D}\u{E14E}\u{E14F}\u{E150}\u{E151}\u{E152}\u{E153}\u{E154}\u{E155}\u{E156}\u{E157}\u{E158}\u{E159}\u{E15A}\u{E15B}\u{E15C}\u{E15D}\u{E15E}\u{E15F}\u{E120}\u{E121}\u{E122}\u{E123}\u{E124}\u{E125}\u{E126}\u{E127}\u{E128}\u{E129}\u{E12A}\u{E12B}\u{E12C}\u{E12D}\u{E12E}\u{E12F}\u{E130}\u{E131}\u{E132}\u{E133}\u{E134}\u{E135}\u{E136}\u{E137}\u{E138}\u{E139}\u{E13A}\u{E13B}\u{E13C}\u{E13D}\u{E13E}\u{E13F}" +
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\u{E0A0}!\"#$%&'()*+,-./0123456789:;<=>?" +
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&'()*+,-./0123456789:;<=>?" +
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~?"
static var charConvTbl = Array( charConvStrFlashOff )
static let charConvTblFlashOn = Array( charConvStrFlashOn )
static let charConvTblFlashOff = Array( charConvStrFlashOff )
static var charConvTbl = charConvTblFlashOn
let textLineOfs : [Int] = [
0x000, 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x028, 0x0A8, 0x128, 0x1A8,
@ -87,7 +91,14 @@ class ViewController: NSViewController {
}
// AppleScript Keycodes
let leftArrowKey = 123
let rightArrowKey = 124
let upArrowKey = 126
let downArrowKey = 125
override func keyDown(with event: NSEvent) {
// print("KBD Event")
// switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
// case [.command] where event.characters == "l",
// [.command, .shift] where event.characters == "l":
@ -100,30 +111,30 @@ class ViewController: NSViewController {
#if FUNCTIONTEST
#else
if let chars = event.characters {
let char = chars.uppercased()[chars.startIndex]
if let code = char.asciiValue {
var A2code = code | 0x80
switch ( code ) {
case 13:
A2code = 141
break
default:
break
let keyCode = Int(event.keyCode)
switch keyCode {
case leftArrowKey:
kbdInput(0x08)
case rightArrowKey:
kbdInput(0x15)
case leftArrowKey:
kbdInput(0x0B)
case rightArrowKey:
kbdInput(0x0A)
default:
// print("keycode: %d", keyCode)
if let chars = event.characters {
let char = chars.uppercased()[chars.startIndex]
if let ascii = char.asciiValue {
kbdInput(ascii)
}
// print("keycode: \(code) --> \(A2code)")
let kbdPointer = UnsafeMutableRawBufferPointer(start: &RAM + 0xC000, count: 1)
kbdPointer[0] = A2code
}
}
#endif
}
override func flagsChanged(with event: NSEvent) {
// override func flagsChanged(with event: NSEvent) {
// switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
// case [.shift]:
// print("shift key is pressed")
@ -158,7 +169,7 @@ class ViewController: NSViewController {
// default:
// print("no modifier keys are pressed")
// }
}
// }
static let textBaseAddr = 0x400
@ -194,7 +205,7 @@ class ViewController: NSViewController {
}
DispatchQueue.main.async {
self.display.stringValue = txt;
self.display.stringValue = txt
self.speedometer.stringValue = String(format: "%0.3lf MHz", mhz);
}
}
@ -212,11 +223,11 @@ class ViewController: NSViewController {
frameCnt += 1
if ( frameCnt == 15 ) {
// flashingSpace = blockChar
ViewController.charConvTbl = Array( ViewController.charConvStrFlashOn )
ViewController.charConvTbl = ViewController.charConvTblFlashOn
}
else if ( frameCnt >= 30 ) {
else if ( frameCnt >= fps ) {
// flashingSpace = spaceChar
ViewController.charConvTbl = Array( ViewController.charConvStrFlashOff )
ViewController.charConvTbl = ViewController.charConvTblFlashOff
frameCnt = 0
}
@ -260,10 +271,18 @@ class ViewController: NSViewController {
// txtArr[ textLines * (textCols+1) + textCols ] = "\0"
txt = String(txtArr)
DispatchQueue.main.async {
self.display.stringValue = txt;
self.speedometer.stringValue = String(format: "%0.3lf MHz", mhz);
self.display.stringValue = txt
if ( mhz < 10 ) {
self.speedometer.stringValue = String(format: "%0.3lf MHz", mhz);
}
else {
self.speedometer.stringValue = String(format: "%.0lf MHz", mhz);
}
// self.HiRes.setNeedsDisplay(self.HiRes.frame)
// self.HiRes.setNeedsDisplay(CGRect(x: 0, y: 191-50, width: 50, height: 50))
// self.HiRes.needsDisplay = true
}
}
@ -278,16 +297,21 @@ class ViewController: NSViewController {
// }
let upd = RepeatingTimer(timeInterval: 1/30)
let upd = RepeatingTimer(timeInterval: 1/Double(fps))
override func viewDidLoad() {
super.viewDidLoad()
NSEvent.addLocalMonitorForEvents(matching: .flagsChanged) {
self.flagsChanged(with: $0)
return $0
}
self.displayField.scaleUnitSquare(to: NSSize(width: 1, height: 1))
// NSEvent.removeMonitor(NSEvent.EventType.flagsChanged)
// NSEvent.addLocalMonitorForEvents(matching: .flagsChanged) {
// self.flagsChanged(with: $0)
// return $0
// }
// NSEvent.removeMonitor(NSEvent.EventType.keyDown)
NSEvent.addLocalMonitorForEvents(matching: .keyDown) {
// print("keyDown event")
self.keyDown(with: $0)
return $0
}
@ -295,7 +319,7 @@ class ViewController: NSViewController {
displayField.maximumNumberOfLines = textLines
displayField.preferredMaxLayoutWidth = displayField.frame.width
// DispatchQueue.main.asyncAfter(deadline: .now() + 1/30, execute: {
// DispatchQueue.main.asyncAfter(deadline: .now() + 1/fps, execute: {
// self.update()
// })

78
A2Mac/disassembler.h Normal file
View File

@ -0,0 +1,78 @@
//
// disassembler.h
// A2Mac
//
// Created by Tamas Rudnai on 9/21/19.
// Copyright © 2019 GameAlloy. All rights reserved.
//
#ifndef disassembler_h
#define disassembler_h
#define NO_DISASSEMBLER
#ifdef DISASSEMBLER
#define disHexB( to, b ) \
if ( m6502.dbgLevel >= DISASSEMBLY ) { \
snprintf((to), 4, "%02X ", (b)); \
to += 3; \
}
#define disHexW( to, w ) \
if ( m6502.dbgLevel >= DISASSEMBLY ) { \
snprintf((to), 6, "%04X ", (w)); \
to += 5; \
}
#define disPuts( to, from ) { \
char * s = from; \
if ( m6502.dbgLevel >= DISASSEMBLY ) { \
while ( (*(to)++ = *s++) ); \
} \
}
#define disPrintf( to, fmt, args... ) { \
if ( m6502.dbgLevel >= DISASSEMBLY ) { \
snprintf( (to), sizeof(to), fmt, ##args ); \
} \
}
#define disNewInstruction() { \
if ( m6502.dbgLevel >= DISASSEMBLY ) { \
disassembly.pHex = disassembly.hex; \
*disassembly.hex = '\0'; \
*disassembly.inst = '\0'; \
*disassembly.addr = '\0'; \
*disassembly.comment = '\0'; \
snprintf(disassembly.codeAddr, 5, "%04X ", m6502.PC); \
} \
}
INLINE void printDisassembly() {
if ( m6502.dbgLevel >= DISASSEMBLY ) {
printf("%s: %-14s%-6s%-14s%s\n",
disassembly.codeAddr,
disassembly.hex,
disassembly.inst,
disassembly.addr,
disassembly.comment
);
}
}
#else // DISASSEMBLER
#define disHexB( to, b )
#define disHexW( to, w )
#define disPuts( to, from )
#define disPrintf( to, fmt, args... )
#define disNewInstruction()
#define printDisassembly()
#endif // DISASSEMBLER
#endif /* disassembler_h */

View File

@ -31,6 +31,7 @@
**/
INLINE void ADC( uint8_t src ) {
dbgPrintf("ADC(%02X) ", src);
disPrintf(disassembly.inst, "ADC");
uint16_t tmp;
@ -95,6 +96,7 @@ INLINE void ADC( uint8_t src ) {
**/
INLINE void SBC( uint8_t src ) {
dbgPrintf("SBC(%02X) ", src);
disPrintf(disassembly.inst, "SBC");
// ADC( ~src );
uint16_t tmp;

View File

@ -31,6 +31,7 @@ INLINE void BRA( int8_t reladdr ) {
**/
INLINE void BCC( int8_t reladdr ) {
dbgPrintf("BCC ");
disPrintf(disassembly.inst, "BCC");
if ( m6502.C == 0 ) {
BRA( reladdr );
}
@ -51,6 +52,7 @@ INLINE void BCC( int8_t reladdr ) {
**/
INLINE void BCS( int8_t reladdr ) {
dbgPrintf("BCS ");
disPrintf(disassembly.inst, "RCS");
if ( m6502.C == 1 ) {
BRA( reladdr );
}
@ -71,6 +73,7 @@ INLINE void BCS( int8_t reladdr ) {
**/
INLINE void BNE( int8_t reladdr ) {
dbgPrintf("BNE ");
disPrintf(disassembly.inst, "BNE");
if ( m6502.Z == 0 ) {
BRA( reladdr );
}
@ -91,6 +94,7 @@ INLINE void BNE( int8_t reladdr ) {
**/
INLINE void BEQ( int8_t reladdr ) {
dbgPrintf("BEQ ");
disPrintf(disassembly.inst, "BEQ");
if ( m6502.Z == 1 ) {
BRA( reladdr );
}
@ -111,6 +115,7 @@ INLINE void BEQ( int8_t reladdr ) {
**/
INLINE void BPL( int8_t reladdr ) {
dbgPrintf("BPL ");
disPrintf(disassembly.inst, "BPL");
if ( m6502.N == 0 ) {
BRA( reladdr );
}
@ -131,6 +136,7 @@ INLINE void BPL( int8_t reladdr ) {
**/
INLINE void BMI( int8_t reladdr ) {
dbgPrintf("BMI ");
disPrintf(disassembly.inst, "BMI");
if ( m6502.N == 1 ) {
BRA( reladdr );
}
@ -151,6 +157,7 @@ INLINE void BMI( int8_t reladdr ) {
**/
INLINE void BVC( int8_t reladdr ) {
dbgPrintf("BVC ");
disPrintf(disassembly.inst, "BVC");
if ( m6502.V == 0 ) {
BRA( reladdr );
}
@ -171,6 +178,7 @@ INLINE void BVC( int8_t reladdr ) {
**/
INLINE void BVS( int8_t reladdr ) {
dbgPrintf("BVS ");
disPrintf(disassembly.inst, "BVS");
if ( m6502.V == 1 ) {
BRA( reladdr );
}

View File

@ -23,6 +23,7 @@
**/
INLINE void JMP( uint16_t addr ) {
dbgPrintf("JMP %04X ", addr);
disPrintf(disassembly.inst, "JMP");
#ifdef DEBUG
if ( addr == m6502.PC - 3 ) {
dbgPrintf("Infinite Loop at %04X!\n", m6502.PC);
@ -44,8 +45,9 @@ INLINE void JMP( uint16_t addr ) {
**/
INLINE void JSR( uint16_t addr ) {
dbgPrintf("JSR ");
disPrintf(disassembly.inst, "JSR");
PUSH_addr(m6502.PC -1);
JMP( addr );
m6502.PC = addr;
}
/**
@ -60,7 +62,8 @@ INLINE void JSR( uint16_t addr ) {
**/
INLINE void RTS() {
dbgPrintf("RTS ");
JMP( POP_addr() +1);
disPrintf(disassembly.inst, "RTS");
m6502.PC = POP_addr() +1;
}
/**
@ -75,9 +78,10 @@ INLINE void RTS() {
**/
INLINE void RTI() {
dbgPrintf("RTI ");
disPrintf(disassembly.inst, "RTI");
m6502.SR = POP();
// m6502.I = 0;
JMP( POP_addr() );
m6502.PC = POP_addr();
}

View File

@ -26,6 +26,7 @@
**/
INLINE void BIT( uint8_t src ) {
dbgPrintf("BIT(%02X) ", src);
disPrintf(disassembly.inst, "BIT");
set_flags_NV(src);
set_flags_Z(m6502.A & src);
}
@ -49,6 +50,7 @@ INLINE void BIT( uint8_t src ) {
**/
INLINE void CMP( uint8_t src ) {
dbgPrintf("CMP(%02X) ", src);
disPrintf(disassembly.inst, "CMP");
set_flags_NZC( (int16_t)m6502.A - src );
}
@ -66,6 +68,7 @@ INLINE void CMP( uint8_t src ) {
**/
INLINE void CPX( uint8_t src ) {
dbgPrintf("CPX(%02X) ", src);
disPrintf(disassembly.inst, "CPX");
set_flags_NZC( (int16_t)m6502.X - src );
}
@ -83,6 +86,7 @@ INLINE void CPX( uint8_t src ) {
**/
INLINE void CPY( uint8_t src ) {
dbgPrintf("CPY(%02X) ", src);
disPrintf(disassembly.inst, "CPY");
set_flags_NZC( (int16_t)m6502.Y - src );
}

View File

@ -25,6 +25,7 @@
**/
INLINE void INC( uint8_t * dst ) {
dbgPrintf("INC %02X -> ", *dst);
disPrintf(disassembly.inst, "INC");
set_flags_NZ( ++(*dst) );
dbgPrintf("%02X ", *dst);
}
@ -41,6 +42,7 @@ INLINE void INC( uint8_t * dst ) {
**/
INLINE void INX() {
dbgPrintf("INX %02X -> ", m6502.X);
disPrintf(disassembly.inst, "INX");
set_flags_NZ( ++m6502.X );
dbgPrintf("%02X ", m6502.X);
}
@ -57,6 +59,7 @@ INLINE void INX() {
**/
INLINE void INY() {
dbgPrintf("INY %02X -> ", m6502.Y);
disPrintf(disassembly.inst, "INY");
set_flags_NZ( ++m6502.Y );
dbgPrintf("%02X ", m6502.Y);
}
@ -76,6 +79,7 @@ INLINE void INY() {
**/
INLINE void DEC( uint8_t * dst ) {
dbgPrintf("DEC %02X -> ", *dst);
disPrintf(disassembly.inst, "DEC");
set_flags_NZ( --(*dst) );
dbgPrintf("%02X ", *dst);
}
@ -92,6 +96,7 @@ INLINE void DEC( uint8_t * dst ) {
**/
INLINE void DEX() {
dbgPrintf("DEX %02X -> ", m6502.X);
disPrintf(disassembly.inst, "DEX");
set_flags_NZ( --m6502.X );
dbgPrintf("%02X ", m6502.X);
}
@ -108,6 +113,7 @@ INLINE void DEX() {
**/
INLINE void DEY() {
dbgPrintf("DEY %02X -> ", m6502.Y);
disPrintf(disassembly.inst, "DEY");
set_flags_NZ( --m6502.Y );
dbgPrintf("%02X ", m6502.Y);
}

View File

@ -31,6 +31,7 @@
**/
INLINE void LDA( uint8_t src ) {
dbgPrintf("LDA(%02X) ", src);
disPrintf(disassembly.inst, "LDA");
set_flags_NZ(m6502.A = src);
}
@ -50,6 +51,7 @@ INLINE void LDA( uint8_t src ) {
**/
INLINE void LDX( uint8_t src ) {
dbgPrintf("LDX(%02X) ", src);
disPrintf(disassembly.inst, "LDX");
set_flags_NZ(m6502.X = src);
}
@ -69,6 +71,7 @@ INLINE void LDX( uint8_t src ) {
**/
INLINE void LDY( uint8_t src ) {
dbgPrintf("LDY(%02X) ", src);
disPrintf(disassembly.inst, "LDY");
set_flags_NZ(m6502.Y = src);
}
@ -153,6 +156,7 @@ INLINE void STR( uint8_t * dst, uint8_t src ) {
**/
INLINE void STA( uint8_t * dst ) {
dbgPrintf("STA ");
disPrintf(disassembly.inst, "STA");
STR(dst, m6502.A);
}
@ -170,6 +174,7 @@ INLINE void STA( uint8_t * dst ) {
**/
INLINE void STX( uint8_t * dst ) {
dbgPrintf("STX ");
disPrintf(disassembly.inst, "STX");
STR(dst, m6502.X);
}
@ -187,6 +192,7 @@ INLINE void STX( uint8_t * dst ) {
**/
INLINE void STY( uint8_t * dst ) {
dbgPrintf("STY ");
disPrintf(disassembly.inst, "STY");
STR(dst, m6502.Y);
}

View File

@ -29,6 +29,7 @@
**/
INLINE void ORA( uint8_t src ) {
dbgPrintf("ORA(%02X) ", src);
disPrintf(disassembly.inst, "ORA");
set_flags_NZ( m6502.A |= src );
}
@ -51,6 +52,7 @@ INLINE void ORA( uint8_t src ) {
**/
INLINE void AND( uint8_t src ) {
dbgPrintf("AND(%02X) ", src);
disPrintf(disassembly.inst, "AND");
set_flags_NZ( m6502.A &= src );
}
@ -73,6 +75,7 @@ INLINE void AND( uint8_t src ) {
**/
INLINE void EOR( uint8_t src ) {
dbgPrintf("EOR(%02X) ", src);
disPrintf(disassembly.inst, "EOR");
set_flags_NZ( m6502.A ^= src );
}

View File

@ -22,6 +22,7 @@
**/
INLINE void BRK() {
dbgPrintf("BRK ");
disPrintf(disassembly.inst, "BRK");
PUSH_addr(m6502.PC +1); // PC +2, however, fetch already incremented it by 1
// B flag should be set before pushing flags onto the stack
m6502.B = 1;
@ -42,6 +43,7 @@ INLINE void BRK() {
**/
INLINE void NOP() {
dbgPrintf("NOP ");
disPrintf(disassembly.inst, "NOP");
}
#endif // __6502_INSTR_MISC_H__

View File

@ -21,6 +21,7 @@
**/
INLINE void CLC() {
dbgPrintf("CLC ");
disPrintf(disassembly.inst, "CLC");
m6502.C = 0;
}
@ -36,6 +37,7 @@ INLINE void CLC() {
**/
INLINE void CLD() {
dbgPrintf("CLD ");
disPrintf(disassembly.inst, "CLD");
m6502.D = 0;
}
@ -51,6 +53,7 @@ INLINE void CLD() {
**/
INLINE void CLI() {
dbgPrintf("CLI ");
disPrintf(disassembly.inst, "CLI");
m6502.I = 0;
}
@ -66,6 +69,7 @@ INLINE void CLI() {
**/
INLINE void CLV() {
dbgPrintf("CLV ");
disPrintf(disassembly.inst, "CLV");
m6502.V = 0;
}
@ -81,6 +85,7 @@ INLINE void CLV() {
**/
INLINE void SEC() {
dbgPrintf("SEC ");
disPrintf(disassembly.inst, "SEC");
m6502.C = 1;
}
@ -96,6 +101,7 @@ INLINE void SEC() {
**/
INLINE void SED() {
dbgPrintf("SED ");
disPrintf(disassembly.inst, "SED");
m6502.D = 1;
}
@ -111,6 +117,7 @@ INLINE void SED() {
**/
INLINE void SEI() {
dbgPrintf("SEI ");
disPrintf(disassembly.inst, "SEI");
m6502.I = 1;
}

View File

@ -26,11 +26,13 @@
**/
INLINE void ASL( uint8_t * dst ) {
dbgPrintf("ASL ");
disPrintf(disassembly.inst, "ASL");
m6502.C = *dst >> 7;
set_flags_NZ( *dst <<= 1 );
}
INLINE void ASLA() {
dbgPrintf("ASL ");
disPrintf(disassembly.inst, "ASL");
m6502.C = m6502.A >> 7;
set_flags_NZ( m6502.A <<= 1 );
}
@ -51,11 +53,13 @@ INLINE void ASLA() {
**/
INLINE void LSR( uint8_t * dst ) {
dbgPrintf("LSR ");
disPrintf(disassembly.inst, "LSR");
m6502.C = *dst & 1;
set_flags_NZ( *dst >>= 1 );
}
INLINE void LSRA() {
dbgPrintf("LSR ");
disPrintf(disassembly.inst, "LSR");
m6502.C = m6502.A & 1;
set_flags_NZ( m6502.A >>= 1 );
}
@ -76,6 +80,7 @@ INLINE void LSRA() {
**/
INLINE void ROL( uint8_t * dst ) {
dbgPrintf("ROL ");
disPrintf(disassembly.inst, "ROL");
uint8_t C = m6502.C;
m6502.C = *dst >> 7;
*dst <<= 1;
@ -83,6 +88,7 @@ INLINE void ROL( uint8_t * dst ) {
}
INLINE void ROLA() {
dbgPrintf("ROL ");
disPrintf(disassembly.inst, "ROL");
uint8_t C = m6502.C;
m6502.C = m6502.A >> 7;
m6502.A <<= 1;
@ -105,6 +111,7 @@ INLINE void ROLA() {
**/
INLINE void ROR( uint8_t * dst ) {
dbgPrintf("ROR ");
disPrintf(disassembly.inst, "ROR");
uint8_t C = m6502.C << 7;
m6502.C = *dst & 1;
*dst >>= 1;
@ -112,6 +119,7 @@ INLINE void ROR( uint8_t * dst ) {
}
INLINE void RORA() {
dbgPrintf("ROR ");
disPrintf(disassembly.inst, "ROR");
uint8_t C = m6502.C << 7;
m6502.C = m6502.A & 1;
m6502.A >>= 1;

View File

@ -42,6 +42,7 @@ INLINE uint16_t POP_addr() {
**/
INLINE void PHA() {
dbgPrintf("PHA %02X ", m6502.A);
disPrintf(disassembly.inst, "PHA");
PUSH( m6502.A );
}
@ -58,6 +59,7 @@ INLINE void PHA() {
INLINE void PLA() {
m6502.A = POP();
dbgPrintf("PLA %02X ", m6502.A);
disPrintf(disassembly.inst, "PLA");
set_flags_NZ( m6502.A );
}
@ -73,6 +75,7 @@ INLINE void PLA() {
**/
INLINE void PHP() {
dbgPrintf("PHP %02X ", m6502.SR);
disPrintf(disassembly.inst, "PHP");
PUSH( m6502.SR ); // res and B flag should be set
}
@ -89,6 +92,7 @@ INLINE void PHP() {
INLINE void PLP() {
m6502.SR = POP() | 0x30; // res and B flag should be set
dbgPrintf("PLP %02X ", m6502.SR);
disPrintf(disassembly.inst, "PLP");
}
#endif // __6502_INSTR_STACK_H__

View File

@ -22,6 +22,7 @@
**/
INLINE void TAX() {
dbgPrintf("TAX(%02X) ", m6502.A);
disPrintf(disassembly.inst, "TAX");
set_flags_NZ(m6502.X = m6502.A);
}
@ -37,6 +38,7 @@ INLINE void TAX() {
**/
INLINE void TXA() {
dbgPrintf("TXA(%02X) ", m6502.X);
disPrintf(disassembly.inst, "TXA");
set_flags_NZ(m6502.A = m6502.X);
}
@ -53,6 +55,7 @@ INLINE void TXA() {
**/
INLINE void TAY() {
dbgPrintf("TAY ");
disPrintf(disassembly.inst, "TAY");
set_flags_NZ(m6502.Y = m6502.A);
}
@ -68,6 +71,7 @@ INLINE void TAY() {
**/
INLINE void TYA() {
dbgPrintf("TYA(%02X) ", m6502.Y);
disPrintf(disassembly.inst, "TYA");
set_flags_NZ(m6502.A = m6502.Y);
}
@ -83,6 +87,7 @@ INLINE void TYA() {
**/
INLINE void TSX() {
dbgPrintf("TSX(%02X) ", m6502.SP);
disPrintf(disassembly.inst, "TSX");
set_flags_NZ(m6502.X = m6502.SP);
}
@ -98,6 +103,7 @@ INLINE void TSX() {
**/
INLINE void TXS() {
dbgPrintf("TXS(%02X) ", m6502.X);
disPrintf(disassembly.inst, "TXS");
m6502.SP = m6502.X;
}