mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-08-07 18:25:03 +00:00
FP WIP
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import conio
|
import conio
|
||||||
|
const NORMAL = $FF
|
||||||
|
const INVERSE = $3F
|
||||||
|
const FLASH = $7F
|
||||||
struc t_conio
|
struc t_conio
|
||||||
word keypressed
|
word keypressed
|
||||||
word home
|
word home
|
||||||
|
@@ -202,6 +202,7 @@ def a2viewport(left, top, width, height)
|
|||||||
return a2gotoxy(0, 0)
|
return a2gotoxy(0, 0)
|
||||||
end
|
end
|
||||||
def a2texttype(type)
|
def a2texttype(type)
|
||||||
|
^$32 = type
|
||||||
end
|
end
|
||||||
def a2textmode(columns)
|
def a2textmode(columns)
|
||||||
call($FB39, 0, 0, 0, 0) // textmode()
|
call($FB39, 0, 0, 0, 0) // textmode()
|
||||||
|
@@ -172,16 +172,16 @@ export def ext2str(ext, str, intdigits, fracdigits, format)
|
|||||||
decrec:exp++
|
decrec:exp++
|
||||||
loop
|
loop
|
||||||
fin
|
fin
|
||||||
if sigdigits - decrec:exp > numdigits or decrec:exp > 0 or format & $04
|
if -decrec:exp > numdigits or decrec:exp > 0 or format & $04
|
||||||
//
|
//
|
||||||
// Convert to exponential format
|
// Convert to exponential format
|
||||||
//
|
//
|
||||||
^(str+2) = decrec.sig.1
|
^(str+2) = decrec.sig.1
|
||||||
^(str+3) = '.'
|
^(str+3) = '.'
|
||||||
i = 3
|
i = 3
|
||||||
for d = 2 to decrec.sig
|
for d = 0 to fracdigits
|
||||||
i++
|
i++
|
||||||
^(str+i) = decrec.sig[d]
|
^(str+i) = decrec.sig.2[d]
|
||||||
next
|
next
|
||||||
//
|
//
|
||||||
// Copy over all significant digits
|
// Copy over all significant digits
|
||||||
|
@@ -21,10 +21,10 @@ struc t_keyinput
|
|||||||
byte keyinfo[t_keypad]
|
byte keyinfo[t_keypad]
|
||||||
word phandler
|
word phandler
|
||||||
end
|
end
|
||||||
predef delKey#0, clearKey#0, dropKey#0
|
predef delKey#0, cmdKey#0, dropKey#0
|
||||||
predef digitKey#0, zeroKey#0, pointKey#0, opKey#0
|
predef digitKey#0, zeroKey#0, pointKey#0, opKey#0
|
||||||
predef enterKey#0, chsKey#0, memKey#0
|
predef enterKey#0, chsKey#0, memKey#0
|
||||||
predef sqrtKey#0, piKey#0
|
predef sqrtKey#0, absKey#0
|
||||||
//
|
//
|
||||||
// Current input
|
// Current input
|
||||||
//
|
//
|
||||||
@@ -39,7 +39,7 @@ byte memory[10*t_extended]
|
|||||||
byte[t_keypad] keypad = $08, 0, 0, ""
|
byte[t_keypad] keypad = $08, 0, 0, ""
|
||||||
word = @delKey
|
word = @delKey
|
||||||
byte[t_keypad] = $1B, 0, 0, ""
|
byte[t_keypad] = $1B, 0, 0, ""
|
||||||
word = @clearKey
|
word = @cmdKey
|
||||||
byte[t_keypad] = '=', 0, 0, ""
|
byte[t_keypad] = '=', 0, 0, ""
|
||||||
word = @dropKey
|
word = @dropKey
|
||||||
byte[t_keypad] = '7', 3, 10, "[7]"
|
byte[t_keypad] = '7', 3, 10, "[7]"
|
||||||
@@ -70,8 +70,8 @@ byte[t_keypad] = '0', 3, 16, "[0]"
|
|||||||
word = @zeroKey
|
word = @zeroKey
|
||||||
byte[t_keypad] = '.', 7, 16, "[.]"
|
byte[t_keypad] = '.', 7, 16, "[.]"
|
||||||
word = @pointKey
|
word = @pointKey
|
||||||
byte[t_keypad] = '?', 11, 16, "[?]"
|
byte[t_keypad] = '@', 11, 16, "[@]"
|
||||||
word = @chsKey
|
word = @opKey
|
||||||
byte[t_keypad] = '+', 15, 16, "[+]"
|
byte[t_keypad] = '+', 15, 16, "[+]"
|
||||||
word = @opKey
|
word = @opKey
|
||||||
byte[t_keypad] = $0D, 3, 18, "[ENTER]"
|
byte[t_keypad] = $0D, 3, 18, "[ENTER]"
|
||||||
@@ -80,10 +80,10 @@ byte[t_keypad] = '<', 11, 18, "[<]"
|
|||||||
word = @memKey
|
word = @memKey
|
||||||
byte[t_keypad] = '>', 15, 18, "[>]"
|
byte[t_keypad] = '>', 15, 18, "[>]"
|
||||||
word = @memKey
|
word = @memKey
|
||||||
byte[t_keypad] = 'Q', 3, 20, "[S(Q)R]"
|
byte[t_keypad] = 'A', 3, 20, "[(A)BS]"
|
||||||
word = @sqrtKey
|
word = @opKey
|
||||||
byte[t_keypad] = 'P', 11, 20, "[ (P)I]"
|
byte[t_keypad] = 'N', 11, 20, "[(N)EG]"
|
||||||
word = @piKey
|
word = @chsKey
|
||||||
byte = 0
|
byte = 0
|
||||||
//
|
//
|
||||||
// Display format state
|
// Display format state
|
||||||
@@ -192,8 +192,6 @@ def initDisplay#0
|
|||||||
puts(pkeys + keystr)
|
puts(pkeys + keystr)
|
||||||
pkeys = pkeys + t_keyinput
|
pkeys = pkeys + t_keyinput
|
||||||
loop
|
loop
|
||||||
initInput
|
|
||||||
showInput
|
|
||||||
end
|
end
|
||||||
def initState#0
|
def initState#0
|
||||||
byte m
|
byte m
|
||||||
@@ -205,19 +203,20 @@ def initState#0
|
|||||||
//
|
//
|
||||||
// Fill memory
|
// Fill memory
|
||||||
//
|
//
|
||||||
for m = 0 to 9
|
for m = 2 to 9
|
||||||
fpu:storExt(@memory[m*t_extended], X_REG)
|
fpu:storExt(@memory[m*t_extended], X_REG)
|
||||||
next
|
next
|
||||||
showStack
|
//
|
||||||
showMem
|
// Put some useful constants in there
|
||||||
|
//
|
||||||
|
fpu:constPi()
|
||||||
|
fpu:pullExt(@memory[0*t_extended])
|
||||||
|
fpu:constE()
|
||||||
|
fpu:pullExt(@memory[1*t_extended])
|
||||||
end
|
end
|
||||||
//
|
//
|
||||||
// Keypress input handlers
|
// Keypress input handlers
|
||||||
//
|
//
|
||||||
def clearKey(pkey)#0
|
|
||||||
initInput
|
|
||||||
showInput
|
|
||||||
end
|
|
||||||
def delKey(pkey)#0
|
def delKey(pkey)#0
|
||||||
if inputStr
|
if inputStr
|
||||||
inputStr--
|
inputStr--
|
||||||
@@ -283,6 +282,12 @@ def opKey(pkey)#0
|
|||||||
is '/'
|
is '/'
|
||||||
fpu:div()
|
fpu:div()
|
||||||
break
|
break
|
||||||
|
is '@'
|
||||||
|
fpu:sqrt()
|
||||||
|
break
|
||||||
|
is 'A'
|
||||||
|
fpu:abs()
|
||||||
|
break
|
||||||
wend
|
wend
|
||||||
showStack
|
showStack
|
||||||
end
|
end
|
||||||
@@ -315,15 +320,24 @@ def memKey(pkey)#0
|
|||||||
fin
|
fin
|
||||||
fin
|
fin
|
||||||
end
|
end
|
||||||
def sqrtKey(pkey)#0
|
//
|
||||||
updateInput
|
// Command line handler
|
||||||
fpu:sqrt()
|
//
|
||||||
showStack
|
def cmdKey(pkey)#0
|
||||||
end
|
word cmdLine
|
||||||
def piKey(pkey)#0
|
|
||||||
fpu:constPi()
|
showStatus("Command")
|
||||||
|
cmdLine = gets(':'|$80)
|
||||||
|
clearStatus
|
||||||
|
//
|
||||||
|
// Do something
|
||||||
|
//
|
||||||
|
initDisplay
|
||||||
showStack
|
showStack
|
||||||
|
showMem
|
||||||
|
showInput
|
||||||
end
|
end
|
||||||
|
|
||||||
//
|
//
|
||||||
// Keypress handler
|
// Keypress handler
|
||||||
//
|
//
|
||||||
@@ -337,7 +351,13 @@ def inputKey
|
|||||||
inkey = toupper(getc)
|
inkey = toupper(getc)
|
||||||
while ^pkeys
|
while ^pkeys
|
||||||
if inkey == ^pkeys
|
if inkey == ^pkeys
|
||||||
|
conio:texttype(INVERSE)
|
||||||
|
conio:gotoxy(pkeys->xpos, pkeys->ypos)
|
||||||
|
puts(pkeys + keystr)
|
||||||
|
conio:texttype(NORMAL)
|
||||||
pkeys=>phandler(pkeys)#0
|
pkeys=>phandler(pkeys)#0
|
||||||
|
conio:gotoxy(pkeys->xpos, pkeys->ypos)
|
||||||
|
puts(pkeys + keystr)
|
||||||
break
|
break
|
||||||
fin
|
fin
|
||||||
pkeys = pkeys + t_keyinput
|
pkeys = pkeys + t_keyinput
|
||||||
@@ -346,6 +366,10 @@ def inputKey
|
|||||||
end
|
end
|
||||||
initDisplay
|
initDisplay
|
||||||
initState
|
initState
|
||||||
|
initInput
|
||||||
|
showStack
|
||||||
|
showMem
|
||||||
|
showInput
|
||||||
inputKey
|
inputKey
|
||||||
conio:gotoxy(0, 22)
|
conio:gotoxy(0, 22)
|
||||||
done
|
done
|
||||||
|
@@ -178,16 +178,17 @@ def ext2str(ext, str, intdigits, fracdigits, format)
|
|||||||
//puts("sigdigits: "); puti(sigdigits); putln
|
//puts("sigdigits: "); puti(sigdigits); putln
|
||||||
//putc(decrec.sgn ?? '-' :: '+'); puts(@decrec.sig); putc('e'); puti(decrec:exp); putln
|
//putc(decrec.sgn ?? '-' :: '+'); puts(@decrec.sig); putc('e'); puti(decrec:exp); putln
|
||||||
//sane:zpSave()
|
//sane:zpSave()
|
||||||
if sigdigits - decrec:exp > numdigits or decrec:exp > 0 or format & $04
|
//if sigdigits - decrec:exp > numdigits or decrec:exp > 0 or format & $04
|
||||||
|
if -decrec:exp > numdigits or decrec:exp > 0 or format & $04
|
||||||
//
|
//
|
||||||
// Convert to exponential format
|
// Convert to exponential format
|
||||||
//
|
//
|
||||||
^(str+2) = decrec.sig.1
|
^(str+2) = decrec.sig.1
|
||||||
^(str+3) = '.'
|
^(str+3) = '.'
|
||||||
i = 3
|
i = 3
|
||||||
for d = 2 to decrec.sig
|
for d = 0 to fracdigits//decrec.sig
|
||||||
i++
|
i++
|
||||||
^(str+i) = decrec.sig[d]
|
^(str+i) = decrec.sig.2[d]
|
||||||
next
|
next
|
||||||
//
|
//
|
||||||
// Copy over all significant digits
|
// Copy over all significant digits
|
||||||
@@ -261,7 +262,7 @@ def divstri(strNum, denom, format)#0
|
|||||||
sane:zpSave()
|
sane:zpSave()
|
||||||
str2ext(strNum, @xResult)
|
str2ext(strNum, @xResult)
|
||||||
sane:fpOp2(FFINT|FODIV, @xResult, @denom) // Div int denom into ext Result
|
sane:fpOp2(FFINT|FODIV, @xResult, @denom) // Div int denom into ext Result
|
||||||
ext2str(@xResult, @strResult, format & $05 ?? 1 :: 6, 4, format)
|
ext2str(@xResult, @strResult, 6, 4, format)//format & $05 ?? 1 :: 6, 4, format)
|
||||||
sane:zpRestore()
|
sane:zpRestore()
|
||||||
puts(strNum); putc('/'); puti(denom); putc('='); puts(@strResult); putln
|
puts(strNum); putc('/'); puti(denom); putc('='); puts(@strResult); putln
|
||||||
end
|
end
|
||||||
@@ -334,4 +335,5 @@ divstri("800000", 2, 4)
|
|||||||
divstri("1e+2", 2, 2)
|
divstri("1e+2", 2, 2)
|
||||||
divstri("-1e-2", 2, 2)
|
divstri("-1e-2", 2, 2)
|
||||||
divstri("0", 1, 2)
|
divstri("0", 1, 2)
|
||||||
|
divstri("1000", 1, 1)
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user