Created
July 27, 2010 14:49
-
-
Save ryukzak/492327 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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