hl and bc as lenses
This commit is contained in:
@@ -61,17 +61,13 @@ data Registers = Registers { _a :: Word8
|
|||||||
|
|
||||||
makeLenses ''Registers
|
makeLenses ''Registers
|
||||||
|
|
||||||
getBC :: Registers -> Word16
|
bc :: Lens' Registers Word16
|
||||||
getBC r = (( .<<. 8) . fromIntegral $ r ^. b) + (fromIntegral $ r ^. c)
|
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
|
hl :: Lens' Registers Word16
|
||||||
setBC r w = r & b %~ (const $ fromIntegral $ w .>>. 8) & c %~ (const $ fromIntegral $ w .&. 255)
|
hl = lens (\r -> ((.<<. 8) . fromIntegral $ r ^. h) + (fromIntegral $ r ^. l))
|
||||||
|
(\r w -> r & h %~ (const $ fromIntegral $ w .>>. 8) & l %~ (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)
|
|
||||||
|
|
||||||
data CPU = CPU { _registers :: Registers
|
data CPU = CPU { _registers :: Registers
|
||||||
, _pc :: Word16
|
, _pc :: Word16
|
||||||
|
|||||||
Reference in New Issue
Block a user