module Nes.APU.BusInterface (
writeToAPU,
readFromAPU,
) where
import Nes.APU.BusInterface.DMC
import Nes.APU.BusInterface.FrameCounter
import Nes.APU.BusInterface.Noise
import Nes.APU.BusInterface.Pulse
import Nes.APU.BusInterface.Status
import Nes.APU.BusInterface.Triangle
import Nes.APU.Monad
import Nes.Memory (Addr, Byte (..))
{-# INLINE writeToAPU #-}
writeToAPU :: Addr -> Byte -> APU r ()
writeToAPU :: forall r. Addr -> Byte -> APU r ()
writeToAPU Addr
addr = case Addr
addr of
Addr
0x4000 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4000
Addr
0x4001 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4001
Addr
0x4002 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4002
Addr
0x4003 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4003
Addr
0x4004 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4004
Addr
0x4005 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4005
Addr
0x4006 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4006
Addr
0x4007 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4007
Addr
0x4008 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4008
Addr
0x400A -> Byte -> APU r ()
forall r. Byte -> APU r ()
write400A
Addr
0x400B -> Byte -> APU r ()
forall r. Byte -> APU r ()
write400B
Addr
0x400C -> Byte -> APU r ()
forall r. Byte -> APU r ()
write400C
Addr
0x400E -> Byte -> APU r ()
forall r. Byte -> APU r ()
write400E
Addr
0x400F -> Byte -> APU r ()
forall r. Byte -> APU r ()
write400F
Addr
0x4010 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4010
Addr
0x4011 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4011
Addr
0x4012 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4012
Addr
0x4013 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4013
Addr
0x4015 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4015
Addr
0x4017 -> Byte -> APU r ()
forall r. Byte -> APU r ()
write4017
Addr
_ -> APU r () -> Byte -> APU r ()
forall a b. a -> b -> a
const (() -> APU r ()
forall a. a -> APU r a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
{-# INLINE readFromAPU #-}
readFromAPU :: Addr -> APU r (Maybe Byte)
readFromAPU :: forall r. Addr -> APU r (Maybe Byte)
readFromAPU = \case
Addr
0x4015 -> Byte -> Maybe Byte
forall a. a -> Maybe a
Just (Byte -> Maybe Byte) -> APU r Byte -> APU r (Maybe Byte)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> APU r Byte
forall r. APU r Byte
read4015
Addr
_ -> Maybe Byte -> APU r (Maybe Byte)
forall a. a -> APU r a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Byte
forall a. Maybe a
Nothing