Post by bluatigro on Dec 10, 2018 7:53:46 GMT
in +- 1870 chales babbige draw the plans
for a turing complete mecanical compter
this is a try to sim this computer in JB
even more andvansd : whit plotter
card info :
www.fourmilab.ch/babbage/cards.html
please look if i got it good and report inprovement's
for a turing complete mecanical compter
this is a try to sim this computer in JB
'' bluatigro 10 dec 2018
'' anilytical engine sim
'' whitout graphics
'' see for more info :
'' https://www.fourmilab.ch/babbage/cards.html
'' https://cs.stanford.edu/people/eroberts/courses/soco/projects/babbage/FormattedWell.html
dim store( 999 ) , card$( 1000 )
global tel , operator$
'' card's posible :
'' N000 number
'' +
'' -
'' * or x
'' /
'' L000
'' S000
'' S000'
'' Z000
'' Z000'
'' <00
'' >00
'' P
'' B
'' H
'' CF?00
'' CF+00
'' CB?00
'' CB+00
while q$ <> "H"
read q$
chard$( i ) = q$
i = i + 1
wend
data "H"
'''run
i = 0
while card$( i ) <> "H"
select case left$( card$( i ) , 1 )
case "N"
q$ = word$( card$( i ) , 1 )
no = val( right$( q$ , len( q$ ) - 1 )
store( no ) = val( word$( card$( i ) , 2 ) )
case "+"
'' Add .
'' The values in the two Ingress Axes are added
'' (ignoring the contents of the Primed Ingress Axis) ,
'' and the sum is placed on the Egress Axis .
'' If the result of the addition differs
'' in sign from that of the first argument ,
'' or a carry-out occurs during the addition
'' (resulting from an overflow of the 50 digit
'' capacity of the Mill) , the run-up lever is set .
operator$ = "+"
case "-"
'' Subtract .
'' The value in the second Ingress Axis is subtracted
'' from that in the first (ignoring the contents
'' of the Primed Ingress Axis)
'' and the difference is placed on the Egress Axis.
'' If the result of the subtraction differs in
'' sign from that of the first argument,
'' or a borrow-in occurs
'' (resulting from an overflow of the 50
'' digit capacity of the Mill), the run-up lever is set.
operator$ = "-"
case "*" , "x"
'' Multiply .
'' The values in the two Ingress Axes are multiplied
'' (ignoring the contents of the Primed Ingress Axis) ,
'' and the least significant 50 digits of the product
'' are placed on the Egress Axis ,
'' with the most significant 50 digits appearing
'' on the Primed Egress Axis .
'' The run-up lever is never set due to a multiplication .
operator$ = "*"
case "/"
'' Divide .
'' The value in the first Ingress Axis
'' (least significant 50 digits)
'' and the Primed Ingress Axis
'' (most significant 50 digits)
'' is divided by the value in the second Ingress Axis .
'' The quotient is placed on the Primed Egress Axis
'' and the remainder on the Egress Axis.
'' If the quotient is larger than 50 digits or
'' the divisor is zero , the run-up lever is set .
operator$ = "/"
case "L"
'' Transfer from Store to Mill Ingress Axis ,
'' leaving Store column intact
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
if tel then
i.a2 = store( no )
select case operator$
case "+"
e.a = i.a1 + i.a2
if sign( e.a ) <> sign( i.a1 ) _
or len( str$( e.a ) ) > 50 then
runuplever = 1
end if
case "-"
e.a = i.a1 - i.a2
if sign( e.a ) <> sign( i.a1 ) _
or e.a < 0 then
runuplever = 1
end if
case "*"
q = i.a1 * i.a2
e.a = q mod 1e50
p.e.a = int( q / 1e50 )
case "/"
if i.a2 = 0 then
runuplever = 1
else
q = i.a1 + p.i.a * 1e50
p.e.a = int( q / i.a2 )
e.a = q mod i.a2
end if
case else
end select
else
i.a1 = store( no )
end if
tel = 1 - tel
case "Z"
'' Transfer from Store to Mill Ingress Axis ,
'' zeroing Store column .
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
if right$( q$ , 1 ) = "'" then
p.e.a = store( no )
else
i.a = store( no )
end if
store( no ) = 0
case "S"
'' Transfer from Mill Egress Axis to Store column .
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
if right$( q$ , 1 ) = "'" then
store( no ) = p.e.a
else
store( no ) = i.a
end if
case "<"
'' Step up (shift left)
'' by n digits the 100 digit value
'' formed by the most significant 50 digits in the
'' Primed Ingress Axis and
'' the least significant digits in the
'' first Ingress Axis.
'' Digits stepped off the 100th place are lost ,
'' and zeroes fill digits vacated by the stepping .
'' The stepped result remains on the
'' Primed Ingress and first Ingress Axes .
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
q$ = str$( p.i.a )
q$ = q$ + left$( "0000000000" _
+ "0000000000" _
+ "0000000000" _
+ "0000000000" _
+ "0000000000" , no )
p.i.a = val( q$ )
i.a1 = val( q$ )
case ">"
'' Step down (shift right)
'' by n digits the 100 digit value
'' formed by the most significant 50 digits
'' in the Primed Egress Axis and
'' the least significant digits in
'' the Egress Axis .
'' Digits stepped off are lost ,
'' and zeroes fill digits vacated by the stepping .
'' The stepped result remains on the
'' Primed Egress and Egress Axes .
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
q$ = str$( p.e.a )
q$ = left$( q$ , len( q$ ) - no )
p.e.a = val( q$ )
e.a = val( q$ )
case "C"
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 3 )
if left$( q$ , 2 ) = "CF" then
if left$( q$ , 3 ) = "CF?" then
if runuplever then
i = i + no
end if
end if
if left$( q$ , 3 ) = "CF+"
i = i + no
end if
end if
if left$( q$ , 2 ) = "CB" then
if left$( q$ , 3 ) = "CB?" then
if runuplever then
i = i - no
end if
end if
if left$( q$ , 3 ) = "CB+"
i = i - no
end if
end if
case "B"
beep
case "P"
print p.e.a
case else
'' any other card is remark
end select
wend
end
function sign( x )
uit = 0
if x < 0 then uit = -1
if x > 0 then uit = 1
sign = uit
end function
''================================================
'' example program 1
'' ( 4000 * 2.5 ) / 28
''data "N000 4000000000"
''data "N001 0002500000"
''data "N002 0028000000"
''data "*"
''data "L000"
''data "L001"
''data ">06"
''data "S003"
''data "/"
''data "L003"
''data "<06"
''data "L002"
''data "S004"
''data "P"
''data "H"
''===========================================================================
'' example program 2
'' 4!
''N000 4
''N001 1
''N002 1
''*
''L001
''L000
''S001
''-
''L000
''L002
''S000
''L002
''L000
''CB?11
''B
''P
''H
even more andvansd : whit plotter
'' bluatigro 10 dec 2018
'' anilytical engine sim
'' whit graphics and GUI
'' see for more info :
'' https://www.fourmilab.ch/babbage/cards.html
'' card's posible :
'' Nxxx number
'' +
'' -
'' *
'' /
'' Lxxx
'' Sxxx
'' Zxxx
'' <xx
'' >xx
'' P
'' B
'' H
'' CF?xx
'' CF+xx
'' CB?xx
'' CB+xx
'' DX
'' DY
'' D+
'' D-
dim store( 999 ) , card$( 10000 )
WindowWidth = 430
WindowHeight = 430
global winx , winy
winx = 430
winy = 430
menu "file" _
, "load" , [load] _
, "run" , [run] _
,|,"exit" , [quit]
open "anelytical engine sim" for graphics as #m
#m "trapclose [quit]"
wait
[load]
filedialog "load program" , "*.txt" , file$
if file$ = "" then
notice chr$( 13 ) _
+ "LOAD ERROR !!" + chr$( 13 ) + chr$( 13 ) _
+ "NO FILE CHOISEN !!"
else
open file$ for input as #in
i = 0
while q$ <> "H" and i < 10000
line input #in , q$
card$( i ) = q$
i = i + 1
wend
close #in
end if
wait
[run]
i = 0
x = 0
y = 0
while card$( i ) <> "H" and i < 10000
scan
select case left$( card$( i ) , 1 )
case "N"
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
store( no ) = val( word$( q$ , 2 ) )
case "+"
'' Add .
'' The values in the two Ingress Axes are added
'' (ignoring the contents of the Primed Ingress Axis) ,
'' and the sum is placed on the Egress Axis .
'' If the result of the addition differs
'' in sign from that of the first argument ,
'' or a carry-out occurs during the addition
'' (resulting from an overflow of the 50 digit
'' capacity of the Mill) , the run-up lever is set .
egress.axis = ingress.axis1 + ingress.axis2
if sign( egress.axis ) <> sign( ingress.axis1 ) _
or egress.axis > 1e50 then
runuplever = 1
end if
case "-"
'' Subtract .
'' The value in the second Ingress Axis is subtracted
'' from that in the first (ignoring the contents
'' of the Primed Ingress Axis)
'' and the difference is placed on the Egress Axis.
'' If the result of the subtraction differs in
'' sign from that of the first argument,
'' or a borrow-in occurs
'' (resulting from an overflow of the 50
'' digit capacity of the Mill), the run-up lever is set.
egress.axis = ingress.axis1 - ingress.axis2
if sign( egress.axis ) <> sign( ingress.axis1 ) _
or egress.axis < 0 then
runuplever = 1
end if
case "*"
'' Multiply .
'' The values in the two Ingress Axes are multiplied
'' (ignoring the contents of the Primed Ingress Axis) ,
'' and the least significant 50 digits of the product
'' are placed on the Egress Axis ,
'' with the most significant 50 digits appearing
'' on the Primed Egress Axis .
'' The run-up lever is never set due to a multiplication .
q = ingress.axis1 * ingress.axis2
egress.axis = q mod 1e50
primed.egress.axis = int( q / 1e50 )
case "/"
'' Divide .
'' The value in the first Ingress Axis
'' (least significant 50 digits)
'' and the Primed Ingress Axis
'' (most significant 50 digits)
'' is divided by the value in the second Ingress Axis .
'' The quotient is placed on the Primed Egress Axis
'' and the remainder on the Egress Axis.
'' If the quotient is larger than 50 digits or
'' the divisor is zero , the run-up lever is set .
if ingress.axis2 = 0 then
runuplever = 1
else
q = ingress.axis1 + primed.ingress.axis * 1e50
primed.egress.axis = q / ingress.axis2
egress.axis = q mod ingress.axis2
end if
case "L"
'' Transfer from Store to Mill Ingress Axis ,
'' leaving Store column intact
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
if right$( q$ , 1 ) = "*" then
primed.egress.axis = store( no )
else
mill.ingeress.axis = store( no )
end if
case "Z"
'' Transfer from Store to Mill Ingress Axis ,
'' zeroing Store column .
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
if right$( q$ , 1 ) = "*" then
primed.egress.axis = store( no )
else
mill.ingeress.axis = store( no )
end if
store( no ) = 0
case "S"
'' Transfer from Mill Egress Axis to Store column .
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
if right$( q$ , 1 ) = "*" then
store( no ) = primed.egress.axis
else
store( no ) = mill.ingeress.axis
end if
case "<"
'' Step up (shift left)
'' by n digits the 100 digit value
'' formed by the most significant 50 digits in the
'' Primed Ingress Axis and
'' the least significant digits in the
'' first Ingress Axis.
'' Digits stepped off the 100th place are lost ,
'' and zeroes fill digits vacated by the stepping .
'' The stepped result remains on the
'' Primed Ingress and first Ingress Axes .
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
q$ = str$( primed.ingress.axis )
q$ = q$ + left$( "0000000000" _
+ "0000000000" _
+ "0000000000" _
+ "0000000000" _
+ "0000000000" , no )
primed.ingress.axis = val( q$ )
ingress.axis1 = val( q$ )
case ">"
'' Step down (shift right)
'' by n digits the 100 digit value
'' formed by the most significant 50 digits
'' in the Primed Egress Axis and
'' the least significant digits in
'' the Egress Axis .
'' Digits stepped off are lost ,
'' and zeroes fill digits vacated by the stepping .
'' The stepped result remains on the
'' Primed Egress and Egress Axes .
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 1 )
q$ = str$( primed.ingress.axis )
q$ = left$( q$ , len( q$ ) - no )
primed.ingress.axis = val( q$ )
case "C"
q$ = card$( i )
no = val( right$( q$ , len( q$ ) - 3 )
if left$( q$ , 2 ) = "CF" then
if left$( q$ , 3 ) = "CF?" then
if runuplever then
i = i + no
end if
end if
if left$( q$ , 3 ) = "CF+"
i = i + no
end if
end if
if left$( q$ , 2 ) = "CB" then
if left$( q$ , 3 ) = "CB?" then
if runuplever then
i = i - no
end if
end if
if left$( q$ , 3 ) = "CB+"
i = i - no
end if
end if
case "B"
beep
case "P"
print primed.egress.axis
case "D"
select case left$( card$( i ) , 2 )
case "DX"
x = primed.egress.axis
#m "set " ; winx / 2 + x _
; " " ; winy / 2 - y
case "DY"
y = primed.egress.axis
#m "set " ; winx / 2 + x _
; " " ; winy / 2 - y
case "D+"
#m "down"
case "D-"
#m "up"
case else
end select
case else
'' al other cards are REM
end select
i = i + 1
wend
wait
[quit]
close #m
end
function sign( x )
uit = 0
if x < 0 then uit = -1
if x > 0 then uit = 1
sign = uit
end function
card info :
www.fourmilab.ch/babbage/cards.html
please look if i got it good and report inprovement's