1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-10 06:30:41 +00:00
This commit is contained in:
David Schmenk 2017-11-21 08:14:43 -08:00
parent 53307bf7d7
commit 3dc4dfec16
2 changed files with 85 additions and 40 deletions

View File

@ -1,42 +1,54 @@
import fpu
//
// RPN Register indeces
//
const X_REG = 0
const Y_REG = 1
const Z_REG = 2
const T_REG = 3
//
// FPU API
//
struc t_fpu
word reset
word pushDbl
word pushDbl
word pushDbl
word pushExt
word pushStr
word pullDbl
word pullDbl
word pullDbl
word pullExt
word pullStr
word loadDbl
word loadDbl
word loadDbl
word loadExt
word loadStr
word storDbl
word storDbl
word storDbl
word storExt
word storStr
word shiftUp
word shiftDown
word rotateUp
word rotateDown
word dup
word swap
word clear
word add
word sub
word mul
word div
word rem
word neg
word abs
word trunc
word round
word sqrt
word reset
word constPi
word constE
word pushDbl
word pushDbl
word pushDbl
word pushExt
word pushStr
word pullDbl
word pullDbl
word pullDbl
word pullExt
word pullStr
word loadDbl
word loadDbl
word loadDbl
word loadExt
word loadStr
word storDbl
word storDbl
word storDbl
word storExt
word storStr
word shiftUp
word shiftDown
word rotateUp
word rotateDown
word dup
word swap
word clear
word add
word sub
word mul
word div
word rem
word neg
word abs
word trunc
word round
word sqrt
end
end

View File

@ -7,14 +7,15 @@ include "inc/fpstr.plh"
//
// External interface to FPU library
//
predef reset, pushInt, pushSgl, pushDbl, pushExt, pushStr
predef reset, constPi, constE
predef pushInt, pushSgl, pushDbl, pushExt, pushStr
predef pullInt, pullSgl, pullDbl, pullExt, pullStr
predef loadInt, loadSgl, loadDbl, loadExt, loadStr
predef storInt, storSgl, storDbl, storExt, storStr
predef shiftUp, shiftDown, rotateUp, rotateDown, dup, swap, clear
predef add, sub, mul, div, rem
predef neg, abs, trunc, round, sqrt, square
export word fpu = @reset
export word fpu = @reset, @constPi, @constE
word = @pushInt, @pushSgl, @pushDbl, @pushExt, @pushStr
word = @pullInt, @pullSgl, @pullDbl, @pullExt, @pullStr
word = @loadInt, @loadSgl, @loadDbl, @loadExt, @loadStr
@ -23,6 +24,11 @@ word = @shiftUp, @shiftDown, @rotateUp, @rotateDown, @dup, @swap, @clear
word = @add, @sub, @mul, @div, @rem
word = @neg, @abs, @trunc, @round, @sqrt, @square
//
// Useful constants
//
byte ext_pi[t_extended] = $35,$C2,$68,$21,$A2,$DA,$0F,$C9,$00,$40
byte ext_e[t_extended] = $9B,$4A,$BB,$A2,$5B,$54,$F8,$AD,$00,$40
//
// FP Stack
//
byte stack[t_extended*4]
@ -234,6 +240,15 @@ def square
sane:zpRestore()
end
//
// Push useful constants
//
def constPi
return pushExt(@ext_pi)
end
def constE
return pushExt(@ext_e)
end
//
// Reset FPU and SANE
//
def reset
@ -261,6 +276,16 @@ def dumpStack#0
puts(" "); puti(r); putc(':'); puts(@regStr); putln
next
end
def dumpExt#0
byte i
for i = 0 to t_extended-1
putc('$')
call($FDDA, stackRegs.[0, i], 0, 0, 0)
putc(' ')
next
putln
end
//
// Run through some test cases
//
@ -281,4 +306,12 @@ dumpStack
puts("Sqrt\n")
sqrt
dumpStack
pushStr("2.71828182845904523536028747")
dumpExt
constE
dumpExt
pushStr("3.14159265358979323846264338")
dumpExt
constPi
dumpExt
done