From 791bd7efbd0c538495bd1b675b4c403a619f3528 Mon Sep 17 00:00:00 2001 From: "Raimon @ quifisraimon" Date: Fri, 18 Sep 2026 10:21:36 +0200 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20el=20cursor=20del=20debugger=20semp?= =?UTF-8?q?re=20anava=20una=20instrucci=C3=B3=20per=20darrere=20de=20PC=20?= =?UTF-8?q?-=20[NEW]=20El=20desensamblador=20s=C3=AD=20que=20pot=20determi?= =?UTF-8?q?nar=20opcodes=20cap=20enrere=20en=20el=206502=20-=20[FIX]=20Fer?= =?UTF-8?q?=20wrap=20correcte=20dels=20uint16=5Ft=20per=20a=20evitar=20des?= =?UTF-8?q?bordaments=20-=20[FIX]=20La=20pila=20ac=C3=AD=20va=20al=20reves?= =?UTF-8?q?,=20pintar=20com=20toca=20en=20el=20debugger=20-=20[FIX]=20arre?= =?UTF-8?q?glats=20(supostament)=20opcodes:=20PHP,=20JSR,=20PLP,=20RTI,=20?= =?UTF-8?q?JMP=20i=20RTS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/6502debugger.cpp | 28 +++++++++++++++------------- source/6502m.cpp | 18 ++++++++++-------- source/atari2600.cpp | 12 +++++------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/source/6502debugger.cpp b/source/6502debugger.cpp index e7a3f67..70c56fa 100644 --- a/source/6502debugger.cpp +++ b/source/6502debugger.cpp @@ -309,7 +309,7 @@ namespace m6502debugger if ( !(tag & MEMTAG_IGNORE) ) tag |= MEMTAG_INST; tag |= (!(tag&MEMTAG_TOUCHED) ? MEMTAG_TREPEAT : MEMTAG_TINST); - setcursor(m6502::getPC()); + setcursor(address); history::store(); } @@ -418,12 +418,14 @@ namespace m6502debugger uint16_t find_previous_opcode(uint16_t pc) { - pc--; - if ( !(tags[pc] & (MEMTAG_CODE | MEMTAG_INST) ) ) return pc; - - while ( !(tags[pc] & MEMTAG_INST) ) pc--; - - return pc; + if (m6502dis::getOpcodeSize(uint16_t(pc-3))==3) return uint16_t(pc-3); + if (m6502dis::getOpcodeSize(uint16_t(pc-2))==2) return uint16_t(pc-2); + return uint16_t(pc-1); + //if ( !(tags[pc] & (MEMTAG_CODE | MEMTAG_INST) ) ) return pc; + // + //while ( !(tags[pc] & MEMTAG_INST) ) pc--; + // + //return pc; } void printDissasemblerLine(const uint16_t address, const int line, const bool heuristics=false) @@ -447,7 +449,7 @@ namespace m6502debugger const int opcodesize = m6502dis::getOpcodeSize(address); for (int i=0; i=0;--i) { pos = find_previous_opcode(pos); line_address[i] = pos; - printDissasemblerLine(pos, i); + printDissasemblerLine(pos, i, true); } // REGISTERS @@ -540,17 +542,17 @@ namespace m6502debugger ui::printrect(midx+2,8, 8,1, COLOR_DARK); ui::printtxt(midx+3,8, "STACK:", COLOR_WHITE); ui::setoffset(midx+1, 9); - uint16_t sp = 0x0100 | m6502::getS();//-(((sym_y-12)>>1)<<1); + uint16_t sp = m6502::getS()+8;//-(((sym_y-12)>>1)<<1); for (int i=0; i<10; ++i) { uint8_t c1=COLOR_CYAN, c2=COLOR_GRAY; - if ((sp & 0xff) == m6502::getS()) { + if (sp == m6502::getS()) { ui::printrect(0,i,9,1,COLOR_BLUE); c1 = c2 = COLOR_YELLOW; } ui::printtxt(0,i, tohex(0x0100 | sp, 4), c1); - uint16_t value = mem::read(0x0100 | sp) + (mem::read(0x0100 | (sp-1))<<8); + uint16_t value = mem::read(0x0100 | sp-1) + (mem::read(0x0100 | (sp))<<8); ui::printtxt(5,i, tohex(value, 4), c2); - sp+=2; + sp-=2; } diff --git a/source/6502m.cpp b/source/6502m.cpp index 25a282c..20ebe26 100644 --- a/source/6502m.cpp +++ b/source/6502m.cpp @@ -89,6 +89,7 @@ namespace m6502 miIncrementPC, miFetchAddressHiToPC, miIndexY, + miFetchOperandHiToPC, miNumMicroinstructions }; @@ -102,7 +103,7 @@ namespace m6502 /* 0x05 ORA zpg */ { miFetchOperandLo, miReadAddress, miFetchOpcode }, /* 0x06 ASL zpg */ { miFetchOperandLo, miReadAddress, miWriteAddress, miWriteAddress, miFetchOpcode }, /* 0x07 --- */ { miFetchOpcode }, - /* 0x08 PHP */ { miFetchOperandLo, miPushP, miFetchOpcode }, + /* 0x08 PHP */ { miFakeFetchOperand, miPushP, miFetchOpcode }, /* 0x09 ORA imm */ { miFetchOperandLo, miFetchOpcode }, /* 0x0A ASL A */ { miFakeFetchOperand, miFetchOpcode }, /* 0x0B --- */ { miFetchOpcode }, @@ -128,7 +129,7 @@ namespace m6502 /* 0x1E ASL abs,X */ { miFetchOperandLo, miFetchOperandHiAndIndexX, miReadAddress, miReadAddress, miWriteAddress, miWriteAddress, miFetchOpcode }, /* 0x1F --- */ { miFetchOpcode }, - /* 0x20 JSR abs */ { miFetchAddressLo, miFakeFetchOperand, miPushPCHi, miPushPCLo, miFetchAddressHi, miFetchOpcode }, + /* 0x20 JSR abs */ { miFetchOperandLo, miFakeFetchOperand, miPushPCHi, miPushPCLo, miFetchOperandHiToPC, miFetchOpcode }, /* 0x21 AND X,ind */ { miFetchOperandLo, miIndexX, miFetchAddressLo, miFetchAddressHi, miReadAddress, miFetchOpcode }, /* 0x22 --- */ { miFetchOpcode }, /* 0x23 --- */ { miFetchOpcode }, @@ -136,7 +137,7 @@ namespace m6502 /* 0x25 AND zpg */ { miFetchOperandLo, miReadAddress, miFetchOpcode }, /* 0x26 ROL zpg */ { miFetchOperandLo, miReadAddress, miWriteAddress, miWriteAddress, miFetchOpcode }, /* 0x27 --- */ { miFetchOpcode }, - /* 0x28 PLP */ { miFetchOperandLo, miPullP, miFetchOpcode }, + /* 0x28 PLP */ { miFakeFetchOperand, miFakeFetchOperand, miPullP, miFetchOpcode }, /* 0x29 AND imm */ { miFetchOperandLo, miFetchOpcode }, /* 0x2A ROL A */ { miFakeFetchOperand, miFetchOpcode }, /* 0x2B --- */ { miFetchOpcode }, @@ -162,7 +163,7 @@ namespace m6502 /* 0x3E ROL abs,X */ { miFetchOperandLo, miFetchOperandHiAndIndexX, miReadAddress, miReadAddress, miWriteAddress, miWriteAddress, miFetchOpcode }, /* 0x3F --- */ { miFetchOpcode }, - /* 0x40 RTI */ { miFetchOperandLo, miFakeFetchOperand, miPullP, miPullPCLo, miPullPCHi, miFetchOpcode }, + /* 0x40 RTI */ { miFakeFetchOperand, miFakeFetchOperand, miPullP, miPullPCLo, miPullPCHi, miFetchOpcode }, /* 0x41 EOR X,ind */ { miFetchOperandLo, miIndexX, miFetchAddressLo, miFetchAddressHi, miReadAddress, miFetchOpcode }, /* 0x42 --- */ { miFetchOpcode }, /* 0x43 --- */ { miFetchOpcode }, @@ -174,7 +175,7 @@ namespace m6502 /* 0x49 EOR imm */ { miFetchOperandLo, miFetchOpcode }, /* 0x4A LSR A */ { miFakeFetchOperand, miFetchOpcode }, /* 0x4B --- */ { miFetchOpcode }, - /* 0x4C JMP abs */ { miFetchAddressLo, miFetchAddressHi, miFetchOpcode }, + /* 0x4C JMP abs */ { miFetchOperandLo, miFetchOperandHi, miFetchOpcode }, /* 0x4D EOR abs */ { miFetchOperandLo, miFetchOperandHi, miReadAddress, miFetchOpcode }, /* 0x4E LSR abs */ { miFetchOperandLo, miFetchOperandHi, miReadAddress, miWriteAddress, miWriteAddress, miFetchOpcode }, /* 0x4F --- */ { miFetchOpcode }, @@ -196,7 +197,7 @@ namespace m6502 /* 0x5E LSR abs,X */ { miFetchOperandLo, miFetchOperandHiAndIndexX, miReadAddress, miReadAddress, miWriteAddress, miWriteAddress, miFetchOpcode }, /* 0x5F --- */ { miFetchOpcode }, - /* 0x60 RTS */ { miFetchOperandLo, miFakeFetchOperand, miPullPCLo, miPullPCHi, miIncrementPC, miFetchOpcode }, + /* 0x60 RTS */ { miFakeFetchOperand, miFakeFetchOperand, miPullPCLo, miPullPCHi, miIncrementPC, miFetchOpcode }, /* 0x61 ADC X,ind */ { miFetchOperandLo, miIndexX, miFetchAddressLo, miFetchAddressHi, miReadAddress, miFetchOpcode }, /* 0x62 --- */ { miFetchOpcode }, /* 0x63 --- */ { miFetchOpcode }, @@ -535,9 +536,10 @@ namespace m6502 int i=0; do { microcode[microcode_last++] = instructions[rI][i++]; } while (instructions[rI][i-1] != miFetchOpcode); } - void FakeFetchOperand() { rAD_lo = mem::read(get_PC()); } + void FakeFetchOperand() { uint8_t dummy = mem::read(get_PC()); (void)dummy; } void FetchOperandLo() { rAD_lo = rB = mem::read(get_PC()); inc_PC(); set_TEMP(rB); } void FetchOperandHi() { rAD_hi = mem::read(get_PC()); inc_PC(); } + void FetchOperandHiToPC() { rAD_hi = mem::read(get_PC()); set_PC(get_AD()); } void FetchOperandHiAndIndexX() { rAD_hi = mem::read(get_PC()); inc_PC(); set_TEMP(rAD_lo + rX); rAD_lo = rTEMP_lo; } void FetchOperandHiAndIndexY() { rAD_hi = mem::read(get_PC()); inc_PC(); set_TEMP(rAD_lo + rY); rAD_lo = rTEMP_lo; } @@ -599,7 +601,7 @@ namespace m6502 IndexX, FetchAddressLo, FetchAddressHi, FetchAddressHiAndIndex, ReadAddress, ReadAddressAndSkip, WriteRegister, WriteAddress, PushA, FetchOperandAndCheckBranch, CheckIfPageCrossed, PullPCHi, PullPCLo, PullP, PullA, - IncrementPC, FetchAddressHiToPC, IndexY }; + IncrementPC, FetchAddressHiToPC, IndexY, FetchOperandHiToPC }; void reset() { diff --git a/source/atari2600.cpp b/source/atari2600.cpp index 173ca65..e212722 100644 --- a/source/atari2600.cpp +++ b/source/atari2600.cpp @@ -37,13 +37,9 @@ namespace atari2600 should_exit = true; } - int ppc = 0; void step() { - //uint8_t t_states; - uint16_t pc = m6502::getPC(); - ppc += pc; - m6502debugger::onInstructionExecute(pc); + uint8_t t_states; // if (z80debugger::isbreak(pc, 9)) { // msx::pause(); // z80debugger::show(); @@ -60,9 +56,11 @@ namespace atari2600 tia::tick(); tia::tick(); pia::tick(); - //t_states++; + t_states++; } - //speaker::update(t_states); + uint16_t pc = m6502::getPC(); + m6502debugger::onInstructionExecute(pc); + speaker::update(t_states); // } }