-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopd.go
121 lines (110 loc) · 2.16 KB
/
opd.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package m68k
import "fmt"
// opAdd implements ADD (pg. 4-4)
func opAdd(c *Processor) (t *stepTrace) {
sz := c.op & 0xC0 >> 6
if sz == 3 {
return opAdda(c)
}
t = &stepTrace{
addr: c.PC,
n: 1,
op: "add",
sz: sz,
}
c.PC += 2
reg := c.op & 0x0E00 >> 9
dir := c.op & 0x0100 >> 8
if dir == 0 { // register to ea
t.src = fmt.Sprintf("D%d", reg)
switch t.sz {
case SizeByte:
var src, dst, v byte
src = byte(c.D[reg])
dst, t.dst, t.err = c.readByte(c.op)
if t.err != nil {
return
}
v = dst + src
_, t.err = c.writeByte(c.op, v)
case SizeWord:
var src, dst, v uint16
src = uint16(c.D[reg])
dst, t.dst, t.err = c.readWord(c.op)
if t.err != nil {
return
}
v = dst + src
_, t.err = c.writeWord(c.op, v)
case SizeLong:
var src, dst, v uint32
src = c.D[reg]
dst, t.dst, t.err = c.readLong(c.op)
if t.err != nil {
return
}
v = dst + src
_, t.err = c.writeLong(c.op, v)
}
} else { // ea to register
t.dst = fmt.Sprintf("D%d", reg)
switch t.sz {
case SizeByte:
var src, dst, v byte
dst = byte(c.D[reg])
src, t.src, t.err = c.readByte(c.op)
if t.err != nil {
return
}
v = dst + src
c.D[reg] = c.D[reg]&0xFFFFFF00 | uint32(v)
case SizeWord:
var src, dst, v uint16
dst = uint16(c.D[reg])
src, t.src, t.err = c.readWord(c.op)
if t.err != nil {
return
}
v = dst + src
c.D[reg] = c.D[reg]&0xFFFF0000 | uint32(v)
case SizeLong:
var src uint32
src, t.src, t.err = c.readLong(c.op)
if t.err != nil {
return
}
c.D[reg] += src
}
}
return
}
// opAdda implements ADDA (pg. 4-7)
func opAdda(c *Processor) (t *stepTrace) {
reg := c.op & 0x0E00 >> 9
t = &stepTrace{
addr: c.PC,
n: 1,
op: "adda",
sz: []uint16{SizeWord, SizeLong}[c.op&0x01>>9],
dst: fmt.Sprintf("A%d", reg),
}
c.PC += 2
switch t.sz {
case SizeWord:
var src, dst uint16
dst = uint16(c.A[reg])
src, t.src, t.err = c.readWord(c.op)
if t.err != nil {
return
}
c.A[reg] = uint32(wordToInt32(dst + src))
case SizeLong:
var src uint32
src, t.src, t.err = c.readLong(c.op)
if t.err != nil {
return
}
c.A[reg] += src
}
return
}