-
Notifications
You must be signed in to change notification settings - Fork 3
/
decode_test.go
61 lines (51 loc) · 1.69 KB
/
decode_test.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
package zog
import (
"fmt"
"testing"
)
// ZX spectrum manual has/had list of opcodes:
// http://www.worldofspectrum.org/ZXBasicManual/zxmanappa.html
func TestDecodeOddities(t *testing.T) {
testCases := []struct {
expected string
buf []byte
}{
{"SET 0,b", []byte{0xcb, 0xc0}},
{"SET 0,(IX+10),b", []byte{0xdd, 0xcb, 0x0a, 0xc0}},
{"rlc (iy+10),b", []byte{0xfd, 0xcb, 0x0a, 0x00}},
{"rlc (iy+10)", []byte{0xfd, 0xcb, 0x0a, 0x06}},
{"rlc (ix+10),b", []byte{0xdd, 0xcb, 0x0a, 0x00}},
{"rlc (ix+10)", []byte{0xdd, 0xcb, 0x0a, 0x06}},
{"INC IX", []byte{0xDD, 0x23}},
{"LD A, (IX+1)", []byte{0xFD, 0xDD, 0x7e, 0x01}},
{"EX DE, HL", []byte{0xDD, 0xeb}},
{"LD H, (IX+1)", []byte{0xDD, 0x66, 0x01}},
{"ADD IX, BC", []byte{0xDD, 0x09}},
}
for _, tc := range testCases {
testDecodeOne(t, tc.buf, tc.expected)
}
}
func TestDecodeAll(t *testing.T) {
testUtilRunAll(t, func(t *testing.T, byteForm []byte, stringForm string) {
testDecodeOne(t, byteForm, stringForm)
})
}
func testDecodeOne(t *testing.T, byteForm []byte, expected string) {
hexBuf := bufToHex(byteForm)
fmt.Printf("== Decode: buf [%s] -> string [%s]\n", hexBuf, expected)
insts, err := DecodeBytes(byteForm)
if err != nil {
t.Fatalf("Error for byte [%s]: %s (%s)", hexBuf, err, expected)
}
if len(insts) == 0 {
t.Fatalf("No instructions for byte [%s] (%s)", hexBuf, expected)
}
if len(insts) != 1 {
t.Fatalf("More than one instruction (%d) for byte [%s]: %v", len(insts), hexBuf, insts)
}
if !compareAssembly(insts[0].String(), expected) {
t.Fatalf("Wrong decode for [%s] got [%s] expected [%s]", hexBuf, insts[0].String(), expected)
}
fmt.Printf("Decoded [%s] to [%s]\n", hexBuf, insts[0].String())
}