From df5418432e5f13632f8d464c9ee57fe663e0274d Mon Sep 17 00:00:00 2001 From: Aearnus Date: Thu, 24 May 2018 01:56:12 -0700 Subject: [PATCH] Define and call are done --- src/SixtyFiveOhTwo/Instruction.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/SixtyFiveOhTwo/Instruction.hs b/src/SixtyFiveOhTwo/Instruction.hs index 9ed6a89..6132a89 100644 --- a/src/SixtyFiveOhTwo/Instruction.hs +++ b/src/SixtyFiveOhTwo/Instruction.hs @@ -72,6 +72,8 @@ genericTwoByteOp op arg = do insState <- get return $ appendBytesThenWord [op] arg insState +-- This allows you to define functions which can be called later using `call`. +-- Note: your function must end with an `rts`, I don't add that automatically define :: String -> Instruction -> Instruction define name definition = do insState <- get @@ -79,6 +81,13 @@ define name definition = do -- TODO: COMBINE THE FUNCTION DEFINITIONS HERE TOO NOT JUST BYTESTRINGS return $ execState definition insState' +call :: String -> Instruction +call name = do + insState <- get + let pointer = case (M.lookup name (insState ^. functionTable)) of + Just ptr -> ptr + Nothing -> error ("Couldn't find function " ++ name ++ ". Perhaps it wasn't `define`d?") + jsr (Absolute $ fromIntegral pointer) -- THE FOLLOWING WAS GENERATED BY -- https://github.com/aearnus/assemblicom