blob: 3912e5dc74dc8e4e78f8fc5ca9cc53367d9bfc4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
module Fig.Emulator.GB.Component.Serial where
import Fig.Prelude
import GHC.IO.Handle (hPutChar)
import Data.Char (chr)
import Fig.Emulator.GB.Utils
import Fig.Emulator.GB.Bus
newtype SerialError = SerialError Text
deriving Show
instance Exception SerialError
instance Pretty SerialError where
pretty (SerialError b) = mconcat
[ "serial error: "
, b
]
compSerial :: Maybe Handle -> Component
compSerial mh = Component
{ compState = ()
, compMatches = (== 0xff01)
, compUpdate = \s _ -> pure s
, compWrite = \s _ v -> do
log $ mconcat
[ "wrote serial byte: ", tshow $ chr $ fromIntegral v
]
case mh of
Nothing -> pure ()
Just h -> liftIO . hPutChar h . chr $ fromIntegral v
pure s
, compRead = \_ _ -> pure 0x00
}
|