aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Instructions.hs (renamed from src/Commands.hs)4
-rw-r--r--src/Machine.hs10
-rw-r--r--src/Suem.hs704
3 files changed, 359 insertions, 359 deletions
diff --git a/src/Commands.hs b/src/Instructions.hs
index ea0a50d..9c2e2cb 100644
--- a/src/Commands.hs
+++ b/src/Instructions.hs
@@ -1,5 +1,5 @@
--- This module describes the semantics of machine commands.
-module Commands where
+-- This module describes the semantics of machine instructions.
+module Instructions where
import Prelude hiding (Word)
import Machine
diff --git a/src/Machine.hs b/src/Machine.hs
index 57d4c9e..4dd40d3 100644
--- a/src/Machine.hs
+++ b/src/Machine.hs
@@ -370,14 +370,14 @@ getOp 4 ar s = do
return (getMemory addr s, setMemory addr s)
getOp 5 ar s = do
pc <- readPC
- incPC
+ skipOp 2
disp <- getMemory pc 2
addr <- readA ar 4
let addr = addr + disp
return (getMemory addr s, setMemory addr s)
getOp 6 ar s = do
pc <- readPC
- incPC
+ skipOp 2
prefix <- getMemory pc 1
index <- (if testBit prefix 0 then readA else readD)
(extractBits prefix [1..3])
@@ -388,13 +388,13 @@ getOp 6 ar s = do
return (getMemory addr s, setMemory addr s)
getOp 7 2 s = do
addr <- readPC
- incPC
+ skipOp 2
disp <- getMemory addr 2
let addr = addr + disp
return (getMemory addr s, setMemory addr s)
getOp 7 3 s = do
addr <- readPC
- incPC
+ skipOp 2
prefix <- getMemory addr 1
index <- (if testBit prefix 0 then readA else readD)
(extractBits prefix [1..3])
@@ -404,7 +404,7 @@ getOp 7 3 s = do
return (getMemory addr s, setMemory addr s)
getOp 7 0 s = do
pc <- readPC
- incPC
+ skipOp 2
addr <- getMemory pc 2
return (getMemory addr s, setMemory addr s)
getOp 7 1 s = do
diff --git a/src/Suem.hs b/src/Suem.hs
index 5edd041..63e52d2 100644
--- a/src/Suem.hs
+++ b/src/Suem.hs
@@ -14,7 +14,7 @@ import Data.IP
import Network.Socket
import Numeric
import Machine
-import Commands
+import Instructions
import Utils
import Device
@@ -22,355 +22,355 @@ import Device
------------------------------------------------------------------------------
-- Main loop and command deciphering.
-doCommand :: Word16 -> Emulator ()
-doCommand 0b0000000000111100 = doORICCR
-doCommand 0b0000000001111100 = doORISR
-doCommand 0b0000001000111100 = doANDICCR
-doCommand 0b0000001001111100 = doANDISR
-doCommand 0b0000101000111100 = doEORICCR
-doCommand 0b0000101001111100 = doEORISR
-doCommand 0b0100101011111100 = doILLEGAL
-doCommand 0b0100111001110000 = doRESET
-doCommand 0b0100111001110001 = doNOP
-doCommand 0b0100111001110010 = doSTOP
-doCommand 0b0100111001110011 = doRTE
-doCommand 0b0100111001110101 = doRTS
-doCommand 0b0100111001110110 = doTRAPV
-doCommand 0b0100111001110111 = doRTR
-doCommand cmd
- | (extractBits cmd [0..7]) == 0b00000000 =
- doORI (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b00000010 =
- doANDI (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b00000100 =
- doSUBI (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b00000110 =
- doADDI (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b00001010 =
- doEORI (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b00001100 =
- doCMPI (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0000 &&
- (extractBits cmd [7]) == 0b0 &&
- (extractBits cmd [10..12]) == 0b001 =
- doMOVEP (extractBits cmd [4..6])
- (extractBits cmd [8])
- (extractBits cmd [9])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0000 &&
- (extractBits cmd [8..9]) == 0b00 =
- doBTST (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0000 &&
- (extractBits cmd [8..9]) == 0b01 =
- doBCHG (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0000 &&
- (extractBits cmd [8..9]) == 0b10 =
- doBCLR (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0000 &&
- (extractBits cmd [8..9]) == 0b11 =
- doBSET (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..1]) == 0b00 &&
- (extractBits cmd [7..9]) == 0b001 =
- doMOVEA (extractBits cmd [2..3])
- (extractBits cmd [4..6])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..1]) == 0b00 =
- doMOVE (extractBits cmd [2..3])
- (extractBits cmd [4..6])
- (extractBits cmd [7..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..9]) == 0b0100000011 =
- doSRMOVE (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..9]) == 0b0100010011 =
- doMOVECCR (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..9]) == 0b0100011011 =
- doMOVESR (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b01000000 =
- doNEGX (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b01000010 =
- doCLR (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b01000100 =
- doNEG (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b01000110 =
- doNOT (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..8]) == 0b010010001 &&
- (extractBits cmd [10..12]) == 0b000 =
- doEXT (extractBits cmd [9])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..9]) == 0b0100100000 =
- doNBCD (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..12]) == 0b0100100001000 =
- doSWAP (extractBits cmd [13..15])
- | (extractBits cmd [0..9]) == 0b0100100001 =
- doPEA (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..9]) == 0b0100100011 =
- doTAS (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b01001010 =
- doTST (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..11]) == 0b010011100100 =
- doTRAP (extractBits cmd [12..15])
- | (extractBits cmd [0..12]) == 0b0100111001010 =
- doLINK (extractBits cmd [13..15])
- | (extractBits cmd [0..12]) == 0b0100111001011 =
- doUNLK (extractBits cmd [13..15])
- | (extractBits cmd [0..11]) == 0b010011100110 =
- doMOVEUSP (extractBits cmd [12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..9]) == 0b0100111010 =
- doJSR (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..9]) == 0b0100111011 =
- doJMP (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..4]) == 0b01001 &&
- (extractBits cmd [6..8]) == 0b001 =
- doMOVEM (extractBits cmd [5])
- (extractBits cmd [9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0100 &&
- (extractBits cmd [7..9]) == 0b111 =
- doLEA (extractBits cmd [4..6])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0100 &&
- (extractBits cmd [7..9]) == 0b110 =
- doCHK (extractBits cmd [4..6])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0101 &&
- (extractBits cmd [8..12]) == 0b11001 =
- doDBcc (extractBits cmd [4..7])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0101 &&
- (extractBits cmd [8..9]) == 0b11 =
- doScc (extractBits cmd [4..7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0101 &&
- (extractBits cmd [7]) == 0b0 =
- doADDQ (extractBits cmd [4..6])
- (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0101 &&
- (extractBits cmd [7]) == 0b1 =
- doSUBQ (extractBits cmd [4..6])
- (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..7]) == 0b01100000 =
- doBRA (extractBits cmd [8..15])
- | (extractBits cmd [0..7]) == 0b01100000 =
- doBSR (extractBits cmd [8..15])
- | (extractBits cmd [0..3]) == 0b0110 =
- doBcc (extractBits cmd [4..7])
- (extractBits cmd [8..15])
- | (extractBits cmd [0..3]) == 0b0111 &&
- (extractBits cmd [7]) == 0b0 =
- doMOVEQ (extractBits cmd [4..6])
- (extractBits cmd [8..15])
- | (extractBits cmd [0..3]) == 0b1000 &&
- (extractBits cmd [7..9]) == 0b011 =
- doDIVU (extractBits cmd [4..6])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1000 &&
- (extractBits cmd [7..9]) == 0b111 =
- doDIVS (extractBits cmd [4..6])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1000 &&
- (extractBits cmd [7..11]) == 0b10000 =
- doSBCD (extractBits cmd [4..6])
- (extractBits cmd [12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1000 =
- doOR (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1001 &&
- (extractBits cmd [8..9]) == 0b11 =
- doSUBA (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1001 &&
- (extractBits cmd [7]) == 0b1 &&
- (extractBits cmd [10..11]) == 0b00 =
- doSUBX (extractBits cmd [4..6])
- (extractBits cmd [8..9])
- (extractBits cmd [12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1001 =
- doSUB (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1011 &&
- (extractBits cmd [8..9]) == 0b11 =
- doCMPA (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1011 &&
- (extractBits cmd [7]) == 0b0 =
- doCMP (extractBits cmd [4..6])
- (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1011 &&
- (extractBits cmd [7]) == 0b1 &&
- (extractBits cmd [10..12]) == 0b001 =
- doCMPM (extractBits cmd [4..6])
- (extractBits cmd [8..9])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1011 &&
- (extractBits cmd [7]) == 0b1 =
- doEOR (extractBits cmd [4..6])
- (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1100 &&
- (extractBits cmd [7..9]) == 0b011 =
- doMULU (extractBits cmd [4..6])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1100 &&
- (extractBits cmd [7..9]) == 0b111 =
- doMULS (extractBits cmd [4..6])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1100 &&
- (extractBits cmd [7..11]) == 0b10000 =
- doABCD (extractBits cmd [4..6])
- (extractBits cmd [12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1100 &&
- (extractBits cmd [7]) == 0b1 &&
- (extractBits cmd [10..11]) == 0b00 =
- doEXG (extractBits cmd [4..6])
- (extractBits cmd [8..9])
- (extractBits cmd [12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1100 =
- doAND (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1101 &&
- (extractBits cmd [8..9]) == 0b11 =
- doADDA (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1101 &&
- (extractBits cmd [7]) == 0b1 &&
- (extractBits cmd [10..11]) == 0b00 =
- doADDX (extractBits cmd [4..6])
- (extractBits cmd [8..9])
- (extractBits cmd [12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1101 =
- doADD (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [8..9])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..6]) == 0b1110000 &&
- (extractBits cmd [8..9]) == 0b11 =
- doASD (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..6]) == 0b1110001 &&
- (extractBits cmd [8..9]) == 0b11 =
- doLSD (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..6]) == 0b1110010 &&
- (extractBits cmd [8..9]) == 0b11 =
- doROXd (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..6]) == 0b1110011 &&
- (extractBits cmd [8..9]) == 0b11 =
- doROd (extractBits cmd [7])
- (extractBits cmd [10..12])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1110 &&
- (extractBits cmd [11..12]) == 0b00 =
- doADSR (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [8..9])
- (extractBits cmd [10])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1110 &&
- (extractBits cmd [11..12]) == 0b01 =
- doLSDR (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [8..9])
- (extractBits cmd [10])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1110 &&
- (extractBits cmd [11..12]) == 0b10 =
- doROXdR (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [8..9])
- (extractBits cmd [10])
- (extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b1110 &&
- (extractBits cmd [11..12]) == 0b11 =
- doROdR (extractBits cmd [4..6])
- (extractBits cmd [7])
- (extractBits cmd [8..9])
- (extractBits cmd [10])
- (extractBits cmd [13..15])
+doInstruction :: Word16 -> Emulator ()
+doInstruction 0b0000000000111100 = doORICCR
+doInstruction 0b0000000001111100 = doORISR
+doInstruction 0b0000001000111100 = doANDICCR
+doInstruction 0b0000001001111100 = doANDISR
+doInstruction 0b0000101000111100 = doEORICCR
+doInstruction 0b0000101001111100 = doEORISR
+doInstruction 0b0100101011111100 = doILLEGAL
+doInstruction 0b0100111001110000 = doRESET
+doInstruction 0b0100111001110001 = doNOP
+doInstruction 0b0100111001110010 = doSTOP
+doInstruction 0b0100111001110011 = doRTE
+doInstruction 0b0100111001110101 = doRTS
+doInstruction 0b0100111001110110 = doTRAPV
+doInstruction 0b0100111001110111 = doRTR
+doInstruction opcode
+ | (extractBits opcode [0..7]) == 0b00000000 =
+ doORI (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b00000010 =
+ doANDI (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b00000100 =
+ doSUBI (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b00000110 =
+ doADDI (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b00001010 =
+ doEORI (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b00001100 =
+ doCMPI (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0000 &&
+ (extractBits opcode [7]) == 0b0 &&
+ (extractBits opcode [10..12]) == 0b001 =
+ doMOVEP (extractBits opcode [4..6])
+ (extractBits opcode [8])
+ (extractBits opcode [9])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0000 &&
+ (extractBits opcode [8..9]) == 0b00 =
+ doBTST (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0000 &&
+ (extractBits opcode [8..9]) == 0b01 =
+ doBCHG (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0000 &&
+ (extractBits opcode [8..9]) == 0b10 =
+ doBCLR (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0000 &&
+ (extractBits opcode [8..9]) == 0b11 =
+ doBSET (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..1]) == 0b00 &&
+ (extractBits opcode [7..9]) == 0b001 =
+ doMOVEA (extractBits opcode [2..3])
+ (extractBits opcode [4..6])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..1]) == 0b00 =
+ doMOVE (extractBits opcode [2..3])
+ (extractBits opcode [4..6])
+ (extractBits opcode [7..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..9]) == 0b0100000011 =
+ doSRMOVE (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..9]) == 0b0100010011 =
+ doMOVECCR (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..9]) == 0b0100011011 =
+ doMOVESR (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b01000000 =
+ doNEGX (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b01000010 =
+ doCLR (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b01000100 =
+ doNEG (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b01000110 =
+ doNOT (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..8]) == 0b010010001 &&
+ (extractBits opcode [10..12]) == 0b000 =
+ doEXT (extractBits opcode [9])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..9]) == 0b0100100000 =
+ doNBCD (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..12]) == 0b0100100001000 =
+ doSWAP (extractBits opcode [13..15])
+ | (extractBits opcode [0..9]) == 0b0100100001 =
+ doPEA (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..9]) == 0b0100100011 =
+ doTAS (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b01001010 =
+ doTST (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..11]) == 0b010011100100 =
+ doTRAP (extractBits opcode [12..15])
+ | (extractBits opcode [0..12]) == 0b0100111001010 =
+ doLINK (extractBits opcode [13..15])
+ | (extractBits opcode [0..12]) == 0b0100111001011 =
+ doUNLK (extractBits opcode [13..15])
+ | (extractBits opcode [0..11]) == 0b010011100110 =
+ doMOVEUSP (extractBits opcode [12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..9]) == 0b0100111010 =
+ doJSR (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..9]) == 0b0100111011 =
+ doJMP (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..4]) == 0b01001 &&
+ (extractBits opcode [6..8]) == 0b001 =
+ doMOVEM (extractBits opcode [5])
+ (extractBits opcode [9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0100 &&
+ (extractBits opcode [7..9]) == 0b111 =
+ doLEA (extractBits opcode [4..6])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0100 &&
+ (extractBits opcode [7..9]) == 0b110 =
+ doCHK (extractBits opcode [4..6])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0101 &&
+ (extractBits opcode [8..12]) == 0b11001 =
+ doDBcc (extractBits opcode [4..7])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0101 &&
+ (extractBits opcode [8..9]) == 0b11 =
+ doScc (extractBits opcode [4..7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0101 &&
+ (extractBits opcode [7]) == 0b0 =
+ doADDQ (extractBits opcode [4..6])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b0101 &&
+ (extractBits opcode [7]) == 0b1 =
+ doSUBQ (extractBits opcode [4..6])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..7]) == 0b01100000 =
+ doBRA (extractBits opcode [8..15])
+ | (extractBits opcode [0..7]) == 0b01100000 =
+ doBSR (extractBits opcode [8..15])
+ | (extractBits opcode [0..3]) == 0b0110 =
+ doBcc (extractBits opcode [4..7])
+ (extractBits opcode [8..15])
+ | (extractBits opcode [0..3]) == 0b0111 &&
+ (extractBits opcode [7]) == 0b0 =
+ doMOVEQ (extractBits opcode [4..6])
+ (extractBits opcode [8..15])
+ | (extractBits opcode [0..3]) == 0b1000 &&
+ (extractBits opcode [7..9]) == 0b011 =
+ doDIVU (extractBits opcode [4..6])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1000 &&
+ (extractBits opcode [7..9]) == 0b111 =
+ doDIVS (extractBits opcode [4..6])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1000 &&
+ (extractBits opcode [7..11]) == 0b10000 =
+ doSBCD (extractBits opcode [4..6])
+ (extractBits opcode [12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1000 =
+ doOR (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1001 &&
+ (extractBits opcode [8..9]) == 0b11 =
+ doSUBA (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1001 &&
+ (extractBits opcode [7]) == 0b1 &&
+ (extractBits opcode [10..11]) == 0b00 =
+ doSUBX (extractBits opcode [4..6])
+ (extractBits opcode [8..9])
+ (extractBits opcode [12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1001 =
+ doSUB (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1011 &&
+ (extractBits opcode [8..9]) == 0b11 =
+ doCMPA (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1011 &&
+ (extractBits opcode [7]) == 0b0 =
+ doCMP (extractBits opcode [4..6])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1011 &&
+ (extractBits opcode [7]) == 0b1 &&
+ (extractBits opcode [10..12]) == 0b001 =
+ doCMPM (extractBits opcode [4..6])
+ (extractBits opcode [8..9])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1011 &&
+ (extractBits opcode [7]) == 0b1 =
+ doEOR (extractBits opcode [4..6])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1100 &&
+ (extractBits opcode [7..9]) == 0b011 =
+ doMULU (extractBits opcode [4..6])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1100 &&
+ (extractBits opcode [7..9]) == 0b111 =
+ doMULS (extractBits opcode [4..6])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1100 &&
+ (extractBits opcode [7..11]) == 0b10000 =
+ doABCD (extractBits opcode [4..6])
+ (extractBits opcode [12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1100 &&
+ (extractBits opcode [7]) == 0b1 &&
+ (extractBits opcode [10..11]) == 0b00 =
+ doEXG (extractBits opcode [4..6])
+ (extractBits opcode [8..9])
+ (extractBits opcode [12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1100 =
+ doAND (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1101 &&
+ (extractBits opcode [8..9]) == 0b11 =
+ doADDA (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1101 &&
+ (extractBits opcode [7]) == 0b1 &&
+ (extractBits opcode [10..11]) == 0b00 =
+ doADDX (extractBits opcode [4..6])
+ (extractBits opcode [8..9])
+ (extractBits opcode [12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1101 =
+ doADD (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..6]) == 0b1110000 &&
+ (extractBits opcode [8..9]) == 0b11 =
+ doASD (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..6]) == 0b1110001 &&
+ (extractBits opcode [8..9]) == 0b11 =
+ doLSD (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..6]) == 0b1110010 &&
+ (extractBits opcode [8..9]) == 0b11 =
+ doROXd (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..6]) == 0b1110011 &&
+ (extractBits opcode [8..9]) == 0b11 =
+ doROd (extractBits opcode [7])
+ (extractBits opcode [10..12])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1110 &&
+ (extractBits opcode [11..12]) == 0b00 =
+ doADSR (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1110 &&
+ (extractBits opcode [11..12]) == 0b01 =
+ doLSDR (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1110 &&
+ (extractBits opcode [11..12]) == 0b10 =
+ doROXdR (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10])
+ (extractBits opcode [13..15])
+ | (extractBits opcode [0..3]) == 0b1110 &&
+ (extractBits opcode [11..12]) == 0b11 =
+ doROdR (extractBits opcode [4..6])
+ (extractBits opcode [7])
+ (extractBits opcode [8..9])
+ (extractBits opcode [10])
+ (extractBits opcode [13..15])
| otherwise = do
pc <- readPC
sr <- readSR
@@ -413,8 +413,8 @@ doCommand cmd
runMachine :: Emulator ()
runMachine = forM_ [0..] $ \_ -> do
pc <- with pc $ \pc -> readIORef pc
- cmd <- getWord $ fromIntegral pc
- doCommand cmd
+ opcode <- getWord $ fromIntegral pc
+ doInstruction opcode
checkInteruptsFromDevices