hl and bc as lenses

This commit is contained in:
2026-03-30 14:18:12 +02:00
parent 45339997c8
commit 213a6bff5e

View File

@@ -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