From 3d4e47bb5a290c638d61ddf6dcfdf1101f6bebae Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Sat, 3 Apr 2021 16:14:03 +0300 Subject: Haskell is awesome. --- src/Instructions.hs | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/Instructions.hs b/src/Instructions.hs index ccd12f6..320c93a 100644 --- a/src/Instructions.hs +++ b/src/Instructions.hs @@ -201,35 +201,23 @@ doBRA disp = do doBSR :: Int -> Emulator () doBSR _ = error "BSR" -doBcc :: Int -> Int -> Emulator () --- NE -doBcc 6 0 = do - incPC - pc <- readPC - zf <- isZero - disp <- getMemory pc 2 - let real_disp = if not zf then disp else 2 - writePC (pc + (fromIntegral real_disp)) -doBcc 6 disp = do - incPC - pc <- readPC +checkBccCondition :: Int -> Emulator Bool +-- BNE +checkBccCondition 6 = do zf <- isZero - let real_disp = if not zf then disp else 0 - writePC (pc + (fromIntegral real_disp)) --- EQ -doBcc 7 0 = do - incPC - pc <- readPC - zf <- isZero - disp <- getMemory pc 2 - let real_disp = if zf then disp else 2 - writePC (pc + (fromIntegral real_disp)) -doBcc 7 disp = do + return $ not zf +-- BEQ +checkBccCondition 7 = isZero + +doBcc :: Int -> Int -> Emulator () +doBcc cc disp = do incPC pc <- readPC - zf <- isZero - let real_disp = if zf then disp else 0 - writePC (pc + (fromIntegral real_disp)) + check <- checkBccCondition cc + the_disp <- if disp == 0 + then if check then getMemory pc 2 else return 2 + else if check then return $ fromIntegral disp else return 0 + writePC $ pc + the_disp doMOVEQ :: Int -> Int -> Emulator () doMOVEQ _ _ = error "MOVEQ" -- cgit v1.2.3