mirror of
https://github.com/ivanizag/izapple2.git
synced 2025-01-02 20:29:44 +00:00
Handle the virtual bits 5 and 4 when pushing P to the stack
This commit is contained in:
parent
7f9aea24e9
commit
2b02b8de9e
20
execute.go
20
execute.go
@ -274,18 +274,20 @@ func pullWord(s *state) uint16 {
|
||||
|
||||
}
|
||||
|
||||
func buildOpPush(reg int) opFunc {
|
||||
return func(s *state, line []uint8, opcode opcode) {
|
||||
pushByte(s, s.registers.getRegister(reg))
|
||||
}
|
||||
}
|
||||
|
||||
func buildOpPull(reg int) opFunc {
|
||||
return func(s *state, line []uint8, opcode opcode) {
|
||||
s.registers.setRegister(reg, pullByte(s))
|
||||
}
|
||||
}
|
||||
|
||||
func opPHA(s *state, line []uint8, opcode opcode) {
|
||||
pushByte(s, s.registers.getA())
|
||||
}
|
||||
|
||||
func opPHP(s *state, line []uint8, opcode opcode) {
|
||||
pushByte(s, s.registers.getP()|(flagB+flag5))
|
||||
}
|
||||
|
||||
func buildOpJump(addressMode int) opFunc {
|
||||
return func(s *state, line []uint8, opcode opcode) {
|
||||
_, address, _ := resolveWithAddressMode(s, line, addressMode)
|
||||
@ -312,7 +314,7 @@ func opRTS(s *state, line []uint8, opcode opcode) {
|
||||
func opBRK(s *state, line []uint8, opcode opcode) {
|
||||
s.registers.setFlag(flagI)
|
||||
pushWord(s, s.registers.getPC()+1) // TODO: De we have to add 1 or 2?
|
||||
pushByte(s, s.registers.getP())
|
||||
pushByte(s, s.registers.getP()|(flagB+flag5))
|
||||
s.registers.setPC(s.memory.getWord(0xFFFE))
|
||||
}
|
||||
|
||||
@ -324,8 +326,8 @@ var opcodes = [256]opcode{
|
||||
0x40: opcode{"RTI", 1, 6, opRTI},
|
||||
0x60: opcode{"RTS", 1, 6, opRTS},
|
||||
|
||||
0x48: opcode{"PHA", 1, 3, buildOpPush(regA)},
|
||||
0x08: opcode{"PHP", 1, 3, buildOpPush(regP)},
|
||||
0x48: opcode{"PHA", 1, 3, opPHA},
|
||||
0x08: opcode{"PHP", 1, 3, opPHP},
|
||||
0x68: opcode{"PLA", 1, 4, buildOpPull(regA)},
|
||||
0x28: opcode{"PLP", 1, 4, buildOpPull(regP)},
|
||||
|
||||
|
@ -427,7 +427,7 @@ func TestStack(t *testing.T) {
|
||||
if s.registers.getSP() != 0xEE {
|
||||
t.Errorf("Error in PHP stack pointer, %v", s.registers)
|
||||
}
|
||||
if s.memory[0x01EF] != 0x0A {
|
||||
if s.memory[0x01EF] != 0x3A {
|
||||
t.Errorf("Error in PHP, %v", s.registers)
|
||||
}
|
||||
|
||||
@ -435,7 +435,7 @@ func TestStack(t *testing.T) {
|
||||
if s.registers.getSP() != 0xEF {
|
||||
t.Errorf("Error in PLA stack pointer, %v", s.registers)
|
||||
}
|
||||
if s.registers.getA() != 0x0A {
|
||||
if s.registers.getA() != 0x3A {
|
||||
t.Errorf("Error in PLA, %v", s.registers)
|
||||
}
|
||||
|
||||
@ -447,3 +447,5 @@ func TestStack(t *testing.T) {
|
||||
t.Errorf("Error in PLP, %v", s.registers)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Tests for BRK, JMP, JSR, RTI, RTS
|
||||
|
@ -15,6 +15,7 @@ const (
|
||||
const (
|
||||
flagN uint8 = 1 << 7
|
||||
flagV uint8 = 1 << 6
|
||||
flag5 uint8 = 1 << 5
|
||||
flagB uint8 = 1 << 4
|
||||
flagD uint8 = 1 << 3
|
||||
flagI uint8 = 1 << 2
|
||||
|
Loading…
Reference in New Issue
Block a user