diff options
Diffstat (limited to 'src')
-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" |