From af294074aa0322ef53c0d22638f36564a5c56a35 Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 11 Dec 2024 02:28:31 +0000 Subject: [PATCH] Did not mean to revert these. --- src/Cpu.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Cpu.php b/src/Cpu.php index 7109231..03e9759 100644 --- a/src/Cpu.php +++ b/src/Cpu.php @@ -28,11 +28,11 @@ class Cpu { } public function popU8(): int { - return $this->io->read($this->state->sPage | $this->state->s--); + return $this->io->read($this->state->sPage | $this->state->s++); } public function pushU8(int $value): void { - $this->io->write($this->state->sPage | $this->state->s++, $value); + $this->io->write($this->state->sPage | $this->state->s--, $value); } public function popU16(): int { @@ -64,13 +64,19 @@ class Cpu { return; } - $vector = match($irq) { - CpuInterruptRequest::Maskable => self::IV_IRQ, - CpuInterruptRequest::NonMaskable => self::IV_NMI, - default => throw new RuntimeException('unexpected irq value') - }; + $pc = $this->state->pc; - $this->pushU16($this->state->pc); + if($irq === CpuInterruptRequest::Break) { + $vector = self::IV_IRQ; + ++$pc; + } else + $vector = match($irq) { + CpuInterruptRequest::Maskable => self::IV_IRQ, + CpuInterruptRequest::NonMaskable => self::IV_NMI, + default => throw new RuntimeException('unexpected irq value') + }; + + $this->pushU16($pc); $this->pushU8($this->state->p); $this->state->pc = $this->readIoU16($vector); }