diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-04-03 16:14:03 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-04-03 16:14:03 +0300 |
commit | 3d4e47bb5a290c638d61ddf6dcfdf1101f6bebae (patch) | |
tree | 8605d81d04b01f5494e11caca6341eea8090a650 | |
parent | 50570477dc1cffecc597dda663ab4738fe2660e9 (diff) | |
download | suem-3d4e47bb5a290c638d61ddf6dcfdf1101f6bebae.tar suem-3d4e47bb5a290c638d61ddf6dcfdf1101f6bebae.tar.xz suem-3d4e47bb5a290c638d61ddf6dcfdf1101f6bebae.zip |
Haskell is awesome.
-rw-r--r-- | src/Instructions.hs | 40 |
1 files 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" |