aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2021-04-03 16:14:03 +0300
committerAleksey Veresov <aleksey@veresov.pro>2021-04-03 16:14:03 +0300
commit3d4e47bb5a290c638d61ddf6dcfdf1101f6bebae (patch)
tree8605d81d04b01f5494e11caca6341eea8090a650 /src
parent50570477dc1cffecc597dda663ab4738fe2660e9 (diff)
downloadsuem-3d4e47bb5a290c638d61ddf6dcfdf1101f6bebae.tar
suem-3d4e47bb5a290c638d61ddf6dcfdf1101f6bebae.tar.xz
suem-3d4e47bb5a290c638d61ddf6dcfdf1101f6bebae.zip
Haskell is awesome.
Diffstat (limited to 'src')
-rw-r--r--src/Instructions.hs40
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"