Skip to content

Commit

Permalink
Merge branch 'wrap-push-pop-functions'
Browse files Browse the repository at this point in the history
  • Loading branch information
koron committed Apr 19, 2024
2 parents 080791b + 0014428 commit 7af52f9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
36 changes: 34 additions & 2 deletions op_load16.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func oopPOPIY(cpu *CPU) {
//////////////////////////////////////////////////////////////////////////////
// eXpanded OPration codes

func xopPUSHreg(cpu *CPU, reg Register) {
func copPUSHreg(cpu *CPU, reg Register) {
// Code before optimization
//cpu.SP -= 2
//cpu.Memory.Set(cpu.SP, reg.Lo)
Expand All @@ -87,7 +87,23 @@ func xopPUSHreg(cpu *CPU, reg Register) {
cpu.Memory.Set(cpu.SP, reg.Lo)
}

func xopPOPreg(cpu *CPU, reg *Register) {
func xopPUSHbc(cpu *CPU) {
copPUSHreg(cpu, cpu.BC)
}

func xopPUSHde(cpu *CPU) {
copPUSHreg(cpu, cpu.DE)
}

func xopPUSHhl(cpu *CPU) {
copPUSHreg(cpu, cpu.HL)
}

func xopPUSHaf(cpu *CPU) {
copPUSHreg(cpu, cpu.AF)
}

func copPOPreg(cpu *CPU, reg *Register) {
// Code before optimization
//reg.Lo = cpu.Memory.Get(cpu.SP)
//reg.Hi = cpu.Memory.Get(cpu.SP + 1)
Expand All @@ -98,6 +114,22 @@ func xopPOPreg(cpu *CPU, reg *Register) {
cpu.SP++
}

func xopPOPbc(cpu *CPU) {
copPOPreg(cpu, &cpu.BC)
}

func xopPOPde(cpu *CPU) {
copPOPreg(cpu, &cpu.DE)
}

func xopPOPhl(cpu *CPU) {
copPOPreg(cpu, &cpu.HL)
}

func xopPOPaf(cpu *CPU) {
copPOPreg(cpu, &cpu.AF)
}

func xopLDbcnn(cpu *CPU) {
cpu.BC.Lo, cpu.BC.Hi = cpu.fetch2()
}
Expand Down
16 changes: 8 additions & 8 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,13 @@ func (cpu *CPU) executeOne() {
xopRETfS(cpu)

case 0xc1:
xopPOPreg(cpu, &cpu.BC)
xopPOPbc(cpu)
case 0xd1:
xopPOPreg(cpu, &cpu.DE)
xopPOPde(cpu)
case 0xe1:
xopPOPreg(cpu, &cpu.HL)
xopPOPhl(cpu)
case 0xf1:
xopPOPreg(cpu, &cpu.AF)
xopPOPaf(cpu)

case 0xc2:
xopJPnZnn(cpu)
Expand Down Expand Up @@ -519,13 +519,13 @@ func (cpu *CPU) executeOne() {
xopCALLfSnn(cpu)

case 0xc5:
xopPUSHreg(cpu, cpu.BC)
xopPUSHbc(cpu)
case 0xd5:
xopPUSHreg(cpu, cpu.DE)
xopPUSHde(cpu)
case 0xe5:
xopPUSHreg(cpu, cpu.HL)
xopPUSHhl(cpu)
case 0xf5:
xopPUSHreg(cpu, cpu.AF)
xopPUSHaf(cpu)

case 0xc6:
oopADDAn(cpu)
Expand Down

0 comments on commit 7af52f9

Please sign in to comment.