Did not mean to revert these.
This commit is contained in:
parent
99294e7c19
commit
af294074aa
1 changed files with 14 additions and 8 deletions
22
src/Cpu.php
22
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue