From 29a23971f5e7f5b657e1caafb76b21de9f457c50 Mon Sep 17 00:00:00 2001 From: Tyler L Date: Wed, 23 May 2018 04:04:09 -0700 Subject: [PATCH] emptyState --- src/SixtyFiveOhTwo/Instruction.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/SixtyFiveOhTwo/Instruction.hs b/src/SixtyFiveOhTwo/Instruction.hs index 05fdfe8..e8f39ca 100644 --- a/src/SixtyFiveOhTwo/Instruction.hs +++ b/src/SixtyFiveOhTwo/Instruction.hs @@ -12,11 +12,14 @@ data InstructionState = InstructionState { -- The functionTable relates functions to their byte offsets in the compiled code _functionTable :: M.Map String Int, _bytestring :: B.ByteString -} +} deriving Show makeLenses ''InstructionState +emptyState :: InstructionState +emptyState = InstructionState { _functionTable = M.empty, _bytestring = B.empty } type Instruction = State InstructionState InstructionState +-- Remember, it's little endian data AddressingMode = Implied | Accumulator | @@ -33,6 +36,8 @@ data AddressingMode = IndirectX Word8 | IndirectY Word8 +appendBytes :: [Word8] -> InstructionState -> InstructionState +appendBytes bytes insState = over bytestring (\bs -> B.append bs (B.pack bytes)) insState define :: String -> Instruction -> Instruction define name definition = do @@ -44,4 +49,10 @@ define name definition = do adc :: AddressingMode -> Instruction adc (Immediate b) = do insState <- get - return $ over bytestring (\bs -> B.append bs (B.pack [0x69, b])) insState \ No newline at end of file + return $ appendBytes [0x69, b] insState +adc (ZeroPage b) = do + insState <- get + return $ appendBytes [0x65, b] insState +adc (ZeroPageX b) = do + insState <- get + return $ appendBytes [0x75, b] insState