aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Suem.hs172
1 files changed, 135 insertions, 37 deletions
diff --git a/src/Suem.hs b/src/Suem.hs
index cbc8361..1e43783 100644
--- a/src/Suem.hs
+++ b/src/Suem.hs
@@ -58,8 +58,8 @@ doCommand cmd
doCMPI (extractBits cmd [8..9])
(extractBits cmd [10..12])
(extractBits cmd [13..15])
- | (extractBits cmd [0..3]) == 0b0000 &&
- (extractBits cmd [7]) == 0b0 &&
+ | (extractBits cmd [0..3]) == 0b0000 &&
+ (extractBits cmd [7]) == 0b0 &&
(extractBits cmd [10..12]) == 0b001 =
doMOVEP (extractBits cmd [4..6])
(extractBits cmd [8])
@@ -101,56 +101,153 @@ doCommand cmd
(extractBits cmd [7..9])
(extractBits cmd [10..12])
(extractBits cmd [13..15])
- | otherwise = error "Bad command."
--- doCommand [0,1,0,0,0,0,0,0, 1,1,a,b,c,x,y,z] = doSRMOVE [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,0,1,0,0, 1,1,a,b,c,x,y,z] = doMOVECCR [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,0,1,1,0, 1,1,a,b,c,x,y,z] = doMOVESR [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,0,0,0,0, i,j,a,b,c,x,y,z] = doNEGX [i,j] [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,0,0,1,0, i,j,a,b,c,x,y,z] = doCLR [i,j] [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,0,1,0,0, i,j,a,b,c,x,y,z] = doNEG [i,j] [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,0,1,1,0, i,j,a,b,c,x,y,z] = doNOT [i,j] [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,1,0,0,0, 1,i,0,0,0,x,y,z] = doEXT [i] [x,y,z]
--- doCommand [0,1,0,0,1,0,0,0, 0,0,a,b,c,x,y,z] = doNBCD [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,1,0,0,0, 0,1,0,0,0,x,y,z] = doSWAP [x,y,z]
--- doCommand [0,1,0,0,1,0,0,0, 0,1,a,b,c,x,y,z] = doPEA [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,1,0,1,0, 1,1,a,b,c,x,y,z] = doTAS [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,1,0,1,0, i,j,a,b,c,x,y,z] = doTST [i,j] [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,1,1,1,0, 0,1,0,0,a,b,c,d] = doTRAP [a,b,c,d]
--- doCommand [0,1,0,0,1,1,1,0, 0,1,0,1,0,x,y,z] = doLINK [x,y,z]
--- doCommand [0,1,0,0,1,1,1,0, 0,1,0,1,1,x,y,z] = doUNLK [x,y,z]
--- doCommand [0,1,0,0,1,1,1,0, 0,1,1,0,t,x,y,z] = doMOVEUSP [t] [x,y,z]
--- doCommand [0,1,0,0,1,1,1,0, 1,0,a,b,c,x,y,z] = doJSR [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,1,1,1,0, 1,1,a,b,c,x,y,z] = doJMP [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,1,t,0,0, 1,i,a,b,c,x,y,z] = doMOVEM [t] [i] [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,u,v,w,1, 1,1,a,b,c,x,y,z] = doLEA [u,v,w] [a,b,c] [x,y,z]
--- doCommand [0,1,0,0,u,v,w,1, 1,0,a,b,c,x,y,z] = doCHK [u,v,w] [a,b,c] [x,y,z]
--- doCommand [0,1,0,1,u,v,w,t, 1,1,0,0,1,x,y,z] = doDBcc [u,v,w,t] [x,y,z]
--- doCommand [0,1,0,1,u,v,w,t, 1,1,a,b,c,x,y,z] = doScc [u,v,w,t] [a,b,c] [x,y,z]
--- doCommand [0,1,0,1,u,v,w,0, i,j,a,b,c,x,y,z] = doADDQ [u,v,w] [i,j] [a,b,c] [x,y,z]
--- doCommand [0,1,0,1,u,v,w,1, i,j,a,b,c,x,y,z] = doSUBQ [u,v,w] [i,j] [a,b,c] [x,y,z]
--- doCommand [0,1,1,0,0,0,0,0, a,b,c,d,e,f,g,h] = doBRA [a,b,c,d,e,f,g,h]
--- doCommand [0,1,1,0,0,0,0,1, a,b,c,d,e,f,g,h] = doBSR [a,b,c,d,e,f,g,h]
--- doCommand [0,1,1,0,u,v,w,t, a,b,c,d,e,f,g,h] = doBcc [u,v,w,t] [a,b,c,d,e,f,g,h]
--- doCommand [0,1,1,1,u,v,w,0, a,b,c,d,e,f,g,h] = doMOVEQ [u,v,w] [a,b,c,d,e,f,g,h]
--- doCommand [1,0,0,0,u,v,w,0, 1,1,a,b,c,x,y,z] = doDIVU [u,v,w] [a,b,c] [x,y,z]
--- doCommand [1,0,0,0,u,v,w,1, 1,1,a,b,c,x,y,z] = doDIVS [u,v,w] [a,b,c] [x,y,z]
--- doCommand [1,0,0,0,u,v,w,1, 0,0,0,0,t,x,y,z] = doSBCD [u,v,w] [t] [x,y,z]
--- doCommand [1,0,0,0,u,v,w,t, i,j,a,b,c,x,y,z] = doOR [u,v,w] [t] [i,j] [a,b,c] [x,y,z]
+ | (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])
-- doCommand [1,0,0,1,u,v,w,t, 1,1,a,b,c,x,y,z] = doSUBA [u,v,w] [t] [a,b,c] [x,y,z]
-- doCommand [1,0,0,1,u,v,w,1, i,j,0,0,t,x,y,z] = doSUBX [u,v,w] [i,j] [t] [x,y,z]
-- doCommand [1,0,0,1,u,v,w,t, i,j,a,b,c,x,y,z] = doSUB [u,v,w] [t] [i,j] [a,b,c] [x,y,z]
+
-- doCommand [1,0,1,1,u,v,w,t, 1,1,a,b,c,x,y,z] = doCMPA [u,v,w] [t] [a,b,c] [x,y,z]
-- doCommand [1,0,1,1,u,v,w,0, i,j,a,b,c,x,y,z] = doCMP [u,v,w] [i,j] [a,b,c] [x,y,z]
-- doCommand [1,0,1,1,u,v,w,1, i,j,0,0,1,x,y,z] = doCMPM [u,v,w] [i,j] [x,y,z]
-- doCommand [1,0,1,1,u,v,w,1, i,j,a,b,c,x,y,z] = doEOR [u,v,w] [i,j] [a,b,c] [x,y,z]
+
-- doCommand [1,1,0,0,u,v,w,0, 1,1,a,b,c,x,y,z] = doMULU [u,v,w] [a,b,c] [x,y,z]
-- doCommand [1,1,0,0,u,v,w,1, 1,1,a,b,c,x,y,z] = doMULS [u,v,w] [a,b,c] [x,y,z]
-- doCommand [1,1,0,0,u,v,w,1, 0,0,0,0,t,x,y,z] = doABCD [u,v,w] [t] [x,y,z]
-- doCommand [1,1,0,0,u,v,w,1, i,j,0,0,t,x,y,z] = doEXG [u,v,w] [i,j] [t] [x,y,z]
-- doCommand [1,1,0,0,u,v,w,t, i,j,a,b,c,x,y,z] = doAND [u,v,w] [t] [i,j] [a,b,c] [x,y,z]
+
-- doCommand [1,1,0,1,u,v,w,t, 1,1,a,b,c,x,y,z] = doADDA [u,v,w] [t] [a,b,c] [x,y,z]
-- doCommand [1,1,0,1,u,v,w,1, i,j,0,0,t,x,y,z] = doADDX [u,v,w] [i,j] [t] [x,y,z]
-- doCommand [1,1,0,1,u,v,w,t, i,j,a,b,c,x,y,z] = doADD [u,v,w] [t] [i,j] [a,b,c] [x,y,z]
+
-- doCommand [1,1,1,0,0,0,0,t, 1,1,a,b,c,x,y,z] = doASD [t] [a,b,c] [x,y,z]
-- doCommand [1,1,1,0,0,0,1,t, 1,1,a,b,c,x,y,z] = doLSD [t] [a,b,c] [x,y,z]
-- doCommand [1,1,1,0,0,1,0,t, 1,1,a,b,c,x,y,z] = doROXd [t] [a,b,c] [x,y,z]
@@ -159,6 +256,7 @@ doCommand cmd
-- doCommand [1,1,1,0,u,v,w,t, i,j,a,0,1,x,y,z] = doLSDR [u,v,w] [t] [i,j] [a] [x,y,z]
-- doCommand [1,1,1,0,u,v,w,t, i,j,a,1,0,x,y,z] = doROXdR [u,v,w] [t] [i,j] [a] [x,y,z]
-- doCommand [1,1,1,0,u,v,w,t, i,j,a,1,1,x,y,z] = doROdR [u,v,w] [t] [i,j] [a] [x,y,z]
+ | otherwise = error "Bad command."
runMachine :: Emulator ()
runMachine = forM_ [0..] $ \_ -> do