Skip to content

Instantly share code, notes, and snippets.

@ryukzak
Created July 27, 2010 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryukzak/492327 to your computer and use it in GitHub Desktop.
Save ryukzak/492327 to your computer and use it in GitHub Desktop.
module Main where
import qualified Data.ByteString as B
import Cmd
import System.Environment
import Data.Array
newState = State { pmem = B.empty
, dmem = array (0, 255) $ take 256 $ zip [0,1..] [0,0..]
, pc = 0x00
, ir = 0x00
, ar = 0x00
, acc = 0x00
, dip = 0
, futureDip = replicate 30 1 ++ replicate 30 5 ++ replicate 30 1 ++ replicate 300 0x0f
, btn = 0
, futureBtn = replicate 30 1 ++ replicate 30 0 ++ replicate 30 1 ++ replicate 300 0
, c = False
, z = False
, on = True
}
step (State {on = False}) = return ()
step state = step $ executeCommand state' commandFlow
where
state'@(State{ir = hexCommand}) = nextCommand state
commandFlow = commandFlowFromInfo $ getCommandInfo hexCommand
executeCommand state [] = state
executeCommand state (f:fs) = executeCommand (f state) fs
setPmem s pmem = s{pmem = pmem}
main = do
args <- getArgs
let input = if length args >= 1 then args !! 0 else "out"
pmem <- B.readFile input
step $ setPmem newState pmem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment