1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-04-04 11:32:41 +00:00

RPN calculator and support

This commit is contained in:
Dave Schmenk 2017-11-21 12:39:07 -08:00
parent 3dc4dfec16
commit 22892c5f42
6 changed files with 128 additions and 46 deletions

14
src/inc/conio.plh Normal file
View File

@ -0,0 +1,14 @@
import conio
struc t_conio
word keypressed
word home
word gotoxy
word viewport
word texttype
word textmode
word grmode
word grcolor
word grplot
end
word conio
end

View File

@ -51,4 +51,5 @@ struc t_fpu
word round
word sqrt
end
word fpu
end

View File

@ -24,16 +24,22 @@ const hgr1 = $2000
const hgr2 = $4000
const page1 = 0
const page2 = 1
struc t_conio
word keypressed
word home
word gotoxy
word viewport
word texttype
word textmode
word grmode
word grcolor
word grplot
end
//
// Predefined functions.
//
predef a2reset,a2keypressed,a2home,a2gotoxy,a2viewport,a2texttype
predef a2textmode,a2writeint,a2writeln
predef a2grmode,grcolor,grplot
//
// String pool.
//
byte stdlib[] = "STDLIB"
predef a2keypressed,a2home,a2gotoxy,a2viewport,a2texttype
predef a2textmode,a2grmode,a2grcolor,a2grplot
//
// Screen row address arrays.
//
@ -63,7 +69,6 @@ export word conio[]
//
// Function pointers.
//
word = @a2reset
word = @a2keypressed
word = @a2home
word = @a2gotoxy
@ -71,8 +76,8 @@ word = @a2viewport
word = @a2texttype
word = @a2textmode
word = @a2grmode
word = @grcolor
word = @grplot
word = @a2grcolor
word = @a2grplot
//
// Native routines.
//
@ -82,7 +87,7 @@ end
//
// def grscrn(rowaddrs)
//
asm grscrn
asm a2grscrn
GRSCRN = $26
GRSCRNL = GRSCRN
GRSCRNH = GRSCRNL+1
@ -95,7 +100,7 @@ end
//
// def grcolor(color)
//
asm grcolor
asm a2grcolor
GRCLR = $30
LDA #$0F
AND ESTKL,X
@ -111,7 +116,7 @@ end
//
// def grplot(x, y)
//
asm grplot
asm a2grplot
STY IPY
LDA ESTKL,X
AND #$FE
@ -142,13 +147,19 @@ end
def a1keypressed
return ^$D011 >= 128
end
def a1home
byte l
for l = 0 to 23
putln
next
end
def a1gotoxy(x, y)
curshpos = x
cursvpos = y
putln
while x
putc(' ')
x = x - 1
x = x - 1
loop
end
def a1viewport(left, top, width, height)
@ -168,7 +179,7 @@ def a2keypressed
end
def a2home
curshpos = 0
cursypos = 0
cursvpos = 0
return call($FC58, 0, 0, 0, 0) // home()
end
def a2gotoxy(x, y)
@ -180,9 +191,9 @@ end
def a2viewport(left, top, width, height)
if !width or !height
left = 0
top = 0
width = 40
height = 24
top = 0
width = 40
height = 24
fin
^$20 = left
^$21 = width
@ -191,9 +202,6 @@ def a2viewport(left, top, width, height)
return a2gotoxy(0, 0)
end
def a2texttype(type)
end
def a2writeln(string, start, fill)
end
def a2textmode(columns)
call($FB39, 0, 0, 0, 0) // textmode()
@ -206,7 +214,7 @@ def a2grmode(mix)
^showfull
fin
a2home
return grscrn(@txt1scrn) // point to lo-res screen
return a2grscrn(@txt1scrn) // point to lo-res screen
end
//
// Apple III routines.
@ -237,7 +245,7 @@ end
def a3home
curshpos = 0
cursvpos = 0
return cout(28)
return putc(28)
end
def a3gotoxy(x, y)
curshpos = x
@ -250,12 +258,12 @@ end
def a3viewport(left, top, width, height)
if !width or !height
//
// Reset the full-screen viewport
//
// Reset the full-screen viewport
//
left = 0
top = 0
width = textwidth
height = 24
top = 0
width = textcols
height = 24
fin
putc(1) // Reset viewport
putc(26)
@ -293,30 +301,31 @@ def a3grmode(mix)
memset(txt1scrn[i], 40, $0000) // text screen
memset(txt2scrn[i], 40, $0000) // color screen
next
return grscrn(@txt2scrn) // point to color screen
return a2grscrn(@txt2scrn) // point to color screen
end
//
// Machine specific initialization.
//
when MACHID & $C8
when ^MACHID & $C8
is $08 // Apple 1
conio:reset = @a1reset
conio:keypressed = @a1keypressed
conio:home = @a1home
conio:gotoxy = @a1gotoxy
conio:viewport = @a1viewport
conio:texttype = @a1texttype
conio:textmode = @a1textmode
conio:grmixmode = @a1grmixmode
conio:home = @a1home
conio:gotoxy = @a1gotoxy
conio:viewport = @a1viewport
conio:texttype = @a1texttype
conio:textmode = @a1textmode
conio:grmode = @a1grmode
break
is $C0 // Apple ///
conio:reset = @a3reset
conio:keypressed = @a3keypressed
conio:home = @a3home
conio:gotoxy = @a3gotoxy
conio:viewport = @a3viewport
conio:texttype = @a3texttype
conio:textmode = @a3textmode
conio:grmixmode = @a3grmixmode
devcons = modaddr(@stdlib).5 // devcons variable from STDLIB
conio:home = @a3home
conio:gotoxy = @a3gotoxy
conio:viewport = @a3viewport
conio:texttype = @a3texttype
conio:textmode = @a3textmode
conio:grmode = @a3grmode
devcons = modaddr("CMDSYS").5 // devcons variable from STDLIB
break
otherwise // Apple ][
wend
done

