Skip to content

Commit

Permalink
beginning simulator definition
Browse files Browse the repository at this point in the history
  • Loading branch information
lisphacker committed Sep 15, 2023
1 parent 317aee8 commit 8d23482
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 25 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ default-extensions:
dependencies:
- name: base
- string-interpolate
- vector

# The library contains all of our application code.
# The executable defined below is just a thin wrapper.
Expand Down
1 change: 0 additions & 1 deletion src/TIS100/CPU/ConnectedNode.hs

This file was deleted.

6 changes: 0 additions & 6 deletions src/TIS100/CPU/T30.hs

This file was deleted.

2 changes: 1 addition & 1 deletion src/TIS100/CPU/Base.hs → src/TIS100/Nodes/Base.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module TIS100.CPU.Base where
module TIS100.Nodes.Base where

newtype Value = Value Int
deriving (Eq)
Expand Down
1 change: 1 addition & 0 deletions src/TIS100/Nodes/ConnectedNode.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module TIS100.Nodes.ConnectedNode where
42 changes: 25 additions & 17 deletions src/TIS100/CPU/T21.hs → src/TIS100/Nodes/T21.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module TIS100.CPU.T21 where
module TIS100.Nodes.T21 where

import TIS100.CPU.Base (Value (..))
import TIS100.Nodes.Base (Value (..))
import Prelude hiding (last)

data Register' = ACC | NIL
Expand Down Expand Up @@ -35,7 +35,7 @@ data Instruction
deriving (Eq, Show)

data RunState
= Running
= Ready
| WaitingOnRead Port'
| WaitingOnWrite Port'
deriving (Eq, Show)
Expand All @@ -48,23 +48,31 @@ data TileState = TileState
up :: Maybe Value,
down :: Maybe Value,
last :: Port',
program :: [Instruction],
pc :: Address,
runState :: RunState
}
deriving (Eq, Show)

createTileState :: [Instruction] -> TileState
data T21 = T21
{ tileState :: TileState,
program :: [Instruction]
}
deriving (Eq, Show)

createTileState :: [Instruction] -> T21
createTileState program =
TileState
{ acc = 0,
bak = 0,
left = Nothing,
right = Nothing,
up = Nothing,
down = Nothing,
last = UP,
program = program,
pc = 0,
runState = Running
}
T21
{ tileState =
TileState
{ acc = 0,
bak = 0,
left = Nothing,
right = Nothing,
up = Nothing,
down = Nothing,
last = UP,
pc = 0,
runState = Ready
},
program = program
}
6 changes: 6 additions & 0 deletions src/TIS100/Nodes/T30.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module TIS100.Nodes.T30 where

import TIS100.Nodes.Base (Value (..))

newtype T30 = Stack [Value]
deriving (Eq, Show)
7 changes: 7 additions & 0 deletions src/TIS100/Simulator/CPU.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module TIS100.Simulator.CPU where

import TIS100.Nodes.T21 (T21 (..))
import TIS100.Nodes.T30 (T30 (..))

data Node = InactiveNode | Node21 T21 | Node30 T30
deriving (Eq, Show)

0 comments on commit 8d23482

Please sign in to comment.