Skip to content

Commit

Permalink
reverse masking out unused bit and default it to set
Browse files Browse the repository at this point in the history
cus it always set apparently OOPS
  • Loading branch information
xubiod committed Mar 7, 2024
1 parent 52a70cb commit 88f2384
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cpu/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const (
FLAG_INTERRUPT_DISABLE // I - When set, interrupts are disabled.
FLAG_DECIMAL // D - When set, math operations are done with BCD. No other operation is affected by the status of this flag.
FLAG_BREAK // B - Set when a software interrupt happens with `BRK`.
FLAG_UNUSED // _ - This flag is not used by the 6502. The emulator masks it out during status push/pulls from the stack.
FLAG_UNUSED // _ - This flag is not used by the 6502. It is always set on the 6502.
FLAG_OVERFLOW // V - Set when the last operation resulted in a *signed overflow* if the numbers were interpreted as signed.
FLAG_NEGATIVE // N - Set when the last operation resulted as a negative number as a bit 7 check.
)
Expand Down Expand Up @@ -314,6 +314,8 @@ func (c *Core) prepare() {
0x9C: c.STZ____a, 0x9E: c.STZ___ax,
}

c.Flags = c.Flags | FLAG_UNUSED

_ = c.SetWriterPtr(0x0200)
}

Expand Down
4 changes: 2 additions & 2 deletions cpu/set_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *Core) PLA____i() {
func (c *Core) PHP____i() {
c.PC += 1

c.Memory[0x0100+uint16(c.S)] = (c.Flags & ^FLAG_BREAK) & ^FLAG_UNUSED
c.Memory[0x0100+uint16(c.S)] = (c.Flags & ^FLAG_BREAK) | FLAG_UNUSED
c.S--
}

Expand All @@ -41,7 +41,7 @@ func (c *Core) PLP____i() {
c.PC += 1

c.S++
c.Flags = c.Memory[0x0100+uint16(c.S)] & ^FLAG_UNUSED
c.Flags = c.Memory[0x0100+uint16(c.S)] | FLAG_UNUSED
}

// 65c02 Instructions/Implementations below this line
Expand Down

0 comments on commit 88f2384

Please sign in to comment.