Skip to content
Browse files

Adding F# tools and ROM emulator.

  • Loading branch information...
1 parent 1c097e9 commit 3803c117e8c6474207e9b0c41e46676bbb930e58 @AshleyF AshleyF committed Jan 25, 2012
View
6 HP35/FSharp/Assembler/App.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5,Profile=Client" />
+ </startup>
+</configuration>
View
57 HP35/FSharp/Assembler/Assembler.fsproj
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{e51037e5-0310-44b9-b8f1-ed15aab3bfcf}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>Assembler</RootNamespace>
+ <AssemblyName>Assembler</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <Name>Assembler</Name>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <Tailcalls>false</Tailcalls>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <DocumentationFile>bin\Debug\Assembler.XML</DocumentationFile>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <Tailcalls>true</Tailcalls>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <DocumentationFile>bin\Release\Assembler.XML</DocumentationFile>
+ </PropertyGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
+ <ItemGroup>
+ <Compile Include="Program.fs" />
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Numerics" />
+ </ItemGroup>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
81 HP35/FSharp/Assembler/Program.fs
@@ -0,0 +1,81 @@
+open System.IO
+open System.Text.RegularExpressions
+
+let asm code =
+ let (|Pat|_|) (p : string) s =
+ let m = Regex.Match(s, (p.Replace("X", "([^\s]+)")
+ .Replace("Y[Z]", "([^\[]+)\[([^\]]+)\]")
+ .Replace("[Z]", "\[([^\]]+)\]")
+ .Replace("Z", "([\d]+)")))
+ if m.Success then Some(List.tail [for g in m.Groups -> g.Value]) else None
+ let labelsAndCode =
+ Path.GetFullPath code |> File.ReadAllLines |> List.ofSeq
+ |> List.choose (function
+ | Pat @"^\s*[\.;]" _ | Pat @"^\s*$" _ -> None // skip non-code (blank, comment, .rom, ...)
+ | Pat @"([^\s:]*):*\s+([^;\t]+)" [label; code] -> Some(label, code)
+ | _ -> failwith "Parse error.")
+ let labelLinesMap =
+ labelsAndCode
+ |> List.mapi (fun num (lbl, _) -> if lbl.Length > 0 then Some(lbl, num) else None)
+ |> List.choose id
+ |> Map.ofList
+ let label (lbl : string) =
+ if lbl.StartsWith("@") then System.Convert.ToInt32(lbl.Substring(1), 8) // octal address
+ else Map.find lbl labelLinesMap
+ let (|Fld|_|) = function
+ | "p" -> Some(-1, -1)
+ | "m" -> Some(3, 12)
+ | "x" -> Some(0, 2)
+ | "w" -> Some(0, 13)
+ | "wp" -> Some(0, -1)
+ | "ms" -> Some(3, 13)
+ | "xs" -> Some(2, 2)
+ | "s" -> Some(13, 13)
+ | _ -> failwith "Unsupported field name."
+ let sp = sprintf
+ let parse = function
+ | Pat "return" _ -> "retn"
+ | Pat "no operation" _ -> "nop"
+ | Pat "down rotate" _ -> "downrot"
+ | Pat "clear registers" _ -> "clearregs"
+ | Pat "clear status" _ -> "clears"
+ | Pat "display off" _ -> "dispoff"
+ | Pat "display toggle" _ -> "disptoggle"
+ | Pat "stack -> a" _ -> "stacka"
+ | Pat "c -> stack" _ -> "cstack"
+ | Pat "p \+ 1 -> p" _ -> "incp"
+ | Pat "p - 1 -> p" _ -> "decp"
+ | Pat "keys -> rom address" _ -> "keyrom"
+ | Pat "jsb X" [l] -> sp "jsb(%d)" (label l)
+ | Pat "go to X" [l] -> sp "goto(%d)" (label l)
+ | Pat "X -> sZ" [n; b] -> sp "sets(%s,%s)" b n // 5 –> s3
+ | Pat "select rom Z" [n] -> sp "setrom(%s)" n
+ | Pat "0 -> Y[Z]" [r; Fld (s, e)] -> sp "zeroreg(%s,%d,%d)" r s e // 0 -> a[w]
+ | Pat "0 - c - 1 -> c[Z]" [Fld (s, e)] -> sp "negsubc(%d,%d)" s e // 0 - c - 1 -> c[s]
+ | Pat "0 - c -> c[Z]" [Fld (s, e)] -> sp "negc(%d,%d)" s e // 0 - c -> c[x]
+ | Pat @"[^\s]+ \+ 1 -> Y[Z]" [r; Fld (s, e)] -> sp "increg(%s,%d,%d)" r s e // a + 1 -> a[p]
+ | Pat @"[^\s]+ - 1 -> Y[Z]" [r; Fld (s, e)] -> sp "decreg(%s,%d,%d)" r s e // a - 1 -> a[x]
+ | Pat "X \+ X -> Y[Z]" [r1; r2; r3; Fld (s, e)] -> sp "add(%s,%s,%s,%d,%d)" r3 r1 r2 s e
+ | Pat "X - X -> Y[Z]" [r1; r2; r3; Fld (s, e)] -> sp "sub(%s,%s,%s,%d,%d)" r3 r1 r2 s e
+ | Pat "X -> Y[Z]" [r1; r2; Fld (s, e)] -> sp "setreg(%s,%s,%d,%d)" r2 r1 s e // a -> b[w]
+ | Pat "X exchange Y[Z]" [r1; r2; Fld (s, e)] -> sp "exchreg(%s,%s,%d,%d)" r1 r2 s e
+ | Pat "X exchange X" [r1; r2] -> sp "exchreg(%s,%s,%d,%d)" r1 r2 0 13 // c exchange m
+ | Pat "X -> p" [n] -> sp "setp(%s)" n // 3 –> p
+ | Pat "X -> X" [r2; r1] -> sp "setreg(%s,%s,%d,%d)" r1 r2 0 13 // c exchange m
+ | Pat "shift left Y[Z]" [r; Fld (s, e)] -> sp "shiftl(%s,%d,%d)" r s e // shiftl a[w]
+ | Pat "shift right Y[Z]" [r; Fld (s, e)] -> sp "shiftr(%s,%d,%d)" r s e // shiftr a[w]
+ | Pat "if Y[Z] = 0" [r; Fld (s, e)] -> sp "ifregzero(%s,%d,%d)" r s e // if c[xs] = 0
+ | Pat "if X >= Y[Z]" [r1; r2; Fld (s, e)] -> sp "regsgte(%s,%s,%d,%d)" r1 r2 s e
+ | Pat "if Y[Z] >= 1" [r; Fld (s, e)] -> sp "regsgte1(%s,%d,%d)" r s e // if a[p] >= 1
+ | Pat "if sX = 0" [n] -> sp "tests(%s)" n // if s3 = 0
+ | Pat "if p # X" [n] -> sp "testp(%s)" n // if p # 11,
+ | Pat "load constant X" [n] -> sp "loadconst(%s)" n
+ | x -> sp "!!! UNKNOWN !!! %s" x
+
+ use output = new StreamWriter(@"..\..\..\ROMs\rom35v2.js")
+ labelsAndCode
+ |> List.map snd // code only
+ |> List.map parse
+ |> Seq.iter (fun a -> output.WriteLine(sprintf " %s," a))
+
+asm @"..\..\..\ROMs\35v2.asm"
View
6 HP35/FSharp/Calculator/App.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5,Profile=Client" />
+ </startup>
+</configuration>
View
58 HP35/FSharp/Calculator/Calculator.fsproj
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{b112cd0b-8351-47b2-bc14-2ca0d7b8c978}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>Calculator</RootNamespace>
+ <AssemblyName>Calculator</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <Name>Calculator</Name>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <Tailcalls>false</Tailcalls>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <DocumentationFile>bin\Debug\Calculator.XML</DocumentationFile>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <Tailcalls>true</Tailcalls>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <DocumentationFile>bin\Release\Calculator.XML</DocumentationFile>
+ </PropertyGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
+ <ItemGroup>
+ <Compile Include="Program.fs" />
+ <None Include="App.config" />
+ <None Include="Utility.fsx" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Numerics" />
+ </ItemGroup>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
154 HP35/FSharp/Calculator/Program.fs
@@ -0,0 +1,154 @@
+open System
+open System.Collections
+
+let calculator input output rom =
+ let r = Array.init 8 (fun _ -> Array.create 14 0)
+ let s = Array.create 12 0
+ let p = ref 0
+ let pc, offset, ret = ref 0, ref 0, ref 0
+ let carry, carry' = ref false, ref false
+ let visible, disp = ref false, ref ""
+ let waiting, lastKey = ref 0, ref 0
+ let halt = ref false
+ let exec code =
+ let doCarry res = carry := (res > 9 || res < 0); (res + 10) % 10
+ let doOp fn x y = doCarry (fn (fn x y) (if !carry then 1 else 0))
+ let iteric c fn (first, last) = carry := c; for i in first..last do fn i
+ let iteri fn = iteric !carry fn
+ let setreg a b = iteri (fun i -> r.[a].[i] <- r.[b].[i])
+ let zeroreg reg = setreg reg 7
+ let shiftl a (f, l) = for i in (List.rev [f..l]) do r.[a].[i] <- if i = f then 0 else r.[a].[i - 1]
+ let shiftr a (f, l) = for i in f..l do r.[a].[i] <- if i = l then 0 else r.[a].[i + 1]
+ let arith op a b c = iteri (fun i -> r.[a].[i] <- (doOp op) r.[b].[i] r.[c].[i])
+ let add = arith (+)
+ let sub = arith (-)
+ let regsgte a b = iteri (fun i -> (doOp (-)) r.[a].[i] r.[b].[i] |> ignore)
+ let regsgte1 a = iteric true (fun i -> carry := !carry && r.[a].[i] = 0)
+ let negcdec dec = iteric dec (fun i -> r.[2].[i] <- (doOp (-)) 0 r.[2].[i])
+ let opreg op a = iteric true (fun i -> r.[a].[i] <- (doOp op) r.[a].[i] 0)
+ let ifregzero a = iteri (fun i -> carry := !carry || r.[a].[i] <> 0)
+ let exchreg a b = iteri (fun i -> let t = r.[a].[i] in r.[a].[i] <- r.[b].[i]; r.[b].[i] <- t)
+ let opp fn = p := (fn !p 1) &&& 0xf
+ let iterir fn = for i in 0..13 do fn i
+ let move pairs = iterir (fun i -> List.iter (fun (a, b) -> r.[a].[i] <- r.[b].[i]) pairs)
+ let n = (code &&& 0b1111111100) >>> 2
+ pc := (!pc + 1) % 256
+ match code &&& 0b11 with
+ | 0b11 -> if not !carry' then pc := n
+ | 0b01 -> ret := !pc; pc := n
+ | 0b10 -> [| ifregzero 1; regsgte 0 2; setreg 2 1; zeroreg 2; shiftl 0; sub 2 0 2; setreg 0 2; add 2 0 2
+ regsgte 0 1; shiftr 2; shiftr 1; shiftr 0; sub 0 0 1; sub 0 0 2; add 0 0 1; add 0 0 2; zeroreg 1
+ regsgte1 2; negcdec false; negcdec true; setreg 1 0; opreg (-) 2; ifregzero 2; opreg (+) 2
+ exchreg 1 2; regsgte1 0; add 2 2 2; zeroreg 0; exchreg 0 1; opreg (-) 0; exchreg 0 2; opreg (+) 0
+ |].[16 * (n / 8 &&& 1) + (n / 16)] [|!p,!p; 3,12; 0,2; 0,13; 0,!p; 3,13; 2,2; 13,13|].[n % 8]
+ | 0b00 -> let arg = n / 16
+ match n % 16 with
+ | 0 -> () // no-op
+ | 1 -> s.[arg] <- 1
+ | 3 -> p := arg
+ | 4 when arg = 3 -> pc := !lastKey
+ | 4 when arg % 2 = 0 -> let r = arg / 2 in offset := r * 256
+ | 5 -> carry := s.[arg] <> 0; if arg = 0 then waiting := !waiting + 1
+ | 6 -> (if !p < 14 then r.[2].[!p] <- arg); opp (-)
+ | 7 -> opp (-)
+ | 9 -> s.[arg] <- 0
+ | 10 -> match arg with
+ | 0 -> visible := not !visible
+ | 2 -> exchreg 2 6 (0, 13)
+ | 4 -> move [5, 4; 4, 3; 3, 2]
+ | 6 -> move [0, 3; 3, 4; 4, 5]
+ | 8 -> visible := false
+ | 10 -> setreg 2 6 (0, 13)
+ | 12 -> iterir (fun i -> let t = r.[2].[i] in move [2,3; 3,4; 4,5]; r.[5].[i] <- t)
+ | 14 -> for i in 0..13 do for j in 0..7 do r.[j].[i] <- 0
+ | 11 -> carry := !p = arg
+ | 12 -> pc := !ret
+ | 13 -> for i in 0..11 do s.[i] <- 0
+ | 15 -> p := (!p + 1) &&& 0xf
+ let display () =
+ if not !visible then "" else
+ let render i a b =
+ (if b >= 8 then " "
+ elif i = 2 || i = 13 then (if a >= 8 then "-" else " ")
+ else string a) + (if b = 2 then "." else "")
+ Array.mapi2 render r.[0] r.[1] |> Array.rev |> Array.fold (+) ""
+ let code = let bits = let toBits b = [|for s in 0..7 -> 0x80uy >>> s &&& b |> min 1uy|]
+ rom |> Convert.FromBase64String |> Array.collect toBits
+ [for i in 0..767 -> List.sum [for b in 0..9 -> (int bits.[i * 10 + 9 - b]) <<< b]]
+ let rec step () =
+ let disp' = display ()
+ if disp' <> !disp then output disp'; disp := disp'
+ carry' := !carry; carry := false
+ exec code.[!offset + !pc]
+ if !waiting > 1 then
+ match input () with
+ | Some k ->
+ match List.tryFind (fst >> (=) k)
+ ['0',36; '1',28; '2',27; '3',26; '4',20; '5',19; '6',18; '7',52; '8',51; '9',50; '.',35; '-',54; '+',22
+ '*',30; '/',38; 'p',34; '~',59; '!',0; 'x',58; 'a',44; 's',43; 'c',42; 't',40; 'l',3; 'g',4; 'e',2
+ '^',6; 'q',46; 'f',14; 'w',12; 'r',11; '>',10; '<',8; ',',56; ' ',62] with
+ | Some (_, addr) -> lastKey := addr; s.[0] <- 1; waiting := 0
+ | None -> halt := k = '`'
+ | None -> ()
+ if not !halt then step () else disp'
+ step ()
+
+let rom = // HP-35 v2 ROM
+ "N2/4kBdRJEIREFRQsXzDajZ7u+ILiQ+r6vqGuaSoqg//q+r6gwMwqmoEN07MDAACDUQRC7k" +
+ "Qn6EwsLiQyjb/q+r6hLmfqO13d27OMTg0oDSzt3qjb0uvpFtqh9uo3zbTI3y67jUVPfj+dR" +
+ "X0ocQzlq767EfR1hOVtbLF7i57hMRIPGiZtbou6Y7K/6a6kUX961RJBBLUHOzuVSqzk6wrq" +
+ "gag8qlKYrwd3tYHCsR/DLuvb4viIwPNilsApH+LLgwP5qAu/r+n6foSqP67pmmp/romEq+6" +
+ "O+oDr7qNhmUtMHFqpLDGmcN6rEmJv0GuskO1UTd7OZ6JM/fqBFUzd6sbCgFMfCQHMs0OKIU" +
+ "zNDlkNBKOu/VxOVTlj0U5PmvvP6pMP7o0lyNqev3M4NGOwxuvfKpeufUzqkURPKgqesZu77" +
+ "fz8uKFqChaiVAn65VBLN6mUopWYSVaimaU2u7viSbplqpJuhntJ6h3s6jkoi5B4uQze0o65" +
+ "oi3K5jiKy9jhUJelG3VQVz+74N6S3463+zJ0suS7Ujvaizuyy5Eko/7/iPM4Knit1Ymo65D" +
+ "KRYybYMm0jIYoybY5m3MUOm0jstzGrqZlRsz+mEZDOWJ6hUpemcxq6lcxq6rpVq7rcxoycY" +
+ "5gydSMhhjJxQycZxy6TtMVj72MhhmFYJhGJYFTawwu74gQRBDqWi6h3+w6g+ORBEFKRB4tO" +
+ "qPzkOByUgsqct3ixay+WRYHAss8twc5bbwQXperq16fsbRCBsrP7LsORAzrMdiGFYNiWIYF" +
+ "hmDYVjDAwBDit7WJ/gsu/qrqGLm7Ok6KjKwyu0QpKkl+7N0sSjIjt+7vsmoB4B0O7JKKSX6" +
+ "PgQz7/pWRIS2opljoUQ+7tGAOzl+AN/kulnYhHzJPueAdzG1gydZMnH+aMnF9bMnHfZxuWc" +
+ "fZ65TgaMNTsuBxDhsMfrm+Oc5nqszFZUBtVJT9mnZT9nsQ2uWzJt32jJtfWTJt/mDJtm2bd" +
+ "Mi7rmYjslF7+qesLxZZ+WQ5alzs40uqb5s8uw46rOi4zlmJR20YeZ52YGx15Ok4lJTDBzDY" +
+ "NgGIYVgGJY6uWfiS5fobtLrkW67foju74sRJC0t+lfks+DAkLOi6g+OX6f+uRbrm3Mxyleq" +
+ "8vsmu7LMXGa2xUAMktmfqMumJCJGYlg2BYRh2BY5v5mT45YsTs4PNsxd6r+wwLpi1tDlqm7" +
+ "PzOSrjp+x/pmOC7DHrkw2BYBgWHYliGAYVhWDY3frkuYaul7fqznq8tnzOwwmDYBgmFYgdTH7"
+
+let test keys expected =
+ let keySequence = ref (List.ofSeq keys)
+ let testInput () =
+ match !keySequence with
+ | h :: t -> keySequence := t; Some h
+ | [] -> Some '`'
+ let res = calculator testInput (fun _ -> ()) rom
+ assert (res = expected)
+
+test "~1.2345678909x~35" "-1.234567890-35" // entry
+test "2 3+" " 5. " // add
+test "3 2-" " 1. " // subtract
+test "3 2*" " 6. " // multiply
+test "3 2/" " 1.5 " // divide
+test "4f" " .25 " // reciprocal
+test "25q" " 5. " // square root
+test "pl" " 1.144729886 " // ln
+test "pg" " .4971498728 " // log
+test "pe" " 23.14069264 " // exp
+test "ps" " .054803665 " // sin
+test "pc" " .9984971498 " // cos
+test "pt" " .0548861507 " // tan
+test "pgas" " 29.81161556 " // sin-1
+test "pgac" " 60.18838444 " // cos-1
+test "pat" " 72.34321286 " // tan-1
+test "1 2 3 4 Swrrr" " 2. " // stack
+test "123>456 ,<" " 123. " // memory
+test "9sctatacas" " 9.002983113 " // "Calculator Forensics" result
+test "9 2^" " 512. " // power
+
+calculator
+ (fun () -> if Console.KeyAvailable then
+ let k = Console.ReadKey true
+ if k.Key = ConsoleKey.Enter then Some ' '
+ elif k.Key = ConsoleKey.Escape then Some '`'
+ else Some (Char.ToLower k.KeyChar)
+ else None)
+ (printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%s")
+ rom |> ignore
View
22 HP35/FSharp/Calculator/Utility.fsx
@@ -0,0 +1,22 @@
+open System
+open System.IO
+open System.Collections
+
+let romToBase64 () =
+ let rec bytes acc = function
+ | a::b::c::d::e::f::g::h::t -> bytes ([a;b;c;d;e;f;g;h] :: acc) t
+ | [] -> List.rev acc
+ | _ -> failwith "Partial byte!"
+ File.ReadAllLines @"..\..\..\ROMs\35v2.obj"
+ |> List.ofArray
+ |> List.map (fun line -> Convert.ToInt32((line.Split ':').[1], 8))
+ |> List.map (fun i -> [ for b in 9 .. -1 .. 0 -> 1 <<< b &&& i <> 0])
+ |> List.concat
+ |> bytes []
+ |> Seq.map (
+ List.rev
+ >> List.mapi (fun i b -> if b then int (2. ** float i) else 0)
+ >> List.sum
+ >> byte)
+ |> Seq.toArray
+ |> Convert.ToBase64String
View
6 HP35/FSharp/Disassembler/App.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5,Profile=Client" />
+ </startup>
+</configuration>
View
57 HP35/FSharp/Disassembler/Disassembler.fsproj
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{f66588c3-4f5e-473c-aa53-5efefc25ac41}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>Disassembler</RootNamespace>
+ <AssemblyName>Disassembler</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <Name>Disassembler</Name>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <Tailcalls>false</Tailcalls>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <DocumentationFile>bin\Debug\Disassembler.XML</DocumentationFile>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <Tailcalls>true</Tailcalls>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <DocumentationFile>bin\Release\Disassembler.XML</DocumentationFile>
+ </PropertyGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
+ <ItemGroup>
+ <Compile Include="Program.fs" />
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="mscorlib" />
+ <Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Numerics" />
+ </ItemGroup>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
92 HP35/FSharp/Disassembler/Program.fs
@@ -0,0 +1,92 @@
+let disassemble code =
+ let n = (code &&& 0b1111111100) >>> 2
+ match code &&& 0b11 with
+ | 0b11 -> sprintf "goto(%d)" n, sprintf "goto %d" n
+ | 0b01 -> sprintf "jsb(%d)" n, sprintf "jsb %d" n
+ | 0b10 ->
+ let instr = [|
+ "ifregzero(b,%s)", "if b[%s] = 0"
+ "regsgte(a,c,%s)", "if a >= c[%s]"
+ "setreg(c,b,%s)", "b -> c[%s]"
+ "zeroreg(c,%s)", "0 -> c[%s]"
+ "shiftl(a,%s)", "shiftl a[%s]"
+ "sub(c,a,c,%s)", "a - c -> c[%s]"
+ "setreg(a,c,%s)", "c -> a[%s]"
+ "add(c,a,c,%s)", "a + c -> c[%s]"
+ "regsgte(a,b,%s)", "if a >= b[%s]"
+ "shiftr(c,%s)", "shiftr c[%s]"
+ "shiftr(b,%s)", "shiftr b[%s]"
+ "shiftr(a,%s)", "shiftr a[%s]"
+ "sub(a,a,b,%s)", "a - b -> a[%s]"
+ "sub(a,a,c,%s)", "a - c -> a[%s]"
+ "add(a,a,b,%s)", "a + b -> a[%s]"
+ "add(a,a,c,%s)", "a + c -> a[%s]"
+ "zeroreg(b,%s)", "0 -> b[%s]"
+ "regsgte1(c,%s)", "if c[%s] >= 1"
+ "negc(%s)", "0 - c -> c[%s]"
+ "negsubc(%s)", "0 - c - 1 -> c[%s]"
+ "setreg(b,a,%s)", "a -> b[%s]"
+ "decreg(c,%s)", "c - 1 -> c[%s]"
+ "ifregzero(c,%s)", "if c[%s] = 0"
+ "increg(c,%s)", "c + 1 -> c[%s]"
+ "exchreg(b,c,%s)", "b <-> c[%s]"
+ "regsgte1(a,%s)", "if a[%s] >= 1"
+ "add(c,c,c,%s)", "c + c -> c[%s]"
+ "zeroreg(a,%s)", "0 -> a[%s]"
+ "exchreg(a,b,%s)", "a <-> b[%s]"
+ "decreg(a,%s)", "a - 1 -> a[%s]"
+ "exchreg(a,c,%s)", "a <-> c[%s]"
+ "increg(a,%s)", "a + 1 -> a[%s]" |]
+ let f = n / 8
+ let i = instr.[16 * (f &&& 1) + (f / 2)]
+ let field = [|
+ "-1,-1", "p"
+ "3,12", "m"
+ "0,2", "x"
+ "0,13", "w"
+ "0,-1", "wp"
+ "3,13", "ms"
+ "2,2", "xs"
+ "13,13", "s" |]
+ let fld (tup : string * string -> string) = (tup i).Replace("%s", tup field.[n % 8])
+ fld fst, fld snd
+ | 0b00 ->
+ let arg = n / 16
+ match n % 16 with
+ | 0 -> "nop", "no operation"
+ | 1 when arg < 12 -> sprintf "sets(%d,1)" arg, sprintf "1 -> s%d" arg
+ | 3 -> sprintf "setp(%d)" arg, sprintf "%d -> p" arg
+ | 4 when arg = 3 -> "keyrom", "key -> rom"
+ | 4 when arg % 2 = 0 -> let r = arg / 2 in sprintf "setrom(%d)" r, sprintf "rom %d" r
+ | 5 when arg < 12 -> sprintf "tests(%d)" arg, sprintf "if s%d = 0" arg
+ | 6 when arg < 10 -> sprintf "loadconst(%d)" arg, sprintf "load %d" arg
+ | 7 when arg = 0 -> "decp", "p - 1 -> p"
+ | 9 when arg < 12 -> sprintf "sets(%d,0)" arg, sprintf "0 -> s%d" arg
+ | 10 when arg % 2 = 0 ->
+ [| "disptoggle", "disptoggle"
+ "exchreg(c,m,0,13)", "c <-> m"
+ "cstack", "c -> stack"
+ "stacka", "stack -> a"
+ "dispoff", "dispoff"
+ "setreg(c,m,0,13)", "m -> c"
+ "downrot", "rotd"
+ "clearregs", "clearregs" |].[arg / 2]
+ | 11 -> sprintf "testp(%d)" arg, sprintf "if p # %d" arg
+ | 12 when arg = 0 -> "retn", "return"
+ | 13 when arg = 0 -> "clears", "clearstatus"
+ | 14 when arg = 11 -> "// NOT USED BY HP-35", "data -> c"
+ | 15 when arg = 0 -> "incp", "p + 1 -> p"
+
+open System
+open System.IO
+
+let output = new StreamWriter(@"..\..\ROMs\rom35v2.js")
+output.WriteLine("var rom = [");
+// Disassemble bits from http://www.pmonta.com/calculators/hp-35/35v2.obj
+File.ReadAllLines @"..\..\ROMs\35v2.obj"
+|> Seq.map (fun line -> Convert.ToInt32((line.Split ':').[1], 8))
+|> Seq.map disassemble
+|> Seq.iteri (fun i (js, asm) ->
+ output.WriteLine((" " + js + ",").PadRight(25, ' ') + (sprintf "// %s" asm)))
+output.WriteLine("];");
+output.Close()
View
32 HP35/FSharp/HP-35.sln
@@ -0,0 +1,32 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 11
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Disassembler", "Disassembler\Disassembler.fsproj", "{F66588C3-4F5E-473C-AA53-5EFEFC25AC41}"
+EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Assembler", "Assembler\Assembler.fsproj", "{E51037E5-0310-44B9-B8F1-ED15AAB3BFCF}"
+EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Calculator", "Calculator\Calculator.fsproj", "{B112CD0B-8351-47B2-BC14-2CA0D7B8C978}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B112CD0B-8351-47B2-BC14-2CA0D7B8C978}.Debug|x86.ActiveCfg = Debug|x86
+ {B112CD0B-8351-47B2-BC14-2CA0D7B8C978}.Debug|x86.Build.0 = Debug|x86
+ {B112CD0B-8351-47B2-BC14-2CA0D7B8C978}.Release|x86.ActiveCfg = Release|x86
+ {B112CD0B-8351-47B2-BC14-2CA0D7B8C978}.Release|x86.Build.0 = Release|x86
+ {E51037E5-0310-44B9-B8F1-ED15AAB3BFCF}.Debug|x86.ActiveCfg = Debug|x86
+ {E51037E5-0310-44B9-B8F1-ED15AAB3BFCF}.Debug|x86.Build.0 = Debug|x86
+ {E51037E5-0310-44B9-B8F1-ED15AAB3BFCF}.Release|x86.ActiveCfg = Release|x86
+ {E51037E5-0310-44B9-B8F1-ED15AAB3BFCF}.Release|x86.Build.0 = Release|x86
+ {F66588C3-4F5E-473C-AA53-5EFEFC25AC41}.Debug|x86.ActiveCfg = Debug|x86
+ {F66588C3-4F5E-473C-AA53-5EFEFC25AC41}.Debug|x86.Build.0 = Debug|x86
+ {F66588C3-4F5E-473C-AA53-5EFEFC25AC41}.Release|x86.ActiveCfg = Release|x86
+ {F66588C3-4F5E-473C-AA53-5EFEFC25AC41}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
769 HP35/FSharp/ROMs/35v2.asm
@@ -0,0 +1,769 @@
+ jsb @067
+ go to @277
+ 0 -> s8
+ go to @005
+ 1 -> s5
+ 1 -> s9
+ 1 -> s2
+ select rom 2
+ jsb @124
+ go to @102
+ go to @027
+ go to @060
+ stack -> a
+ go to @331
+ 0 -> a[w]
+ a + 1 -> a[p]
+ 0 -> b[w]
+ select rom 1
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ go to @032
+ jsb @232
+ c exchange m
+ m -> c
+ go to @077
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ return
+ 3 -> p
+ 0 - c -> c[x]
+ stack -> a
+ go to @020
+ go to @164
+ 11 -> p
+ return
+ no operation
+ go to @040
+ 1 -> s5
+ 1 -> s1
+ go to @056
+ 1 -> s9
+ go to @047
+ 1 -> s10
+ go to @302
+ 0 -> b[w]
+ select rom 1
+ down rotate
+ go to @333
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ go to @022
+ go to @231
+ clear registers
+ jsb @355
+ go to @335
+ go to @166
+ shift right a[w]
+ 1 -> s3
+ go to @340
+ c -> stack
+ clear status
+ shift right a[w]
+ go to @335
+ m -> c
+ go to @333
+ a -> b[w]
+ 0 -> a[xs]
+ shift left a[ms]
+ a - 1 -> a[x]
+ go to @207
+ if c[xs] = 0
+ go to @215
+ a exchange b[ms]
+ 13 -> p
+ go to @215
+ a exchange b[w]
+ 0 -> a[w]
+ if s3 = 0
+ go to @124
+ a - 1 -> a[s]
+ 0 - c - 1 -> c[s]
+ if s7 = 0
+ go to @127
+ c -> stack
+ 1 -> s7
+ 0 -> c[w]
+ c - 1 -> c[x]
+ a exchange c[s]
+ if p # 11
+ go to @107
+ jsb @107
+ 1 -> s6
+ jsb @345
+ shift right a[ms]
+ if p # 12
+ go to @136
+ b exchange c[w]
+ c + 1 -> c[w]
+ 1 -> p
+ shift left a[wp]
+ p + 1 -> p
+ if c[p] = 0
+ go to @146
+ c - 1 -> c[w]
+ b exchange c[w]
+ a exchange c[m]
+ if p # 3
+ go to @257
+ a exchange c[m]
+ 0 -> a[x]
+ if s4 = 0
+ go to @137
+ go to @172
+ jsb @124
+ select rom 1
+ 1 -> s4
+ if s11 = 0
+ go to @034
+ shift right a[w]
+ jsb @345
+ a -> b[x]
+ shift right a[w]
+ a -> b[xs]
+ a - b -> a[x]
+ a exchange c[x]
+ if b[xs] = 0
+ go to @203
+ 0 - c -> c[x]
+ a - c -> c[x]
+ c -> a[x]
+ jsb @360
+ go to @335
+ shift right a[ms]
+ p - 1 -> p
+ if p # 2
+ go to @107
+ 12 -> p
+ 0 -> a[w]
+ 0 -> a[ms]
+ a + 1 -> a[p]
+ a + 1 -> a[p]
+ 2 -> p
+ p + 1 -> p
+ a - 1 -> a[p]
+ go to @226
+ if b[p] = 0
+ go to @221
+ a + 1 -> a[p]
+ a exchange b[w]
+ return
+ 0 - c - 1 -> c[s]
+ stack -> a
+ 0 -> b[w]
+ a + 1 -> a[xs]
+ a + 1 -> a[xs]
+ c + 1 -> c[xs]
+ c + 1 -> c[xs]
+ if a >= c[x]
+ go to @243
+ a exchange c[w]
+ a exchange c[m]
+ if c[m] = 0
+ go to @247
+ a exchange c[w]
+ b exchange c[m]
+ if a >= c[x]
+ go to @276
+ shift right b[w]
+ a + 1 -> a[x]
+ if b[w] = 0
+ go to @276
+ go to @250
+ c -> a[m]
+ if s6 = 0
+ go to @264
+ p - 1 -> p
+ c - 1 -> c[x]
+ shift right b[wp]
+ 12 -> p
+ if c[m] = 0
+ go to @160
+ c + 1 -> c[x]
+ 1 -> s11
+ if a[p] >= 1
+ go to @157
+ shift left a[m]
+ go to @272
+ select rom 1
+ jsb @355
+ 1 -> s5
+ go to @335
+ shift right a[w]
+ c -> a[s]
+ 0 -> s8
+ go to @317
+ c + 1 -> c[xs]
+ 1 -> s8
+ if s5 = 0
+ go to @315
+ c + 1 -> c[x]
+ go to @306
+ display toggle
+ if s0 = 0
+ go to @307
+ 0 -> s0
+ p - 1 -> p
+ if p # 12
+ go to @320
+ display off
+ if s8 = 0
+ go to @314
+ shift left a[w]
+ 0 -> s5
+ keys -> rom address
+ c -> stack
+ a exchange c[w]
+ jsb @375
+ 1 -> s7
+ jsb @345
+ jsb @116
+ go to @143
+ if s4 = 0
+ go to @344
+ a + b -> a[xs]
+ go to @373
+ 0 - c - 1 -> c[s]
+ 0 -> s10
+ go to @303
+ a exchange c[xs]
+ 0 -> c[wp]
+ c - 1 -> c[wp]
+ 0 -> c[xs]
+ if a[xs] >= 1
+ go to @375
+ 0 -> c[w]
+ clear status
+ c -> a[w]
+ 12 -> p
+ if c[xs] = 0
+ go to @367
+ 0 - c -> c[x]
+ c - 1 -> c[xs]
+ go to @347
+ 5 -> p
+ a exchange c[x]
+ if s4 = 0
+ go to @104
+ a exchange b[x]
+ 0 -> b[x]
+ go to @172
+ if c[m] >= 1
+ go to @356
+ go to @355
+ go to @363
+ a exchange b[w]
+ jsb @050
+ stack -> a
+ jsb @050
+ stack -> a
+ if s9 = 0
+ go to @011
+ a exchange c[w]
+ if s5 = 0
+ go to @022
+ 0 -> c[s]
+ jsb @246
+ c -> stack
+ jsb @245
+ jsb @230
+ jsb @045
+ stack -> a
+ jsb @246
+ if s10 = 0
+ go to @332
+ 0 -> a[w]
+ a + 1 -> a[p]
+ a -> b[m]
+ a exchange c[m]
+ c - 1 -> c[x]
+ shift right b[wp]
+ if c[xs] = 0
+ go to @031
+ shift right a[wp]
+ c + 1 -> c[x]
+ go to @035
+ shift right a[w]
+ shift right b[w]
+ c -> stack
+ b exchange c[w]
+ go to @101
+ b exchange c[w]
+ 4 -> p
+ go to @336
+ c -> stack
+ a exchange c[w]
+ if c[p] = 0
+ go to @055
+ 0 - c -> c[w]
+ c -> a[w]
+ b -> c[x]
+ go to @313
+ c -> a[w]
+ if s1 = 0
+ go to @045
+ if s10 = 0
+ go to @155
+ if s5 = 0
+ go to @025
+ 0 - c - 1 -> c[s]
+ a exchange c[s]
+ go to @015
+ shift right b[wp]
+ a - 1 -> a[s]
+ go to @072
+ c + 1 -> c[s]
+ a exchange b[wp]
+ a + c -> c[wp]
+ a exchange b[w]
+ a -> b[w]
+ a - c -> a[wp]
+ go to @073
+ stack -> a
+ shift right a[w]
+ a exchange c[wp]
+ a exchange b[w]
+ shift left a[wp]
+ c -> stack
+ a + 1 -> a[s]
+ a + 1 -> a[s]
+ go to @043
+ 0 -> c[w]
+ 0 -> b[x]
+ c + 1 -> c[p]
+ jsb @267
+ c - 1 -> c[p]
+ stack -> a
+ a exchange c[w]
+ 4 -> p
+ jsb @244
+ 6 -> p
+ jsb @233
+ 8 -> p
+ jsb @233
+ 2 -> p
+ load constant 8
+ 10 -> p
+ jsb @233
+ jsb @216
+ jsb @233
+ jsb @314
+ shift left a[w]
+ jsb @233
+ b -> c[w]
+ jsb @313
+ jsb @314
+ c + c -> c[w]
+ jsb @246
+ if s9 = 0
+ go to @154
+ 0 - c - 1 -> c[s]
+ jsb @230
+ 0 -> s1
+ 0 -> c[w]
+ c - 1 -> c[p]
+ c + 1 -> c[x]
+ if s1 = 0
+ go to @245
+ jsb @246
+ jsb @314
+ c + c -> c[w]
+ jsb @245
+ jsb @314
+ c + c -> c[w]
+ c + c -> c[w]
+ jsb @225
+ c + c -> c[w]
+ jsb @353
+ jsb @314
+ 10 -> p
+ jsb @234
+ jsb @216
+ 8 -> p
+ jsb @235
+ 2 -> p
+ load constant 8
+ 6 -> p
+ jsb @234
+ 4 -> p
+ jsb @234
+ jsb @234
+ a exchange b[w]
+ shift right c[w]
+ 13 -> p
+ load constant 5
+ go to @373
+ 6 -> p
+ load constant 8
+ load constant 6
+ load constant 5
+ load constant 2
+ load constant 4
+ load constant 9
+ if s1 = 0
+ go to @332
+ return
+ 0 -> a[w]
+ a + 1 -> a[p]
+ select rom 0
+ select rom 2
+ shift left a[w]
+ shift right b[ms]
+ b exchange c[w]
+ go to @241
+ c + 1 -> c[s]
+ a - b -> a[w]
+ go to @240
+ a + b -> a[w]
+ select rom 2
+ select rom 2
+ a - c -> c[x]
+ select rom 2
+ c + 1 -> c[p]
+ a - c -> a[w]
+ go to @250
+ a + c -> a[w]
+ shift left a[w]
+ p - 1 -> p
+ shift right c[wp]
+ if p # 0
+ go to @251
+ go to @055
+ c + 1 -> c[p]
+ a - b -> a[ms]
+ go to @262
+ a + b -> a[ms]
+ shift left a[ms]
+ p - 1 -> p
+ if p # 0
+ go to @263
+ go to @055
+ p - 1 -> p
+ a + b -> a[ms]
+ go to @333
+ select rom 0
+ c - 1 -> c[xs]
+ c - 1 -> c[xs]
+ 0 -> a[x]
+ a - c -> a[s]
+ if a[s] >= 1
+ go to @306
+ select rom 2
+ if a >= b[m]
+ go to @312
+ 0 - c - 1 -> c[s]
+ a exchange b[w]
+ a - b -> a[w]
+ select rom 2
+ 0 -> c[w]
+ 11 -> p
+ load constant 7
+ load constant 8
+ load constant 5
+ load constant 3
+ load constant 9
+ load constant 8
+ load constant 1
+ load constant 6
+ load constant 3
+ load constant 5
+ 12 -> p
+ return
+ select rom 0
+ a + b -> a[x]
+ go to @336
+ c - 1 -> c[p]
+ c + 1 -> c[s]
+ if p # 0
+ go to @273
+ a exchange c[x]
+ 0 -> a[x]
+ if c[p] >= 1
+ go to @346
+ shift right a[w]
+ shift right c[w]
+ b exchange c[x]
+ 0 -> c[x]
+ 12 -> p
+ go to @256
+ select rom 2
+ shift right b[wp]
+ shift right b[wp]
+ c - 1 -> c[s]
+ go to @354
+ a + c -> c[wp]
+ a - b -> a[wp]
+ b exchange c[wp]
+ b -> c[w]
+ a - 1 -> a[s]
+ go to @356
+ a exchange c[wp]
+ stack -> a
+ if b[s] = 0
+ go to @001
+ shift left a[w]
+ a exchange c[wp]
+ c -> stack
+ shift right b[wp]
+ c - 1 -> c[s]
+ b exchange c[s]
+ select rom 0
+ a exchange b[s]
+ a + 1 -> a[s]
+ shift right c[ms]
+ shift left a[wp]
+ go to @022
+ stack -> a
+ jsb @246
+ c -> a[w]
+ if s8 = 0
+ go to @103
+ 0 -> a[w]
+ a - c -> a[m]
+ go to @000
+ shift right a[w]
+ c - 1 -> c[s]
+ go to @000
+ c + 1 -> c[s]
+ a -> b[w]
+ jsb @226
+ a - 1 -> a[p]
+ go to @021
+ a exchange b[wp]
+ a -> b[s]
+ a + b -> a[s]
+ go to @001
+ 7 -> p
+ jsb @155
+ 8 -> p
+ jsb @235
+ 9 -> p
+ jsb @234
+ jsb @376
+ 10 -> p
+ jsb @234
+ jsb @175
+ 11 -> p
+ jsb @234
+ jsb @337
+ jsb @234
+ jsb @271
+ jsb @234
+ jsb @366
+ a exchange c[w]
+ a - c -> c[w]
+ if b[xs] = 0
+ go to @060
+ a - c -> c[w]
+ a exchange b[w]
+ p - 1 -> p
+ shift left a[w]
+ if p # 1
+ go to @061
+ a exchange c[w]
+ if c[s] = 0
+ go to @071
+ 0 - c - 1 -> c[m]
+ c + 1 -> c[x]
+ 11 -> p
+ jsb @305
+ if s9 = 0
+ go to @006
+ if s5 = 0
+ go to @224
+ jsb @366
+ jsb @247
+ go to @224
+ jsb @366
+ jsb @354
+ 0 -> b[ms]
+ jsb @271
+ 11 -> p
+ jsb @233
+ jsb @337
+ 10 -> p
+ jsb @233
+ jsb @175
+ 9 -> p
+ jsb @233
+ jsb @376
+ 8 -> p
+ jsb @233
+ jsb @233
+ jsb @233
+ 13 -> p
+ b exchange c[w]
+ a exchange c[w]
+ load constant 6
+ go to @216
+ if s2 = 0
+ go to @136
+ a + 1 -> a[x]
+ if a[xs] >= 1
+ go to @302
+ a - b -> a[ms]
+ go to @131
+ a + b -> a[ms]
+ shift left a[w]
+ c - 1 -> c[x]
+ go to @134
+ shift right a[w]
+ 0 -> c[wp]
+ a exchange c[x]
+ if c[s] = 0
+ go to @154
+ a exchange b[w]
+ a - b -> a[w]
+ 0 - c - 1 -> c[x]
+ shift right a[w]
+ b exchange c[w]
+ 0 -> c[w]
+ c - 1 -> c[m]
+ if s2 = 0
+ go to @166
+ load constant 4
+ c + 1 -> c[m]
+ go to @171
+ load constant 6
+ if p # 1
+ go to @165
+ shift right c[w]
+ shift right c[w]
+ if s2 = 0
+ go to @224
+ return
+ 7 -> p
+ load constant 3
+ load constant 3
+ load constant 0
+ load constant 8
+ load constant 5
+ load constant 0
+ load constant 9
+ go to @352
+ jsb @226
+ a + 1 -> a[p]
+ a -> b[w]
+ c - 1 -> c[s]
+ go to @206
+ shift right a[wp]
+ a exchange c[w]
+ shift left a[ms]
+ a exchange c[w]
+ a - 1 -> a[s]
+ go to @210
+ 0 -> a[w]
+ a + 1 -> a[p]
+ jsb @304
+ select rom 1
+ shift right a[wp]
+ a - 1 -> a[s]
+ go to @225
+ a + b -> a[wp]
+ a exchange b[s]
+ return
+ select rom 1
+ shift right a[w]
+ b exchange c[w]
+ go to @240
+ a + b -> a[w]
+ c - 1 -> c[s]
+ go to @237
+ a exchange c[w]
+ shift left a[ms]
+ a exchange c[w]
+ go to @155
+ 3 -> p
+ a + c -> c[x]
+ a - c -> c[s]
+ go to @253
+ 0 - c -> c[s]
+ a exchange b[m]
+ 0 -> a[w]
+ if p # 12
+ go to @305
+ if c[m] >= 1
+ go to @266
+ if s1 = 0
+ go to @000
+ b -> c[wp]
+ a - 1 -> a[m]
+ c + 1 -> c[xs]
+ b exchange c[wp]
+ a exchange c[m]
+ select rom 1
+ 0 -> s8
+ load constant 6
+ load constant 9
+ load constant 3
+ load constant 1
+ load constant 4
+ load constant 7
+ load constant 1
+ go to @346
+ a + 1 -> a[m]
+ go to @144
+ a + b -> a[w]
+ c - 1 -> c[p]
+ go to @304
+ shift right a[w]
+ p + 1 -> p
+ if p # 13
+ go to @305
+ c + 1 -> c[x]
+ 0 -> a[s]
+ 12 -> p
+ 0 -> b[w]
+ if a[p] >= 1
+ go to @326
+ shift left a[w]
+ c - 1 -> c[x]
+ if a[w] >= 1
+ go to @317
+ 0 -> c[w]
+ a -> b[x]
+ a + b -> a[w]
+ if a[s] >= 1
+ go to @307
+ a exchange c[m]
+ c -> a[w]
+ 0 -> b[w]
+ 12 -> p
+ go to @172
+ 9 -> p
+ load constant 3
+ load constant 1
+ load constant 0
+ load constant 1
+ load constant 7
+ load constant 9
+ load constant 8
+ load constant 0
+ load constant 5
+ load constant 5
+ load constant 3
+ go to @335
+ a exchange c[w]
+ a -> b[w]
+ c -> a[m]
+ c + c -> c[xs]
+ go to @136
+ c + 1 -> c[xs]
+ shift right a[w]
+ c + 1 -> c[x]
+ go to @362
+ go to @147
+ 0 -> c[w]
+ 12 -> p
+ load constant 2
+ load constant 3
+ load constant 0
+ load constant 2
+ load constant 5
+ go to @201
+ 5 -> p
+ go to @176
+
View
768 HP35/FSharp/ROMs/35v2.obj
@@ -0,0 +1,768 @@
+0000:0335
+0001:1377
+0002:1044
+0003:0027
+0004:0504
+0005:1104
+0006:0204
+0007:0420
+0010:0521
+0011:0413
+0012:0137
+0013:0303
+0014:0650
+0015:1547
+0016:1356
+0017:1742
+0020:0056
+0021:0220
+0022:1752
+0023:1752
+0024:1752
+0025:0153
+0026:1151
+0027:0250
+0030:1250
+0031:0377
+0032:1752
+0033:1752
+0034:1752
+0035:0060
+0036:0314
+0037:0252
+0040:0650
+0041:0103
+0042:0723
+0043:1314
+0044:0060
+0045:0000
+0046:0203
+0047:0504
+0050:0104
+0051:0273
+0052:1104
+0053:0237
+0054:1204
+0055:1413
+0056:0056
+0057:0220
+0060:1450
+0061:1557
+0062:1752
+0063:1752
+0064:1752
+0065:0113
+0066:1147
+0067:1650
+0070:1665
+0071:1567
+0072:0733
+0073:1316
+0074:0304
+0075:1603
+0076:0450
+0077:0064
+0100:1316
+0101:1567
+0102:1250
+0103:1557
+0104:0456
+0105:1372
+0106:0426
+0107:1552
+0110:1037
+0111:0672
+0112:1067
+0113:1466
+0114:1514
+0115:1067
+0116:1456
+0117:1356
+0120:0324
+0121:0523
+0122:1576
+0123:0376
+0124:0724
+0125:0537
+0126:0450
+0127:0704
+0130:0316
+0131:0552
+0132:1676
+0133:1354
+0134:0437
+0135:0435
+0136:0604
+0137:1625
+0140:1326
+0141:1454
+0142:0573
+0143:1056
+0144:0756
+0145:0114
+0146:0422
+0147:0074
+0150:0642
+0151:0633
+0152:0556
+0153:1056
+0154:1646
+0155:0354
+0156:1277
+0157:1646
+0160:1352
+0161:0424
+0162:0577
+0163:0753
+0164:0521
+0165:0220
+0166:0404
+0167:1324
+0170:0163
+0171:1316
+0172:1625
+0173:0452
+0174:1316
+0175:0472
+0176:1412
+0177:1652
+0200:0032
+0201:1017
+0202:0252
+0203:0512
+0204:0612
+0205:1701
+0206:1567
+0207:1326
+0210:0034
+0211:0254
+0212:0437
+0213:1414
+0214:1356
+0215:1366
+0216:1742
+0217:1742
+0220:0214
+0221:0074
+0222:1542
+0223:1133
+0224:0002
+0225:1107
+0226:1742
+0227:1456
+0230:0060
+0231:0376
+0232:0650
+0233:0056
+0234:1772
+0235:1772
+0236:0772
+0237:0772
+0240:0112
+0241:1217
+0242:1656
+0243:1646
+0244:0646
+0245:1237
+0246:1656
+0247:1046
+0250:0112
+0251:1373
+0252:1216
+0253:1752
+0254:0016
+0255:1373
+0256:1243
+0257:0606
+0260:0624
+0261:1323
+0262:0034
+0263:0552
+0264:1222
+0265:1414
+0266:0646
+0267:0703
+0270:0752
+0271:1304
+0272:1142
+0273:0677
+0274:0406
+0275:1353
+0276:0220
+0277:1665
+0300:0504
+0301:1567
+0302:1316
+0303:0636
+0304:1044
+0305:1477
+0306:0772
+0307:1004
+0310:0524
+0311:1467
+0312:0752
+0313:1433
+0314:0050
+0315:0024
+0316:1437
+0317:0044
+0320:0034
+0321:1454
+0322:1503
+0323:1050
+0324:1024
+0325:1463
+0326:0416
+0327:0544
+0330:0320
+0331:0450
+0332:1656
+0333:1765
+0334:0704
+0335:1625
+0336:0471
+0337:0617
+0340:0424
+0341:1623
+0342:1632
+0343:1757
+0344:0376
+0345:1244
+0346:1417
+0347:1672
+0350:0322
+0351:0562
+0352:0332
+0353:1172
+0354:1767
+0355:0316
+0356:0064
+0357:0616
+0360:1414
+0361:0672
+0362:1737
+0363:0252
+0364:0572
+0365:1637
+0366:0514
+0367:1652
+0370:0424
+0371:0423
+0372:1452
+0373:0052
+0374:0753
+0375:0146
+0376:1673
+0377:1667
+0400:1717
+0401:1456
+0402:0241
+0403:0650
+0404:0241
+0405:0650
+0406:1124
+0407:0047
+0410:1656
+0411:0524
+0412:0113
+0413:0336
+0414:1231
+0415:0450
+0416:1225
+0417:1141
+0420:0225
+0421:0650
+0422:1231
+0423:1224
+0424:1553
+0425:1356
+0426:1742
+0427:0446
+0430:1646
+0431:0552
+0432:1222
+0433:0672
+0434:0147
+0435:1322
+0436:0752
+0437:0167
+0440:1316
+0441:1216
+0442:0450
+0443:1056
+0444:0407
+0445:1056
+0446:0414
+0447:1573
+0450:0450
+0451:1656
+0452:0642
+0453:0267
+0454:0256
+0455:0616
+0456:0212
+0457:1457
+0460:0616
+0461:0124
+0462:0227
+0463:1224
+0464:0667
+0465:0524
+0466:0127
+0467:0376
+0470:1676
+0471:0067
+0472:1222
+0473:1576
+0474:0353
+0475:0776
+0476:1462
+0477:0722
+0500:1456
+0501:0456
+0502:1522
+0503:0357
+0504:0650
+0505:1316
+0506:1662
+0507:1456
+0510:0422
+0511:0450
+0512:1776
+0513:1776
+0514:0217
+0515:0316
+0516:0052
+0517:0742
+0520:1335
+0521:0542
+0522:0650
+0523:1656
+0524:0414
+0525:1221
+0526:0614
+0527:1155
+0530:1014
+0531:1155
+0532:0214
+0533:1030
+0534:1214
+0535:1155
+0536:1071
+0537:1155
+0540:1461
+0541:0416
+0542:1155
+0543:0216
+0544:1455
+0545:1461
+0546:1256
+0547:1231
+0550:1124
+0551:0663
+0552:0376
+0553:1141
+0554:0144
+0555:0316
+0556:0542
+0557:0752
+0560:0124
+0561:1227
+0562:1231
+0563:1461
+0564:1256
+0565:1225
+0566:1461
+0567:1256
+0570:1256
+0571:1125
+0572:1256
+0573:1655
+0574:1461
+0575:1214
+0576:1161
+0577:1071
+0600:1014
+0601:1165
+0602:0214
+0603:1030
+0604:0614
+0605:1161
+0606:0414
+0607:1161
+0610:1161
+0611:1456
+0612:1116
+0613:1514
+0614:0530
+0615:1757
+0616:0614
+0617:1030
+0620:0630
+0621:0530
+0622:0230
+0623:0430
+0624:1130
+0625:0124
+0626:1553
+0627:0060
+0630:1356
+0631:1742
+0632:0020
+0633:0420
+0634:0416
+0635:1226
+0636:1056
+0637:1207
+0640:0776
+0641:1416
+0642:1203
+0643:1616
+0644:0420
+0645:0420
+0646:0512
+0647:0420
+0650:0742
+0651:1516
+0652:1243
+0653:1716
+0654:0416
+0655:0034
+0656:1122
+0657:0054
+0660:1247
+0661:0267
+0662:0742
+0663:1426
+0664:1313
+0665:1626
+0666:0426
+0667:0034
+0670:0054
+0671:1317
+0672:0267
+0673:0034
+0674:1626
+0675:1557
+0676:0020
+0677:0572
+0700:0572
+0701:1352
+0702:1536
+0703:1176
+0704:1433
+0705:0420
+0706:1006
+0707:1453
+0710:0376
+0711:1456
+0712:1416
+0713:0420
+0714:0316
+0715:1314
+0716:0730
+0717:1030
+0720:0530
+0721:0330
+0722:1130
+0723:1030
+0724:0130
+0725:0630
+0726:0330
+0727:0530
+0730:1414
+0731:0060
+0732:0020
+0733:1612
+0734:1573
+0735:0542
+0736:0776
+0737:0054
+0740:1357
+0741:1652
+0742:1352
+0743:0142
+0744:1633
+0745:1316
+0746:1116
+0747:1052
+0750:0312
+0751:1414
+0752:1273
+0753:0420
+0754:1222
+0755:1222
+0756:0576
+0757:1663
+0760:0722
+0761:1422
+0762:1062
+0763:0216
+0764:1576
+0765:1673
+0766:1662
+0767:0650
+0770:0036
+0771:0007
+0772:0416
+0773:1662
+0774:0450
+0775:1222
+0776:0576
+0777:1076
+1000:0020
+1001:1476
+1002:1776
+1003:1126
+1004:0422
+1005:0113
+1006:0650
+1007:1231
+1010:0616
+1011:1024
+1012:0417
+1013:1356
+1014:1506
+1015:0003
+1016:1316
+1017:0576
+1020:0003
+1021:0776
+1022:0456
+1023:1131
+1024:1542
+1025:0107
+1026:1462
+1027:0476
+1030:1636
+1031:0007
+1032:0714
+1033:0665
+1034:1014
+1035:1165
+1036:1114
+1037:1161
+1040:1771
+1041:1214
+1042:1161
+1043:0765
+1044:1314
+1045:1161
+1046:1575
+1047:1161
+1050:1345
+1051:1161
+1052:1731
+1053:1656
+1054:0516
+1055:0032
+1056:0303
+1057:0516
+1060:1456
+1061:0034
+1062:0416
+1063:0154
+1064:0307
+1065:1656
+1066:0676
+1067:0347
+1070:0346
+1071:0752
+1072:1314
+1073:1425
+1074:1124
+1075:0033
+1076:0524
+1077:1123
+1100:1731
+1101:1235
+1102:1123
+1103:1731
+1104:1661
+1105:0066
+1106:1345
+1107:1314
+1110:1155
+1111:1575
+1112:1214
+1113:1155
+1114:0765
+1115:1114
+1116:1155
+1117:1771
+1120:1014
+1121:1155
+1122:1155
+1123:1155
+1124:1514
+1125:1056
+1126:1656
+1127:0630
+1130:1073
+1131:0224
+1132:0573
+1133:1752
+1134:1172
+1135:1413
+1136:1426
+1137:0547
+1140:1626
+1141:0416
+1142:0552
+1143:0563
+1144:1316
+1145:0322
+1146:1652
+1147:0676
+1150:0663
+1151:1456
+1152:1416
+1153:0352
+1154:1316
+1155:1056
+1156:0316
+1157:0546
+1160:0224
+1161:0733
+1162:0430
+1163:0746
+1164:0747
+1165:0630
+1166:0154
+1167:0727
+1170:1116
+1171:1116
+1172:0224
+1173:1123
+1174:0060
+1175:0714
+1176:0330
+1177:0330
+1200:0030
+1201:1030
+1202:0530
+1203:0030
+1204:1130
+1205:1653
+1206:1131
+1207:1742
+1210:0456
+1211:0576
+1212:1033
+1213:1322
+1214:1656
+1215:0426
+1216:1656
+1217:1576
+1220:1043
+1221:1356
+1222:1742
+1223:1421
+1224:0220
+1225:1322
+1226:1576
+1227:1127
+1230:1622
+1231:1476
+1232:0060
+1233:0220
+1234:1316
+1235:1056
+1236:1203
+1237:1616
+1240:0576
+1241:1177
+1242:1656
+1243:0426
+1244:1656
+1245:0667
+1246:0314
+1247:0712
+1250:0536
+1251:1257
+1252:0276
+1253:1446
+1254:1356
+1255:1454
+1256:1427
+1257:0146
+1260:1333
+1261:0124
+1262:0003
+1263:0222
+1264:1546
+1265:0772
+1266:1062
+1267:1646
+1270:0220
+1271:1044
+1272:0630
+1273:1130
+1274:0330
+1275:0130
+1276:0430
+1277:0730
+1300:0130
+1301:1633
+1302:1746
+1303:0623
+1304:1616
+1305:0542
+1306:1423
+1307:1316
+1310:0074
+1311:1554
+1312:1427
+1313:0752
+1314:1376
+1315:1414
+1316:0056
+1317:1142
+1320:1533
+1321:0416
+1322:0552
+1323:1156
+1324:1477
+1325:0316
+1326:0452
+1327:1616
+1330:1176
+1331:1437
+1332:1646
+1333:0616
+1334:0056
+1335:1414
+1336:0753
+1337:1114
+1340:0330
+1341:0130
+1342:0030
+1343:0130
+1344:0730
+1345:1130
+1346:1030
+1347:0030
+1350:0530
+1351:0530
+1352:0330
+1353:1567
+1354:1656
+1355:0456
+1356:0606
+1357:1272
+1360:0573
+1361:0772
+1362:1316
+1363:0752
+1364:1713
+1365:0637
+1366:0316
+1367:1414
+1370:0230
+1371:0330
+1372:0030
+1373:0230
+1374:0530
+1375:1007
+1376:0514
+1377:0773
View
769 HP35/FSharp/ROMs/35v4.asm
@@ -0,0 +1,769 @@
+ jsb @067
+ go to @277
+ 0 -> s8
+ go to @005
+ 1 -> s5
+ 1 -> s9
+ 1 -> s2
+ select rom 2
+ jsb @264
+ go to @376
+ go to @027
+ go to @060
+ stack -> a
+ go to @331
+ 0 -> a[w]
+ a + 1 -> a[p]
+ 0 -> b[w]
+ select rom 1
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ go to @032
+ jsb @232
+ c exchange m
+ m -> c
+ go to @077
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ return
+ 3 -> p
+ 0 - c -> c[x]
+ stack -> a
+ go to @020
+ go to @164
+ 3 -> p
+ return
+ no operation
+ go to @040
+ 1 -> s5
+ 1 -> s1
+ go to @056
+ 1 -> s9
+ go to @047
+ 1 -> s10
+ go to @302
+ 0 -> b[w]
+ select rom 1
+ down rotate
+ go to @333
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ a + 1 -> a[x]
+ go to @022
+ go to @231
+ clear registers
+ jsb @134
+ go to @335
+ go to @362
+ shift right a[w]
+ 1 -> s3
+ go to @166
+ c -> stack
+ clear status
+ shift right a[w]
+ jsb @335
+ a -> b[w]
+ 0 -> a[xs]
+ shift left a[ms]
+ a - 1 -> a[x]
+ go to @340
+ if c[xs] = 0
+ go to @346
+ a exchange b[ms]
+ 13 -> p
+ go to @346
+ p - 1 -> p
+ c + 1 -> c[x]
+ if b[p] = 0
+ go to @114
+ 1 -> s11
+ shift right a[ms]
+ a exchange c[m]
+ if s4 = 0
+ go to @207
+ jsb @137
+ go to @335
+ 0 -> c[wp]
+ c - 1 -> c[wp]
+ 0 -> c[xs]
+ a + b -> a[x]
+ go to @135
+ 0 -> c[w]
+ clear status
+ c -> a[w]
+ 12 -> p
+ a -> b[x]
+ c -> a[x]
+ if c[xs] = 0