Skip to content

Commit

Permalink
Merge pull request #7 from lisphacker/asm-tilenum-fix
Browse files Browse the repository at this point in the history
Fix to skip non-compute tiles for numbering of tile sources.
  • Loading branch information
lisphacker authored Oct 25, 2023
2 parents bf956e4 + 2bba0b1 commit 7e9c0bd
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 27 deletions.
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

0 comments on commit 7e9c0bd

Please sign in to comment.