Skip to content

Commit

Permalink
Patch for loading very old designs successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcl committed Apr 16, 2022
1 parent 9528bc5 commit 2e5673e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/Renderer/DrawBlock/BusWireUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,10 +1154,15 @@ let update (msg : Msg) (model : Model) : Model*Cmd<Msg> =
// reconstructed precisely

/// check whether a laoded wires position matches a symbol vertex
let posMatchesVertex (pos:XYPos) (vertex: float*float) =
let epsilon = 0.00001
abs (pos.X - (fst vertex)) < epsilon &&
abs (pos.Y - (snd vertex)) < epsilon
/// If the vertices lits is empty the evrtex will be None, and not match
let posMatchesVertex (pos:XYPos) (vertexOpt: (float*float) option) =
match vertexOpt with
| None ->
false
| Some vertex ->
let epsilon = 0.00001
abs (pos.X - (fst vertex)) < epsilon &&
abs (pos.Y - (snd vertex)) < epsilon

// get the newly loaded wires
let newWires =
Expand All @@ -1173,11 +1178,11 @@ let update (msg : Msg) (model : Model) : Model*Cmd<Msg> =
| true ->
posMatchesVertex
(Symbol.getInputPortLocation None model.Symbol inputId)
(List.last conn.Vertices |> getVertex)
(List.tryLast conn.Vertices |> Option.map getVertex)
| false ->
posMatchesVertex
(Symbol.getOutputPortLocation None model.Symbol outputId)
(List.head conn.Vertices |> getVertex)
(List.tryHead conn.Vertices |> Option.map getVertex)
|> (fun b ->
if b then
wire
Expand Down
5 changes: 2 additions & 3 deletions src/Renderer/Interface/FilesIO.fs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ let readMemLines (addressWidth:int) (wordWidth: int) (lines: string array) =
match Array.tryFind (function | Error _ -> true | _ -> false) parse with
| None ->
let defs = (Array.map (function |Ok x -> x | _ -> failwithf "What?") parse)
Array.iter (fun (a,b) -> printfn "a=%d, b=%d" a b) defs
let repeats =
Array.groupBy fst defs
|> Array.filter (fun (num, vals) -> vals.Length > 1)
Expand All @@ -383,8 +382,8 @@ let readMemDefns (addressWidth:int) (wordWidth: int) (fPath: string) =
printfn "starting defn read"
tryReadFileSync fPath
|> Result.bind (
(fun contents -> printfn "read file:\n contents={contents}"; contents)
>> String.splitRemoveEmptyEntries [|'\n';'\r'|]
//(fun contents -> printfn "read file:\n contents={contents}"; contents)
String.splitRemoveEmptyEntries [|'\n';'\r'|]
>> readMemLines addressWidth wordWidth
>> (fun x -> printfn "read lines"; x)
>> Result.map Map.ofArray)
Expand Down

0 comments on commit 2e5673e

Please sign in to comment.