Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrange decoder #12

Merged
merged 11 commits into from
Apr 19, 2024
Merged
4 changes: 2 additions & 2 deletions cmd/zexdoc/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TIMESTAMP=$(shell date +%Y%m%dT%H%M%S%z)
PROFILE_NAME=tmp/profile/zexdoc-$(TIMESTAMP)
TIMESTAMP = $(shell date +%Y%m%dT%H%M%S%z)
PROFILE_NAME := tmp/profile/zexdoc-$(TIMESTAMP)

.PHONY: run
run: zexdoc.cim
Expand Down
24 changes: 24 additions & 0 deletions cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ func (cpu *CPU) flagZ() bool {
return cpu.AF.Lo&maskZ != 0
}

func (cpu *CPU) flagPV() bool {
return cpu.AF.Lo&maskPV != 0
}

func (cpu *CPU) flagS() bool {
return cpu.AF.Lo&maskS != 0
}

func (cpu *CPU) readU16(addr uint16) uint16 {
l := cpu.Memory.Get(addr)
h := cpu.Memory.Get(addr + 1)
Expand All @@ -111,6 +119,22 @@ func (cpu *CPU) fetch() uint8 {
return v
}

func (cpu *CPU) fetch2() (l, h uint8) {
l = cpu.Memory.Get(cpu.PC)
cpu.PC++
h = cpu.Memory.Get(cpu.PC)
cpu.PC++
return l, h
}

func (cpu *CPU) fetch16() uint16 {
l := cpu.Memory.Get(cpu.PC)
cpu.PC++
h := cpu.Memory.Get(cpu.PC)
cpu.PC++
return (uint16(h) << 8) | uint16(l)
}

func (cpu *CPU) ioIn(addr uint8) uint8 {
if cpu.IO == nil {
return 0
Expand Down
84 changes: 56 additions & 28 deletions op_arith8.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package z80

func oopADDAn(cpu *CPU, n uint8) {
func oopADDAn(cpu *CPU) {
n := cpu.fetch()
a := cpu.AF.Hi
cpu.AF.Hi = cpu.addU8(a, n)
}
Expand All @@ -11,21 +12,24 @@ func oopADDAHLP(cpu *CPU) {
cpu.AF.Hi = cpu.addU8(a, x)
}

func oopADDAIXdP(cpu *CPU, d uint8) {
func oopADDAIXdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.addU8(a, x)
}

func oopADDAIYdP(cpu *CPU, d uint8) {
func oopADDAIYdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.addU8(a, x)
}

func oopADCAn(cpu *CPU, n uint8) {
func oopADCAn(cpu *CPU) {
n := cpu.fetch()
a := cpu.AF.Hi
cpu.AF.Hi = cpu.adcU8(a, n)
}
Expand All @@ -36,21 +40,24 @@ func oopADCAHLP(cpu *CPU) {
cpu.AF.Hi = cpu.adcU8(a, x)
}

func oopADCAIXdP(cpu *CPU, d uint8) {
func oopADCAIXdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.adcU8(a, x)
}

func oopADCAIYdP(cpu *CPU, d uint8) {
func oopADCAIYdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.adcU8(a, x)
}

func oopSUBAn(cpu *CPU, n uint8) {
func oopSUBAn(cpu *CPU) {
n := cpu.fetch()
a := cpu.AF.Hi
cpu.AF.Hi = cpu.subU8(a, n)
}
Expand All @@ -61,21 +68,24 @@ func oopSUBAHLP(cpu *CPU) {
cpu.AF.Hi = cpu.subU8(a, x)
}

func oopSUBAIXdP(cpu *CPU, d uint8) {
func oopSUBAIXdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.subU8(a, x)
}

func oopSUBAIYdP(cpu *CPU, d uint8) {
func oopSUBAIYdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.subU8(a, x)
}

func oopSBCAn(cpu *CPU, n uint8) {
func oopSBCAn(cpu *CPU) {
n := cpu.fetch()
a := cpu.AF.Hi
cpu.AF.Hi = cpu.sbcU8(a, n)
}
Expand All @@ -86,21 +96,24 @@ func oopSBCAHLP(cpu *CPU) {
cpu.AF.Hi = cpu.sbcU8(a, x)
}

func oopSBCAIXdP(cpu *CPU, d uint8) {
func oopSBCAIXdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.sbcU8(a, x)
}

func oopSBCAIYdP(cpu *CPU, d uint8) {
func oopSBCAIYdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.sbcU8(a, x)
}

func oopANDn(cpu *CPU, n uint8) {
func oopANDn(cpu *CPU) {
n := cpu.fetch()
a := cpu.AF.Hi
cpu.AF.Hi = cpu.andU8(a, n)
}
Expand All @@ -111,21 +124,24 @@ func oopANDHLP(cpu *CPU) {
cpu.AF.Hi = cpu.andU8(a, x)
}

func oopANDIXdP(cpu *CPU, d uint8) {
func oopANDIXdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.andU8(a, x)
}

func oopANDIYdP(cpu *CPU, d uint8) {
func oopANDIYdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.andU8(a, x)
}

func oopORn(cpu *CPU, n uint8) {
func oopORn(cpu *CPU) {
n := cpu.fetch()
a := cpu.AF.Hi
cpu.AF.Hi = cpu.orU8(a, n)
}
Expand All @@ -136,21 +152,24 @@ func oopORHLP(cpu *CPU) {
cpu.AF.Hi = cpu.orU8(a, x)
}

func oopORIXdP(cpu *CPU, d uint8) {
func oopORIXdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.orU8(a, x)
}

func oopORIYdP(cpu *CPU, d uint8) {
func oopORIYdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.orU8(a, x)
}

func oopXORn(cpu *CPU, n uint8) {
func oopXORn(cpu *CPU) {
n := cpu.fetch()
a := cpu.AF.Hi
cpu.AF.Hi = cpu.xorU8(a, n)
}
Expand All @@ -161,21 +180,24 @@ func oopXORHLP(cpu *CPU) {
cpu.AF.Hi = cpu.xorU8(a, x)
}

func oopXORIXdP(cpu *CPU, d uint8) {
func oopXORIXdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.xorU8(a, x)
}

func oopXORIYdP(cpu *CPU, d uint8) {
func oopXORIYdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
cpu.AF.Hi = cpu.xorU8(a, x)
}

func oopCPn(cpu *CPU, n uint8) {
func oopCPn(cpu *CPU) {
n := cpu.fetch()
a := cpu.AF.Hi
cpu.cpU8(a, n)
}
Expand All @@ -186,14 +208,16 @@ func oopCPHLP(cpu *CPU) {
cpu.cpU8(a, x)
}

func oopCPIXdP(cpu *CPU, d uint8) {
func oopCPIXdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.cpU8(a, x)
}

func oopCPIYdP(cpu *CPU, d uint8) {
func oopCPIYdP(cpu *CPU) {
d := cpu.fetch()
a := cpu.AF.Hi
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
Expand All @@ -206,13 +230,15 @@ func oopINCHLP(cpu *CPU) {
cpu.Memory.Set(p, cpu.incU8(x))
}

func oopINCIXdP(cpu *CPU, d uint8) {
func oopINCIXdP(cpu *CPU) {
d := cpu.fetch()
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.Memory.Set(p, cpu.incU8(x))
}

func oopINCIYdP(cpu *CPU, d uint8) {
func oopINCIYdP(cpu *CPU) {
d := cpu.fetch()
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
cpu.Memory.Set(p, cpu.incU8(x))
Expand All @@ -224,13 +250,15 @@ func oopDECHLP(cpu *CPU) {
cpu.Memory.Set(p, cpu.decU8(x))
}

func oopDECIXdP(cpu *CPU, d uint8) {
func oopDECIXdP(cpu *CPU) {
d := cpu.fetch()
p := addrOff(cpu.IX, d)
x := cpu.Memory.Get(p)
cpu.Memory.Set(p, cpu.decU8(x))
}

func oopDECIYdP(cpu *CPU, d uint8) {
func oopDECIYdP(cpu *CPU) {
d := cpu.fetch()
p := addrOff(cpu.IY, d)
x := cpu.Memory.Get(p)
cpu.Memory.Set(p, cpu.decU8(x))
Expand Down
Loading