From 86602a4eb78a10b605bfeb3554f9f630a16e01c0 Mon Sep 17 00:00:00 2001 From: Will Scullin Date: Wed, 18 Sep 2019 19:46:15 -0700 Subject: [PATCH] Try and emulate "false reads" --- js/cpu6502.js | 43 ++++++++++++++++++++++++++----------------- js/main2e.js | 1 - 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/js/cpu6502.js b/js/cpu6502.js index 2ea8825..c51d92c 100644 --- a/js/cpu6502.js +++ b/js/cpu6502.js @@ -314,7 +314,8 @@ export default function CPU6502(options) addr = (addr + xr) & 0xffff; page = addr >> 8; if (page != oldPage) { - cycles++; + var off = addr & 0xff; + readByte(oldPage << 8 | off); } return readByte(addr); } @@ -325,7 +326,8 @@ export default function CPU6502(options) addr = (addr + yr) & 0xffff; page = addr >> 8; if (page != oldPage) { - cycles++; + var off = addr & 0xff; + readByte(oldPage << 8 | off); } return readByte(addr); } @@ -357,7 +359,8 @@ export default function CPU6502(options) addr = (addr + yr) & 0xffff; page = addr >> 8; if (page != oldPage) { - cycles++; + var off = addr & 0xff; + readByte(oldPage << 8 | off); } return readByte(addr); } @@ -383,16 +386,20 @@ export default function CPU6502(options) // $0000,X function writeAbsoluteX(val) { - var address = (readWordPC() + xr) & 0xffff; - cycles++; - writeByte(address, val); + var addr = readWordPC(), oldPage = addr >> 8; + addr = (addr + xr) & 0xffff; + var off = addr & 0xff; + readByte(oldPage << 8 | off); + writeByte(addr, val); } // $0000,Y function writeAbsoluteY(val) { - var address = (readWordPC() + yr) & 0xffff; - cycles++; - writeByte(address, val); + var addr = readWordPC(), oldPage = addr >> 8; + addr = (addr + yr) & 0xffff; + var off = addr & 0xff; + readByte(oldPage << 8 | off); + writeByte(addr, val); } // $00,X @@ -418,9 +425,11 @@ export default function CPU6502(options) // ($00),Y function writeZeroPageIndirectY(val) { - var address = (readZPWord(readBytePC()) + yr) & 0xffff; - cycles++; - writeByte(address, val); + var addr = readZPWord(readBytePC()), oldPage = addr >> 8; + addr = (addr + yr) & 0xffff; + var off = addr & 0xff; + readByte(oldPage << 8 | off); + writeByte(addr, val); } // ($00) (65C02) @@ -458,9 +467,9 @@ export default function CPU6502(options) } // $0000,X - function readAddrAbsoluteX() { + function readAddrAbsoluteX(opts) { var addr = readWordPC(); - if (!is65C02) { + if (!is65C02 || (opts && opts.inc)) { readByte(addr); } else { cycles++; @@ -538,7 +547,7 @@ export default function CPU6502(options) } function inc(readAddrFn) { - var addr = readAddrFn(); + var addr = readAddrFn({inc: true}); writeByte(addr, increment(readByte(addr))); } @@ -558,7 +567,7 @@ export default function CPU6502(options) } function dec(readAddrFn) { - var addr = readAddrFn(); + var addr = readAddrFn({inc: true}); writeByte(addr, decrement(readByte(addr))); } @@ -1422,7 +1431,7 @@ export default function CPU6502(options) } }, - /* IRQ - Interupt Request */ + /* IRQ - Interrupt Request */ irq: function cpu_irq() { if ((sr & flags.I) === 0) { diff --git a/js/main2e.js b/js/main2e.js index d1071d5..37032b8 100644 --- a/js/main2e.js +++ b/js/main2e.js @@ -227,7 +227,6 @@ function doLoadLocalDisk(drive, file) { var name = parts.join('.'); if (disk2.setBinary(drive, name, ext, this.result)) { drivelights.label(drive, name); - MicroModal.close('load-modal'); initGamepad(); } };