aboutsummaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-02-10 12:42:31 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-02-10 12:42:31 +0100
commit6779ce8c51ed965085805cd5c1b1f7a0e7833ffe (patch)
treeca87327d68e0b3d075f2c465793105822c1edab8 /parse.go
parentf686063b66c97fa65e556c8c56b9beadc6b35eca (diff)
replace expand with lookup map
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go12
1 files changed, 4 insertions, 8 deletions
diff --git a/parse.go b/parse.go
index 3a6bd8d..a117f93 100644
--- a/parse.go
+++ b/parse.go
@@ -75,8 +75,8 @@ func newALU(v uint16) ALU {
TtoN: v&(1<<7) != 0,
TtoR: v&(1<<6) != 0,
NtoAtT: v&(1<<5) != 0,
- Rdir: expand((v >> 2) & 3),
- Ddir: expand(v & 3),
+ Rdir: expand[(v>>2)&3],
+ Ddir: expand[v&3],
}
}
@@ -101,12 +101,8 @@ func (v ALU) value() uint16 {
func (v ALU) compile() uint16 { return v.value() | (3 << 13) }
-func expand(v uint16) int8 {
- if v&2 != 0 {
- v |= 0xfc
- }
- return int8(v)
-}
+// expand 2 bit unsigned to 8 bit signed
+var expand = map[uint16]int8{0: 0, 1: 1, 2: -2, 3: -1}
const (
opT = iota // 0