From bc1a7a271ba5a3f971e9dbed774b01b43af2642e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 16 Jan 2018 23:59:44 +0100 Subject: ... --- core.go | 21 ++++++++++----------- core_test.go | 6 +++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/core.go b/core.go index 9a82b36..c3108b6 100644 --- a/core.go +++ b/core.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/binary" + "errors" "fmt" "io/ioutil" ) @@ -39,7 +40,7 @@ func (c *Core) Reset() { func (c *Core) LoadBytes(data []byte) error { size := len(data) >> 1 if size >= memSize { - return fmt.Errorf("too big") + return errors.New("too big") } return binary.Read(bytes.NewReader(data), binary.LittleEndian, c.memory[:size]) } @@ -136,6 +137,11 @@ func (c *Core) Eval(ins Instruction) { } } +var boolValue = map[bool]uint16{ + false: 0, + true: ^uint16(0), +} + func (c *Core) newST0(opcode uint16) uint16 { T, N, R := c.st0, c.d.peek(), c.r.peek() switch opcode { @@ -154,9 +160,9 @@ func (c *Core) newST0(opcode uint16) uint16 { case opNotT: // ~T return ^T case opNeqT: // N==T - return bool2int(N == T) + return boolValue[N == T] case opNleT: // N>T return N >> (T & 0xf) case opTminus1: // T-1 @@ -170,15 +176,8 @@ func (c *Core) newST0(opcode uint16) uint16 { case opDepth: // depth (dsp) return (c.r.depth() << 8) | c.d.depth() case opNuleT: // Nu