-
Notifications
You must be signed in to change notification settings - Fork 1
/
instr_mov16.go
104 lines (87 loc) · 1.31 KB
/
instr_mov16.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package i8080
import ()
/*
This file:
LXI
SHLD, LHLD
POP, PUSH
XTHL
SPHL
XCHG
*/
// LXI: 0x01, 0x11, 0x21, 0x31
func instrLXI(op uint8, c *CPU) uint64 {
reg := insArg2(op)
val := insArg16(c)
switch reg {
case R4:
c.SP = val
default:
c.SetR16(reg, val)
}
return 10
}
// SHLD: 0x22
func instrSHLD(op uint8, c *CPU) uint64 {
addr := insArg16(c)
c.Write16(addr, c.HL())
return 16
}
// LHLD: 0x2A
func instrLHLD(op uint8, c *CPU) uint64 {
addr := insArg16(c)
c.SetHL(c.Read16(addr))
return 16
}
// POP: 0xC1, 0xD1, 0xE1, 0xF1
func instrPOP(op uint8, c *CPU) uint64 {
reg := insArg2(op)
val := c.Pop()
switch reg {
case BC:
c.SetBC(val)
case DE:
c.SetDE(val)
case HL:
c.SetHL(val)
case R4:
c.SetPSW(val)
}
return 10
}
// PUSH: 0xC5, 0xD5, 0xE5, 0xF5
func instrPUSH(op uint8, c *CPU) uint64 {
reg := insArg2(op)
var val uint16
switch reg {
case BC:
val = c.BC()
case DE:
val = c.DE()
case HL:
val = c.HL()
case R4:
val = c.PSW()
}
c.Push(val)
return 11
}
// XTHL: 0xE3
func instrXTHL(op uint8, c *CPU) uint64 {
newHL := c.Pop()
c.Push(c.HL())
c.SetHL(newHL)
return 18
}
// SPHL: 0xF9
func instrSPHL(op uint8, c *CPU) uint64 {
c.SP = c.HL()
return 5
}
// XCHG: 0xEB
func instrXCHG(op uint8, c *CPU) uint64 {
newHL := c.HL()
c.SetHL(c.DE())
c.SetDE(newHL)
return 5
}