aboutsummaryrefslogtreecommitdiff
path: root/src/Suem.hs
blob: eeb743df5bceb1be51285bf4d7ac4a9442933106 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
{-# LANGUAGE BinaryLiterals #-}
-- This module organizes Emulator execution.
module Suem (Config(..), ConfigSocket(..), suem) where

import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString as B
import Prelude hiding (Word)
import Data.Word
import Data.IORef
import Data.Foldable
import Control.Monad.Reader (runReaderT)
import Data.IP
import Network.Socket
import Numeric
import Machine
import Instructions
import Utils
import Device


------------------------------------------------------------------------------
-- Main loop and command deciphering.

doInstruction :: Word16 -> Emulator ()
doInstruction 0b0000000000111100 = doORICCR
doInstruction 0b0000000001111100 = doORISR
doInstruction 0b0000001000111100 = doANDICCR
doInstruction 0b0000001001111100 = doANDISR
doInstruction 0b0000101000111100 = doEORICCR
doInstruction 0b0000101001111100 = doEORISR
doInstruction 0b0100101011111100 = doILLEGAL
doInstruction 0b0100111001110000 = doRESET
doInstruction 0b0100111001110001 = doNOP
doInstruction 0b0100111001110010 = doSTOP
doInstruction 0b0100111001110011 = doRTE
doInstruction 0b0100111001110101 = doRTS
doInstruction 0b0100111001110110 = doTRAPV
doInstruction 0b0100111001110111 = doRTR
doInstruction opcode
    | (extractBits opcode [0..7]) == 0b00000000 =
        doORI (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b00000010 =
        doANDI (extractBits opcode [8..9])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b00000100 =
        doSUBI (extractBits opcode [8..9])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b00000110 =
        doADDI (extractBits opcode [8..9])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b00001010 =
        doEORI (extractBits opcode [8..9])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b00001100 =
        doCMPI (extractBits opcode [8..9])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0000 &&
      (extractBits opcode [7]) == 0b0 &&
      (extractBits opcode [10..12]) == 0b001 =
        doMOVEP (extractBits opcode [4..6])
                (extractBits opcode [8])
                (extractBits opcode [9])
                (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0000 &&
      (extractBits opcode [8..9]) == 0b00 =
        doBTST (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0000 &&
      (extractBits opcode [8..9]) == 0b01 =
        doBCHG (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0000 &&
      (extractBits opcode [8..9]) == 0b10 =
        doBCLR (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0000 &&
      (extractBits opcode [8..9]) == 0b11 =
        doBSET (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..1]) == 0b00 &&
      (extractBits opcode [7..9]) == 0b001 =
        doMOVEA (extractBits opcode [2..3])
                (extractBits opcode [4..6])
                (extractBits opcode [10..12])
                (extractBits opcode [13..15])
    | (extractBits opcode [0..1]) == 0b00 =
        doMOVE (extractBits opcode [2..3])
               (extractBits opcode [4..6])
               (extractBits opcode [7..9])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..9]) == 0b0100000011 =
        doSRMOVE (extractBits opcode [10..12])
                 (extractBits opcode [13..15])
    | (extractBits opcode [0..9]) == 0b0100010011 =
        doMOVECCR (extractBits opcode [10..12])
                  (extractBits opcode [13..15])
    | (extractBits opcode [0..9]) == 0b0100011011 =
        doMOVESR (extractBits opcode [10..12])
                 (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b01000000 =
        doNEGX (extractBits opcode [8..9])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b01000010 =
        doCLR (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b01000100 =
        doNEG (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b01000110 =
        doNOT (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..8]) == 0b010010001 &&
      (extractBits opcode [10..12]) == 0b000 =
        doEXT (extractBits opcode [9])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..9]) == 0b0100100000 =
        doNBCD (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..12]) == 0b0100100001000 =
        doSWAP (extractBits opcode [13..15])
    | (extractBits opcode [0..9]) == 0b0100100001 =
        doPEA (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..9]) == 0b0100100011 =
        doTAS (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b01001010 =
        doTST (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..11]) == 0b010011100100 =
        doTRAP (extractBits opcode [12..15])
    | (extractBits opcode [0..12]) == 0b0100111001010 =
        doLINK (extractBits opcode [13..15])
    | (extractBits opcode [0..12]) == 0b0100111001011 =
        doUNLK (extractBits opcode [13..15])
    | (extractBits opcode [0..11]) == 0b010011100110 =
        doMOVEUSP (extractBits opcode [12])
                  (extractBits opcode [13..15])
    | (extractBits opcode [0..9]) == 0b0100111010 =
        doJSR (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..9]) == 0b0100111011 =
        doJMP (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..4]) == 0b01001 &&
      (extractBits opcode [6..8]) == 0b001 =
        doMOVEM (extractBits opcode [5])
                (extractBits opcode [9])
                (extractBits opcode [10..12])
                (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0100 &&
      (extractBits opcode [7..9]) == 0b111 =
        doLEA (extractBits opcode [4..6])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0100 &&
      (extractBits opcode [7..9]) == 0b110 =
        doCHK (extractBits opcode [4..6])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0101 &&
      (extractBits opcode [8..12]) == 0b11001 =
        doDBcc (extractBits opcode [4..7])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0101 &&
      (extractBits opcode [8..9]) == 0b11 =
        doScc (extractBits opcode [4..7])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0101 &&
      (extractBits opcode [7]) == 0b0 =
        doADDQ (extractBits opcode [4..6])
               (extractBits opcode [8..9])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b0101 &&
      (extractBits opcode [7]) == 0b1 =
        doSUBQ (extractBits opcode [4..6])
               (extractBits opcode [8..9])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..7]) == 0b01100001 =
        doBSR (extractBits opcode [8..15])
    | (extractBits opcode [0..3]) == 0b0110 =
        doBcc (extractBits opcode [4..7])
              (extractBits opcode [8..15])
    | (extractBits opcode [0..3]) == 0b0111 &&
      (extractBits opcode [7]) == 0b0 =
        doMOVEQ (extractBits opcode [4..6])
                (extractBits opcode [8..15])
    | (extractBits opcode [0..3]) == 0b1000 &&
      (extractBits opcode [7..9]) == 0b011 =
        doDIVU (extractBits opcode [4..6])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1000 &&
      (extractBits opcode [7..9]) == 0b111 =
        doDIVS (extractBits opcode [4..6])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1000 &&
      (extractBits opcode [7..11]) == 0b10000 =
        doSBCD (extractBits opcode [4..6])
               (extractBits opcode [12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1000 =
        doOR (extractBits opcode [4..6])
             (extractBits opcode [7])
             (extractBits opcode [8..9])
             (extractBits opcode [10..12])
             (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1001 &&
      (extractBits opcode [8..9]) == 0b11 =
        doSUBA (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1001 &&
      (extractBits opcode [7]) == 0b1 &&
      (extractBits opcode [10..11]) == 0b00 =
        doSUBX (extractBits opcode [4..6])
               (extractBits opcode [8..9])
               (extractBits opcode [12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1001 =
        doSUB (extractBits opcode [4..6])
              (extractBits opcode [7])
              (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1011 &&
      (extractBits opcode [8..9]) == 0b11 =
        doCMPA (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1011 &&
      (extractBits opcode [7]) == 0b0 =
        doCMP (extractBits opcode [4..6])
              (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1011 &&
      (extractBits opcode [7]) == 0b1 &&
      (extractBits opcode [10..12]) == 0b001 =
        doCMPM (extractBits opcode [4..6])
               (extractBits opcode [8..9])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1011 &&
      (extractBits opcode [7]) == 0b1 =
        doEOR (extractBits opcode [4..6])
              (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1100 &&
      (extractBits opcode [7..9]) == 0b011 =
        doMULU (extractBits opcode [4..6])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1100 &&
      (extractBits opcode [7..9]) == 0b111 =
        doMULS (extractBits opcode [4..6])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1100 &&
      (extractBits opcode [7..11]) == 0b10000 =
        doABCD (extractBits opcode [4..6])
               (extractBits opcode [12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1100 &&
      (extractBits opcode [7]) == 0b1 &&
      (extractBits opcode [10..11]) == 0b00 =
        doEXG (extractBits opcode [4..6])
              (extractBits opcode [8..9])
              (extractBits opcode [12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1100 =
        doAND (extractBits opcode [4..6])
              (extractBits opcode [7])
              (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1101 &&
      (extractBits opcode [8..9]) == 0b11 =
        doADDA (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1101 &&
      (extractBits opcode [7]) == 0b1 &&
      (extractBits opcode [10..11]) == 0b00 =
        doADDX (extractBits opcode [4..6])
               (extractBits opcode [8..9])
               (extractBits opcode [12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1101 =
        doADD (extractBits opcode [4..6])
              (extractBits opcode [7])
              (extractBits opcode [8..9])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..6]) == 0b1110000 &&
      (extractBits opcode [8..9]) == 0b11 =
        doASD (extractBits opcode [7])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..6]) == 0b1110001 &&
      (extractBits opcode [8..9]) == 0b11 =
        doLSD (extractBits opcode [7])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..6]) == 0b1110010 &&
      (extractBits opcode [8..9]) == 0b11 =
        doROXd (extractBits opcode [7])
               (extractBits opcode [10..12])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..6]) == 0b1110011 &&
      (extractBits opcode [8..9]) == 0b11 =
        doROd (extractBits opcode [7])
              (extractBits opcode [10..12])
              (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1110 &&
      (extractBits opcode [11..12]) == 0b00 =
        doADSR (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [8..9])
               (extractBits opcode [10])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1110 &&
      (extractBits opcode [11..12]) == 0b01 =
        doLSDR (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [8..9])
               (extractBits opcode [10])
               (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1110 &&
      (extractBits opcode [11..12]) == 0b10 =
        doROXdR (extractBits opcode [4..6])
                (extractBits opcode [7])
                (extractBits opcode [8..9])
                (extractBits opcode [10])
                (extractBits opcode [13..15])
    | (extractBits opcode [0..3]) == 0b1110 &&
      (extractBits opcode [11..12]) == 0b11 =
        doROdR (extractBits opcode [4..6])
               (extractBits opcode [7])
               (extractBits opcode [8..9])
               (extractBits opcode [10])
               (extractBits opcode [13..15])
    | otherwise = do
                pc <- readPC
                sr <- readSR
                d0 <- readD 0 4
                d1 <- readD 1 4
                d2 <- readD 2 4
                d3 <- readD 3 4
                d4 <- readD 4 4
                d5 <- readD 5 4
                d6 <- readD 6 4
                d7 <- readD 7 4
                a0 <- readA 0 4
                a1 <- readA 1 4
                a2 <- readA 2 4
                a3 <- readA 3 4
                a4 <- readA 4 4
                a5 <- readA 5 4
                a6 <- readA 6 4
                a7 <- readA 7 4
                error ("Error:\n"
                    ++ "PC:0x" ++ showHex pc "\n"
                    ++ "SR:0x" ++ showHex sr "\n\n"
                    ++ "D0:0x" ++ showHex d0 "\n"
                    ++ "D1:0x" ++ showHex d1 "\n"
                    ++ "D2:0x" ++ showHex d2 "\n"
                    ++ "D3:0x" ++ showHex d3 "\n"
                    ++ "D4:0x" ++ showHex d4 "\n"
                    ++ "D5:0x" ++ showHex d5 "\n"
                    ++ "D6:0x" ++ showHex d6 "\n"
                    ++ "D7:0x" ++ showHex d7 "\n\n"
                    ++ "A0:0x" ++ showHex a0 "\n"
                    ++ "A1:0x" ++ showHex a1 "\n"
                    ++ "A2:0x" ++ showHex a2 "\n"
                    ++ "A3:0x" ++ showHex a3 "\n"
                    ++ "A4:0x" ++ showHex a4 "\n"
                    ++ "A5:0x" ++ showHex a5 "\n"
                    ++ "A6:0x" ++ showHex a6 "\n"
                    ++ "A7:0x" ++ showHex a7 "")

runMachine :: Emulator ()
runMachine = forM_ [0..] $ \_ -> do
    pc <- with pc $ \pc -> readIORef pc
    opcode <- getWord $ fromIntegral pc
    doInstruction opcode
    checkInteruptsFromDevices


------------------------------------------------------------------------------
-- Config and start of execution based on the config.

data ConfigSocket = ConfigInet String | ConfigUnix String

data Config = Config Int      -- frequence
                     Int      -- size of RAM
                     FilePath -- path to ROM
                     (Maybe ConfigSocket)
                     (Maybe ConfigSocket)
                     (Maybe ConfigSocket)
                     (Maybe ConfigSocket)
                     (Maybe ConfigSocket)
                     (Maybe ConfigSocket)
                     (Maybe ConfigSocket)
                     (Maybe ConfigSocket)

ipString :: String -> Word32
ipString = fromIntegral . sum . map (\(n,o) -> toInteger o * 256 ^ n)
         . zip [0..] . reverse . fromIPv4 . read

makeSocket :: Maybe ConfigSocket -> IO (Maybe Socket)
makeSocket (Just (ConfigUnix a)) = do
    sock <- socket AF_UNIX Stream defaultProtocol
    Network.Socket.bind sock $ SockAddrUnix a
    return $ Just sock
makeSocket (Just (ConfigInet a)) = do
    sock <- socket AF_INET Stream defaultProtocol
    Network.Socket.bind sock $ SockAddrInet
                                (read $ tail $ dropWhile (/= ':') a)
                                (ipString    $ takeWhile (/= ':') a)
    return $ Just sock
makeSocket Nothing = return Nothing

makeMachine :: VM.IOVector Byte -> V.Vector Byte
            -> Maybe ConfigSocket -> Maybe ConfigSocket
            -> Maybe ConfigSocket -> Maybe ConfigSocket
            -> Maybe ConfigSocket -> Maybe ConfigSocket
            -> Maybe ConfigSocket -> Maybe ConfigSocket
            -> IO Machine
makeMachine ramData romData s0 s1 s2 s3 s4 s5 s6 s7 = do
    pc <- newIORef pcval
    sr <- newIORef 0x2700
    drs <- newIORef (fromIntegral 0, fromIntegral 0, fromIntegral 0,
                     fromIntegral 0, fromIntegral 0, fromIntegral 0,
                     fromIntegral 0, fromIntegral 0)
    ars <- newIORef (fromIntegral 0, fromIntegral 0, fromIntegral 0,
                     fromIntegral 0, fromIntegral 0, fromIntegral 0,
                     fromIntegral 0)
    usp <- newIORef 0
    ssp <- newIORef sspval
    ms0 <- makeSocket s0
    ms1 <- makeSocket s1
    ms2 <- makeSocket s2
    ms3 <- makeSocket s3
    ms4 <- makeSocket s4
    ms5 <- makeSocket s5
    ms6 <- makeSocket s6
    ms7 <- makeSocket s7
    return $ Machine pc sr drs ars usp ssp ramData romData
                     ms0 ms1 ms2 ms3 ms4 ms5 ms6 ms7
    where pcval = (fromIntegral $ romData V.! 4) * 256 * 256 * 256 +
                  (fromIntegral $ romData V.! 5) * 256 * 256 +
                  (fromIntegral $ romData V.! 6) * 256 +
                  (fromIntegral $ romData V.! 7)
          sspval = (fromIntegral $ romData V.! 0) * 256 * 256 * 256 +
                   (fromIntegral $ romData V.! 1) * 256 * 256 +
                   (fromIntegral $ romData V.! 2) * 256 +
                   (fromIntegral $ romData V.! 3)

runEmulator :: Emulator a -> Machine -> IO a
runEmulator (Emulator reader) m = runReaderT reader m

suem :: Config -> IO ()
suem (Config _ ramSize romPath s0 s1 s2 s3 s4 s5 s6 s7) = do
    romData <- B.readFile romPath
    ram <- VM.replicate ramSize 0
    m <- makeMachine ram (V.fromList $ B.unpack $ romData)
                     s0 s1 s2 s3 s4 s5 s6 s7
    runEmulator runMachine m