Skip to content

Commit

Permalink
Fix Issue#205: Self-modifying JSR, JSR bus cycle order
Browse files Browse the repository at this point in the history
This fixes Issue#205 where a self-modifying JSR instruction crafted to
modify the address being called calls the wrong address.  The fix is to
match the order of the bus cycles to a real 6502.
  • Loading branch information
Steve Fosdick committed Jul 2, 2023
1 parent a55f951 commit 44b4252
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
14 changes: 6 additions & 8 deletions src/6502.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,12 +1637,11 @@ void m6502_exec(void)
takeint = (interrupt && !p.i);
break;

case 0x20:
/*JSR*/ addr = getw();
pc--;
case 0x20: /*JSR*/
addr = readmem(pc++);
push(pc >> 8);
push((uint8_t)pc);
pc = addr;
pc = addr | (readmem(pc) << 8);
polltime(5);
takeint = (interrupt && !p.i);
polltime(1);
Expand Down Expand Up @@ -4292,12 +4291,11 @@ void m65c02_exec(void)
polltime(6 + tempw);
break;

case 0x20:
/*JSR*/ addr = getw();
pc--;
case 0x20: /*JSR*/
addr = readmem(pc++);
push(pc >> 8);
push((uint8_t)pc);
pc = addr;
pc = addr | (readmem(pc) << 8);
polltime(5);
takeint = (interrupt && !p.i);
polltime(1);
Expand Down
7 changes: 3 additions & 4 deletions src/6502tube.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,11 @@ void tube_6502_exec()
bbr(0x02);
break;

case 0x20:
/*JSR*/ addr = getw();
pc--;
case 0x20: /*JSR*/
addr = readmem(pc++);
push(pc >> 8);
push(pc);
pc = addr;
pc = addr | (readmem(pc) << 8);
polltime(6);
break;

Expand Down

0 comments on commit 44b4252

Please sign in to comment.