summaryrefslogtreecommitdiff
path: root/fig-emulator-gb/src/Fig/Emulator/GB/Component/Interrupt.hs
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-05-07 14:21:13 -0400
committerLLLL Colonq <llll@colonq>2024-05-07 14:21:13 -0400
commita81c92dc2cdff02c55fdc197d943bc7a35c64be5 (patch)
treec5c4039f1e81d8290859656f3a0d306e6af62053 /fig-emulator-gb/src/Fig/Emulator/GB/Component/Interrupt.hs
parent82d4f5c55bdb1f160fe558bd9e413b726e36541b (diff)
fig-emulator-gb: Fix space leak
Diffstat (limited to 'fig-emulator-gb/src/Fig/Emulator/GB/Component/Interrupt.hs')
-rw-r--r--fig-emulator-gb/src/Fig/Emulator/GB/Component/Interrupt.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/fig-emulator-gb/src/Fig/Emulator/GB/Component/Interrupt.hs b/fig-emulator-gb/src/Fig/Emulator/GB/Component/Interrupt.hs
new file mode 100644
index 0000000..ec5540c
--- /dev/null
+++ b/fig-emulator-gb/src/Fig/Emulator/GB/Component/Interrupt.hs
@@ -0,0 +1,33 @@
+module Fig.Emulator.GB.Component.Interrupt where
+
+import Fig.Prelude
+
+import Fig.Emulator.GB.Utils
+import Fig.Emulator.GB.Bus
+
+newtype InterruptError = InterruptError Text
+ deriving Show
+instance Exception InterruptError
+instance Pretty InterruptError where
+ pretty (InterruptError b) = mconcat
+ [ "interrupt error: "
+ , b
+ ]
+
+compInterrupt :: (MonadIO m, MonadThrow m) => Component m
+compInterrupt = Component
+ { compState = ()
+ , compMatches = \a -> a == 0xff0f || a == 0xffff
+ , compUpdate = \s _ -> pure s
+ , compWrite = \s (Addr a) v -> do
+ case a of
+ 0xff0f -> do
+ -- log $ "set IF:" <> show8 v
+ pure ()
+ 0xffff -> do
+ -- log $ "set IE:" <> show8 v
+ pure ()
+ _ -> throwM . InterruptError $ "write to invalid address: " <> pretty (Addr a)
+ pure s
+ , compRead = \_ _ -> pure 0x00
+ }