View File

@ -264,6 +264,7 @@ def reset
next
return sane:zpRestore()
end
done
//
// Test code
//

View File

@ -18,10 +18,12 @@ FATPUT = FATPUT\#FE1000
FATWDSK = FATWRITEDSK\#FE1000
FATRDSK = FATREADDSK\#FE1000
FILEIO = FILEIO\#FE1000
CONIO = CONIO\#FE1000
SANE = SANE\#FE1000
FPSTR = FPSTR\#FE1000
FPU = FPU\#FE1000
SANITY = SANITY\#FE1000
RPNCALC = RPNCALC\#FE1000
WIZNET = WIZNET\#FE1000
UTHERNET2= UTHERNET2\#FE1000
UTHERNET= UTHERNET\#FE1000
@ -66,7 +68,7 @@ TXTTYPE = .TXT
#SYSTYPE = \#FF2000
#TXTTYPE = \#040000
all: $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVM03) $(CMD) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(SB) $(MON) $(ROD) $(SIEVE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(ROGUEIO) $(HGR1) $(TONE) $(DGR) $(DGRTEST) $(FILEIO) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(SANE) $(FPSTR) $(FPU) $(SANITY)
all: $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVM03) $(CMD) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(SB) $(MON) $(ROD) $(SIEVE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(ROGUEIO) $(HGR1) $(TONE) $(DGR) $(DGRTEST) $(FILEIO) $(CONIO) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(SANE) $(FPSTR) $(FPU) $(SANITY) $(RPNCALC)
clean:
-rm *FE1000 *FF2000 $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVM03)
@ -179,6 +181,10 @@ $(FILEIO): libsrc/fileio.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMO < libsrc/fileio.pla > libsrc/fileio.a
acme --setpc 4094 -o $(FILEIO) libsrc/fileio.a
$(CONIO): libsrc/conio.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMO < libsrc/conio.pla > libsrc/conio.a
acme --setpc 4094 -o $(CONIO) libsrc/conio.a
$(SANE): libsrc/sane.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMO < libsrc/sane.pla > libsrc/sane.a
acme --setpc 4094 -o $(SANE) libsrc/sane.a
@ -195,6 +201,10 @@ $(SANITY): samplesrc/sanity.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMO < samplesrc/sanity.pla > samplesrc/sanity.a
acme --setpc 4094 -o $(SANITY) samplesrc/sanity.a
$(RPNCALC): samplesrc/rpncalc.pla libsrc/fpu.pla inc/fpu.plh libsrc/fpstr.pla inc/fpstr.plh libsrc/conio.pla inc/conio.plh $(PLVM02) $(PLASM)
./$(PLASM) -AMO < samplesrc/rpncalc.pla > samplesrc/rpncalc.a
acme --setpc 4094 -o $(RPNCALC) samplesrc/rpncalc.a
$(TONE): libsrc/tone.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMO < libsrc/tone.pla > libsrc/tone.a
acme --setpc 4094 -o $(TONE) libsrc/tone.a

47
src/samplesrc/rpncalc.pla Normal file
View File

@ -0,0 +1,47 @@
//
// Desktop RPN calculator
//
include "inc/cmdsys.plh"
include "inc/sane.plh"
include "inc/fpu.plh"
include "inc/conio.plh"
def repc(rep, c)#0
while rep
putc(c)
rep--
loop
end
def rect(x, y, width, height, frame, title)
byte i
conio:gotoxy(x + 1, y)
repc(width - 2, frame ?? '=' :: '-')
conio:gotoxy(x + 1, y + height - 1)
repc(width - 2, frame ?? '=' :: '-')
for i = 1 to height - 1
conio:gotoxy(x, y + i)
putc(frame ?? '#' :: '!')
conio:gotoxy(x + width - 1, y + i)
putc(frame ?? '#' :: '!')
next
conio:gotoxy(x, y)
putc(frame ?? '/' :: '+')
conio:gotoxy(x + width - 1, y)
putc(frame ?? '\\' :: '+')
conio:gotoxy(x, y + height - 1)
putc(frame ?? '\\' :: '+')
conio:gotoxy(x + width - 1, y + height - 1)
putc(frame ?? '/' :: '+')
if title
conio:gotoxy(x + (width - ^title) / 2, y)
puts(title)
fin
end
conio:home()
rect(0, 0, 40, 23, 1, "RPN Calculator")
rect(1, 1, 19, 6, 0, "Stack")
rect(1, 6, 19, 3, 0, 0)
rect(20, 1, 19, 12, 0, "Memory")
conio:gotoxy(0, 20)
done