diff --git a/A2Mac.xcodeproj/project.pbxproj b/A2Mac.xcodeproj/project.pbxproj index 3d0eb85..23985ee 100644 --- a/A2Mac.xcodeproj/project.pbxproj +++ b/A2Mac.xcodeproj/project.pbxproj @@ -1410,7 +1410,7 @@ "@executable_path/../Frameworks", ); OTHER_CFLAGS = ( - "-DDISASSEMBLER", + "-D_NO_DISASSEMBLER", "-D_NO_INTERRUPT_CHECK_PER_STEP", "-D_NO_CLK_ABSOLUTE_PRECISE", ); @@ -1447,7 +1447,7 @@ ); LLVM_LTO = YES_THIN; OTHER_CFLAGS = ( - "-DDISASSEMBLER", + "-D_NO_DISASSEMBLER", "-D_NO_INTERRUPT_CHECK_PER_STEP", "-D_NO_CLK_ABSOLUTE_PRECISE", ); diff --git a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist index 9c1f43a..f10d9dd 100644 --- a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -223,6 +223,14 @@ + + + + + + @@ -339,6 +347,14 @@ + + + + + + @@ -582,6 +598,9 @@ + + @@ -593,6 +612,26 @@ + + + + + + + + + + + + + + diff --git a/A2Mac/Base.lproj/Main.storyboard b/A2Mac/Base.lproj/Main.storyboard index 230fe62..8bfd4bd 100644 --- a/A2Mac/Base.lproj/Main.storyboard +++ b/A2Mac/Base.lproj/Main.storyboard @@ -1388,13 +1388,13 @@ - + - + - + - + - + - + @@ -1503,10 +1503,10 @@ - + - + @@ -1517,7 +1517,7 @@ - + - + @@ -1591,7 +1591,7 @@ + + + + @@ -1651,6 +1664,8 @@ + + @@ -1678,6 +1693,8 @@ + + diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift index 64d757d..db7fce2 100644 --- a/A2Mac/ViewController.swift +++ b/A2Mac/ViewController.swift @@ -1050,6 +1050,17 @@ class ViewController: NSViewController { openDiskImage() } + @IBAction func traceEnable(_ sender: NSButton) { + switch sender.state { + case .on: + m6502.dbgLevel.trace = 1 + openLog() + + default: + m6502.dbgLevel.trace = 0 + closeLog() + } + } } diff --git a/src/cpu/6502.c b/src/cpu/6502.c index 309273f..7ac2cd9 100644 --- a/src/cpu/6502.c +++ b/src/cpu/6502.c @@ -254,11 +254,11 @@ INLINE int m6502_Step() { case 0x16: ASL( addr_zp_X() ); return 6; // ASL zpg,X case 0x17: SLO( addr_zp_X() ); return 6; // SLO* zpg,X (undocumented) case 0x18: CLC(); return 2; // CLC - case 0x19: ORA( src_abs_Y() ); return 4; // ORA abs,Y + case 0x19: ORA( src_abs_Y() ); return 4+1; // ORA abs,Y case 0x1A: NOP(); return 2; // NOP* (undocumented) case 0x1B: SLO( addr_abs_Y() ); return 7; // SLO* abs,Y (undocumented) case 0x1C: NOP(); src_abs_X(); return 4; // NOP* (undocumented) - case 0x1D: ORA( src_abs_X() ); return 4; // ORA abs,X + case 0x1D: ORA( src_abs_X() ); return 4+1; // ORA abs,X case 0x1E: ASL( addr_abs_X() ); return 7; // ASL abs,X case 0x1F: SLO( addr_abs_X() ); return 7; // SLO* abs,X (undocumented) case 0x20: JSR( abs_addr() ); return 6; // JSR abs @@ -409,10 +409,10 @@ INLINE int m6502_Step() { case 0xB1: LDA( src_ind_Y() ); return 5; // LDA ind,Y case 0xB2: HLT(); return 0; // HLT* - Halts / Hangs / Jams / Kills the CPU (undocumented) case 0xB3: LAX( src_ind_Y() ); return 5; // LAX* izy 5 (undocumented) - case 0xB4: LDY( src_zp_X() ); return 4; // LDY zpg,X - case 0xB5: LDA( src_zp_X() ); return 4; // LDA zpg,X - case 0xB6: LDX( src_zp_Y() ); return 4; // LDX zpg,Y - case 0xB7: LAX( src_zp_Y() ); return 4; // LAX* zpy 4 (undocumented) + case 0xB4: LDY( src_zp_X() ); return 4+1; // LDY zpg,X + case 0xB5: LDA( src_zp_X() ); return 4+1; // LDA zpg,X + case 0xB6: LDX( src_zp_Y() ); return 4+1; // LDX zpg,Y + case 0xB7: LAX( src_zp_Y() ); return 4+1; // LAX* zpy 4 (undocumented) case 0xB8: CLV(); return 2; // CLV case 0xB9: LDA( src_abs_Y() ); return 4; // LDA abs,Y case 0xBA: TSX(); return 2; // TSX @@ -478,11 +478,11 @@ INLINE int m6502_Step() { case 0xF6: INC( addr_zp_X() ); return 6; // INC zpg,X case 0xF7: ISB( addr_zp_X() ); return 6; // ISB* zpx 6 (undocumented) case 0xF8: SED(); return 2; // SED - case 0xF9: SBC( src_abs_Y() ); return 4; // SBC abs,Y + case 0xF9: SBC( src_abs_Y() ); return 4+1; // SBC abs,Y case 0xFA: NOP(); return 2; // NOP case 0xFB: ISB( addr_abs_Y() ); return 7; // ISB* aby 7 (undocumented) case 0xFC: NOP(); src_abs_X(); return 4; // NOP* abx 4 (undocumented) - case 0xFD: SBC( src_abs_X() ); return 4; // SBC abs,X + case 0xFD: SBC( src_abs_X() ); return 4+1; // SBC abs,X case 0xFE: INC( addr_abs_X() ); return 7; // INC abs,X case 0xFF: ISB( addr_abs_X() ); return 7; // ISB* abx 7 (undocumented) @@ -677,6 +677,23 @@ void rom_loadFile( const char * bundlePath, const char * filename ) { } +void openLog() { + outdev = fopen("/Users/trudnai/Library/Containers/com.gamealloy.A2Mac/Data/disassembly_new.log", "w+"); + + // for DEBUG ONLY!!! -- use stdout if could not create log file +// if (outdev == NULL) { +// outdev = stdout; +// } +} + + +void closeLog() { + if ( ( outdev ) && ( outdev != stdout ) && ( outdev != stderr ) ) { + fclose(outdev); + } +} + + void m6502_ColdReset( const char * bundlePath, const char * romFileName ) { inst_cnt = 0; @@ -699,13 +716,6 @@ void m6502_ColdReset( const char * bundlePath, const char * romFileName ) { resetMemory(); - // for DEBUG ONLY!!! -// outdev = fopen("/Users/trudnai/Library/Containers/com.gamealloy.A2Mac/Data/disassembly_new.log", "w+"); -// if (outdev == NULL) { -// outdev = stdout; -// } - - #ifdef FUNCTIONTEST FILE * f = fopen("/Users/trudnai/Library/Containers/com.gamealloy.A2Mac/Data/6502_functional_test.bin", "rb"); diff --git a/src/cpu/6502.h b/src/cpu/6502.h index ed026ba..3ee224b 100644 --- a/src/cpu/6502.h +++ b/src/cpu/6502.h @@ -134,7 +134,7 @@ typedef struct disassembly_s { typedef struct MEMcfg_s { unsigned RAM_16K : 1; unsigned RAM_128K : 1; - unsigned RD_RAM : 1; + unsigned RD_INT_RAM : 1; unsigned WR_RAM : 1; unsigned RAM_BANK_2 : 1; unsigned AUX_BANK : 1; @@ -193,5 +193,9 @@ extern void interrupt_NMI(void); extern void hardReset(void); extern void softReset(void); +extern void openLog(void); +extern void closeLog(void); + + #endif /* __6502_H__ */ diff --git a/src/dev/disk/disk.c b/src/dev/disk/disk.c index 652b6f4..4eb8c41 100644 --- a/src/dev/disk/disk.c +++ b/src/dev/disk/disk.c @@ -6,6 +6,9 @@ // Copyright © 2020 GameAlloy. All rights reserved. // + +#include + #include "disk.h" #include "6502.h" #include "common.h" @@ -15,7 +18,9 @@ disk_t disk = { { 0, 0, 0 }, // phase + 0, // clk_last_access 0, // clk_since_last_read + 0, // drive number }; const int diskAccelerator_frames = 2; @@ -137,12 +142,17 @@ void disk_motor_off() { uint8_t disk_read() { dbgPrintf("io_DISK_READ (S%u)\n", 6); + disk.clk_last_access = m6502.clktime; disk_accelerator_speedup(); // Debug disk read // spkr_toggle(); + if ( disk.drive ) { + return rand(); + } + return woz_read(); } diff --git a/src/dev/disk/disk.h b/src/dev/disk/disk.h index ff655c1..7b84a41 100644 --- a/src/dev/disk/disk.h +++ b/src/dev/disk/disk.h @@ -30,6 +30,7 @@ typedef struct disk_s { phase_t phase; uint64_t clk_last_access; uint64_t clk_last_read; + uint8_t drive; } disk_t; diff --git a/src/dev/disk/woz.c b/src/dev/disk/woz.c index 8d4cd4e..20a4c52 100644 --- a/src/dev/disk/woz.c +++ b/src/dev/disk/woz.c @@ -230,11 +230,13 @@ uint8_t woz_read() { clkBeforeSync += clkelpased; const int clkBeforeAdjusting = 512; - const int magicShiftOffset = 50; + const int magicShiftOffset = 45; uint16_t usedBytes = woz_trks[track].bytes_used < WOZ_TRACK_BYTE_COUNT ? woz_trks[track].bytes_used : WOZ_TRACK_BYTE_COUNT; if ( usedBytes ) { + int shiftOffset = magicShiftOffset; + // printf("elpased : %llu (clkBefRd:%d)\n", clkelpased, clkBeforeSync); if ( clkelpased > clkBeforeAdjusting ) { @@ -242,7 +244,13 @@ uint8_t woz_read() { clkBeforeSync = 0; bitOffset = (clkelpased >> 2) & 7; trackOffset += clkelpased >> 5; - trackOffset %= usedBytes; + if ( trackOffset >= usedBytes ) { + bitOffset = 0; + trackOffset = 0; + WOZread.shift = 0; + shiftOffset = 0; + } +// trackOffset %= usedBytes; // preroll data stream WOZread.shift = 0; @@ -253,7 +261,7 @@ uint8_t woz_read() { WOZread.shift <<= bitOffset; WOZwrite = WOZread; - for ( int i = 0; i < magicShiftOffset; i++ ) { + for ( int i = 0; i < shiftOffset; i++ ) { for ( ; bitOffset < 8; bitOffset++ ) { WOZread.shift <<= 1; WOZwrite.shift <<= 1; diff --git a/src/dev/mem/mmio.h b/src/dev/mem/mmio.h index 8544929..cfa4340 100644 --- a/src/dev/mem/mmio.h +++ b/src/dev/mem/mmio.h @@ -326,7 +326,7 @@ void resetMemory() { // Reset memory configuration MEMcfg.RAM_16K = 0; MEMcfg.RAM_128K = 1; - MEMcfg.RD_RAM = 0; + MEMcfg.RD_INT_RAM = 0; MEMcfg.WR_RAM = 0; MEMcfg.RAM_BANK_2 = 0; MEMcfg.AUX_BANK = 0; @@ -401,14 +401,24 @@ void auxMemorySelect( MEMcfg_t newMEMcfg ) { } if ( MEMcfg.WR_AUX_MEM ) { - WRLOMEM = Apple2_64K_AUX; + if ( MEMcfg.RD_INT_RAM ) { + WRLOMEM = Apple2_64K_AUX; + } + else { + WRLOMEM = Apple2_64K_MEM; + } } else { - WRLOMEM = Apple2_64K_RAM; + if ( MEMcfg.RD_INT_RAM ) { + WRLOMEM = Apple2_64K_MEM; + } + else { + WRLOMEM = Apple2_64K_RAM; + } } } else { - WRLOMEM = Apple2_64K_RAM; + WRLOMEM = Apple2_64K_MEM; } // load new content to shadow memory @@ -473,7 +483,7 @@ INLINE void io_RAM_EXP( uint16_t addr ) { // printf("RD_RAM\n"); - MEMcfg.RD_RAM = 1; + MEMcfg.RD_INT_RAM = 1; // load the content of Aux Memory memcpy(Apple2_64K_MEM + 0xD000, RAM_BANK, 0x1000); @@ -485,7 +495,7 @@ INLINE void io_RAM_EXP( uint16_t addr ) { default: // printf("RD_ROM\n"); - MEMcfg.RD_RAM = 0; + MEMcfg.RD_INT_RAM = 0; // load the content of ROM Memory memcpy(Apple2_64K_MEM + 0xD000, Apple2_16K_ROM + 0x1000, 0x3000); @@ -611,7 +621,7 @@ INLINE uint8_t ioRead( uint16_t addr ) { return MEMcfg.RAM_BANK_2 << 7; case (uint8_t)io_RDLCRAM: - return MEMcfg.RD_RAM << 7; + return MEMcfg.RD_INT_RAM << 7; case (uint8_t)io_RDRAMRD: return MEMcfg.RD_AUX_MEM << 7; @@ -752,10 +762,12 @@ INLINE uint8_t ioRead( uint16_t addr ) { case (uint8_t)io_DISK_SELECT_1 + SLOT6: dbgPrintf2("io_DISK_SELECT_1 (S%u)\n", 6); + disk.drive = 0; return 0; case (uint8_t)io_DISK_SELECT_2 + SLOT6: dbgPrintf2("io_DISK_SELECT_2 (S%u)\n", 6); + disk.drive = 1; return 0; case (uint8_t)io_DISK_READ + SLOT6: @@ -1018,10 +1030,12 @@ INLINE void ioWrite( uint16_t addr, uint8_t val ) { case (uint8_t)io_DISK_SELECT_1 + SLOT6: dbgPrintf2("io_DISK_SELECT_1 (S%u)\n", 6); + disk.drive = 0; break; case (uint8_t)io_DISK_SELECT_2 + SLOT6: dbgPrintf2("io_DISK_SELECT_2 (S%u)\n", 6); + disk.drive = 1; break; case (uint8_t)io_DISK_READ + SLOT6: