-
Notifications
You must be signed in to change notification settings - Fork 1
/
dispatch.go
78 lines (73 loc) · 1.72 KB
/
dispatch.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
package m68k
// A stepFunc is a function that executes a single processor instruction and
// returns trace information. Any errors should be returned by Processor.err.
type stepFunc func(*Processor) *stepTrace
// An opcode maps an opcode to a stepFunc. Opcodes are matched by applying each
// mask and comparing the result to the base.
type opcode struct {
base, mask uint16
f stepFunc
}
var opcodes = [][]opcode{
[]opcode{ /* 0x0... */
{0x0000, 0xFF00, opOri},
{0x0100, 0xF1C0, opBtst},
{0x0200, 0xFF00, opAndi},
{0x0400, 0xFF00, opSubi},
{0x0600, 0xFF00, opAddi},
{0x0A00, 0xFF00, opEori},
},
[]opcode{ /* 0x1... */
{0x1000, 0xF000, opMove},
},
[]opcode{ /* 0x2... */
{0x2000, 0xF000, opMove},
},
[]opcode{ /* 0x3... */
{0x3000, 0xF000, opMove},
},
[]opcode{ /* 0x4... */
{0x41C0, 0xF1C0, opLea},
{0x4200, 0xFF00, opClr},
{0x46C0, 0xFFC0, opMoveToSr},
{0x4880, 0xFB80, opMovem},
{0x4A00, 0xFF00, opTst},
{0x4E40, 0xFFF0, opTrap},
{0x4E60, 0xFFF0, opMoveUsp},
{0x4E72, 0xFFFF, opStop},
{0x4E75, 0xFFFF, opRts},
{0x4E80, 0xFFC0, opJsr},
},
[]opcode{ /* 0x5... */
{0x50C8, 0xF0F8, opDBcc},
},
[]opcode{ /* 0x6... */
{0x6000, 0xF000, opBcc},
},
[]opcode{ /* 0x7... */
{0x7000, 0xF100, opMoveq},
},
[]opcode{ /* 0x8... */ },
[]opcode{ /* 0x9... */ },
[]opcode{ /* 0xA... */ },
[]opcode{ /* 0xB... */
{0xB000, 0xF100, opCmp},
},
[]opcode{ /* 0xC... */
{0xC100, 0xF1F0, opAbcd},
},
[]opcode{ /* 0xD... */
{0xD000, 0xF000, opAdd},
},
[]opcode{ /* 0xE... */ },
[]opcode{ /* 0xF... */ },
}
func dispatch(op uint16) stepFunc {
g := op >> 12
for i := 0; i < len(opcodes[g]); i++ {
if op&opcodes[g][i].mask == opcodes[g][i].base {
return opcodes[g][i].f
}
}
return nil
}