diff --git a/src/GB/CPU.hs b/src/GB/CPU.hs index 1205a8c..b68bc24 100644 --- a/src/GB/CPU.hs +++ b/src/GB/CPU.hs @@ -61,17 +61,13 @@ data Registers = Registers { _a :: Word8 makeLenses ''Registers -getBC :: Registers -> Word16 -getBC r = (( .<<. 8) . fromIntegral $ r ^. b) + (fromIntegral $ r ^. c) +bc :: Lens' Registers Word16 +bc = lens (\r -> (( .<<. 8) . fromIntegral $ r ^. b) + (fromIntegral $ r ^. c)) + (\r w -> r & b %~ (const $ fromIntegral $ w .>>. 8) & c %~ (const $ fromIntegral $ w .&. 255)) -setBC :: Registers -> Word16 -> Registers -setBC r w = r & b %~ (const $ fromIntegral $ w .>>. 8) & c %~ (const $ fromIntegral $ w .&. 255) - -getHL :: Registers -> Word16 -getHL r = ((.<<. 8) . fromIntegral $ r ^. h) + (fromIntegral $ r ^. l) - -setHL :: Registers -> Word16 -> Registers -setHL r w = r & h %~ (const $ fromIntegral $ w .>>. 8) & l %~ (const $ fromIntegral $ w .&. 255) +hl :: Lens' Registers Word16 +hl = lens (\r -> ((.<<. 8) . fromIntegral $ r ^. h) + (fromIntegral $ r ^. l)) + (\r w -> r & h %~ (const $ fromIntegral $ w .>>. 8) & l %~ (const $ fromIntegral $ w .&. 255)) data CPU = CPU { _registers :: Registers , _pc :: Word16