Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to skip non-compute tiles for numbering of tile sources. #7

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

stack build --pedantic 2>&1 | tee build.log
stack build 2>&1 | tee build.log
22 changes: 14 additions & 8 deletions examples/segment00150/segment00150.asm
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
@0
MOV UP, DOWN

@1
MOV RIGHT, DOWN

@2
MOV UP, LEFT

@3
MOV UP, DOWN

@4
MOV UP, DOWN
@8

@5
MOV UP, DOWN

@3
MOV UP, LEFT
@2
MOV RIGHT, DOWN
@6
MOV UP, DOWN
@10
MOV UP, RIGHT
@11

@7
MOV LEFT, DOWN
23 changes: 20 additions & 3 deletions examples/segment20176/segment20176.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@0


@1
MOV UP, ACC
SUB RIGHT
Expand All @@ -6,16 +9,30 @@ MOV ACC, DOWN
@2
MOV UP, LEFT

@3


@4


@5
MOV UP, ACC
MOV ACC, DOWN
MOV ACC, DOWN

@9
@6


@7


@8
MOV UP, RIGHT
MOV UP, DOWN

@10
@9
MOV LEFT, ACC
NEG
MOV ACC, DOWN
MOV ACC, DOWN

@10
4 changes: 2 additions & 2 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

./build.sh
# stack run tissim -- examples/segment00150/segment00150.asm -c examples/segment00150/segment00150.cfg 2>&1 | tee test.log
stack run tissim -- examples/segment20176/segment20176.asm -c examples/segment20176/segment20176.cfg 2>&1 | tee test.log
stack run tissim -- examples/segment00150/segment00150.asm -c examples/segment00150/segment00150.cfg 2>&1 | tee test.log
# stack run tissim -- examples/segment20176/segment20176.asm -c examples/segment20176/segment20176.cfg 2>&1 | tee test.log
24 changes: 16 additions & 8 deletions src/TIS100/Sim/CPU.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module TIS100.Sim.CPU where

import Control.Monad (zipWithM)
import Data.IntMap qualified as IM
import Data.Map qualified as M
import Data.Vector qualified as V
Expand Down Expand Up @@ -38,15 +37,24 @@ data CPUState = CPUState
createInitialCPUState :: C.Config -> AP.AsmSource -> TISErrorOr CPUState
createInitialCPUState cfg asm =
let tileTypes = concat $ C.tiles cfg
in (CPUState (CPUConfig (C.rows cfg) (C.cols cfg)) . V.fromList <$> zipWithM createTile [0 ..] tileTypes)
in (CPUState (CPUConfig (C.rows cfg) (C.cols cfg)) . V.fromList <$> createTiles 0 0 tileTypes)
where
createTile :: Int -> C.TileType -> TISErrorOr PositionedTile
createTile i tileType =
let pos = i `divMod` C.cols cfg
createTiles :: Int -> Int -> [C.TileType] -> TISErrorOr [PositionedTile]
createTiles _ _ [] = Right []
createTiles asmIdx tileIdx (t : ts) = do
tile' <- createTile asmIdx tileIdx t
tiles' <- case t of
C.Conpute -> createTiles (asmIdx + 1) (tileIdx + 1) ts
_ -> createTiles asmIdx (tileIdx + 1) ts
return $ tile' : tiles'

createTile :: Int -> Int -> C.TileType -> TISErrorOr PositionedTile
createTile asmIdx tileIdx tileType =
let pos = tileIdx `divMod` C.cols cfg
in case tileType of
C.Conpute -> PositionedTile pos i . ConnectedTile . T21.createTileState <$> getTileAsm i
C.Stack -> Right $ PositionedTile pos i $ ConnectedTile $ T30.T30 []
C.Disabled -> Right $ PositionedTile pos i $ ConnectedTile $ Inactive.InactiveTile
C.Conpute -> PositionedTile pos tileIdx . ConnectedTile . T21.createTileState <$> getTileAsm asmIdx
C.Stack -> Right $ PositionedTile pos tileIdx $ ConnectedTile $ T30.T30 []
C.Disabled -> Right $ PositionedTile pos tileIdx $ ConnectedTile $ Inactive.InactiveTile

getTileAsm :: Int -> TISErrorOr T21.TileProgram
getTileAsm i = case IM.lookup i asm of
Expand Down
13 changes: 8 additions & 5 deletions src/TIS100/Tiles/T21.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ instance IsConnectedTile T21 where

writeValueTo = setPortVal False -- External call

step t = case (runState . tileState) t of
Ready -> stepReady
WaitingOnRead _ Nothing -> t
WaitingOnRead _ (Just _) -> stepReady
WaitingOnWrite _ _ -> t
step t =
if null (tileProgram t)
then t
else case (runState . tileState) t of
Ready -> stepReady
WaitingOnRead _ Nothing -> t
WaitingOnRead _ (Just _) -> stepReady
WaitingOnWrite _ _ -> t
where
stepReady :: T21
stepReady = stepReady'
Expand Down
2 changes: 2 additions & 0 deletions tissim/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ main = do
print asm

let initialCPUState = CPU.createInitialCPUState cfg asm
print initialCPUState

finalSimState <- case initialCPUState of
Left err -> error $ show err
Right cpuState -> Run.run $ Run.SimState cpuState (ParserCfg.inputs cfg) (ParserCfg.outputs cfg)
Expand Down