pete-gordon / oricutron

Portable Oric-1/Atmos/Telestrat and Pravetz 8D emulator
http://www.petergordon.org.uk/oricutron/
GNU General Public License v2.0
69 stars 25 forks source link

Copy/Paste sometimes fails with illegal op code and open the monitor #127

Closed assinie closed 5 years ago

assinie commented 5 years ago

I think there is a bug in function ay_ticktock() when the IRQ is raised while the 6502 executes a JMP CheckKbd (so just before the call to ay_ticktock). In this case, the SP and PC registers are wrong when ay_ticktock() ends, then the next op code isn't fetched from the right address and is possibly JAM.

A possible fix may be:

  // Need to do queued keys?
  if( ( keyqueue ) && ( keysqueued ) && (!ay->oric->cpu.irq))

instead of

  // Need to do queued keys?
  if( ( keyqueue ) && ( keysqueued ) )

at the beginning of ay_ticktock() (line 465).

Or maybe wrap the whole function within a if (!ay->oric->cpu.irq)

If someone else can check and confirm...

iss000 commented 5 years ago

Good find, @assinie ! I tested and everything seems to work OK. I committed your proposal. Thanks.