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