-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
44 lines (36 loc) · 983 Bytes
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Main where
import DCPU
import DCPU.Types
import DCPU.Hardware.LEM1802
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.State.Strict
import Data.Sequence
import Data.Vector (Vector)
import qualified Data.Vector as V
import Data.Word
import Foreign
import Graphics.UI.Gtk
import System.IO
loadDCPUmem :: FilePath -> IO (Vector Word16)
loadDCPUmem path = do
arr <- mallocArray 0x10000
withFile path ReadMode $ \handle -> do
h <- hGetBuf handle arr 0x10000
V.generateM 0x10000 $ \n ->
if n <= h
then peekElemOff arr n
else return 0
main :: IO ()
main = do
[f] <- initGUI
mem <- loadDCPUmem f
lem <- fmap lem1802 newLEM1802
let initDCPU = DCPU {
_dcpuRam = (mem V.!) . fromIntegral,
_dcpuRegisters = const 0,
_dcpuIsInterruptQueueing = False,
_dcpuInterruptQueue = empty,
_dcpuHardware = singleton lem
}
runStateT (runMaybeT $ runStateT runDCPU initDCPU) 0
return ()