This program is being released as FREEWARE. You do not have to pay me
for it. It requires cbasPad 0.68. Because some of the functions it 
uses are not guaranteed by the author of cbasPad to remain in future 
releases, I cannot promise that this will work on later versions of 
cbasPad.

I wrote this program in an attempt to replace my HP 48SX calculator 
which I still use for graphing functions. It has the functionality I 
need - I may update it further, especially if there are features that 
people request. The program will graph one or more functions within a 
user-defined range. The functions can be anything that returns a value 
- using if statements the user can make block functions if desired.

Due to memory constraints I had to remove all named constants in the 
program. Because this makes it hard to follow, I've included the same 
program below; the only difference is that this one has named 
constants and more comments. Individuals are free to modify this code 
to suit their private (non-commercial) use. See the legal stuff below 
for more information.

I you have any questions on how to use this program, or any 
suggestions or comments, please email me at jerobbins@pobox.com.


Legal Stuff:

This program is public domain, but the source is copyrighted in 1997 
by James Robbins. Modifications for private, educational, or 
non-commercial use are allowed. Permission from the author is needed 
to release commercial programs based on this code. No warranty is 
implied or given with this program, and the author is not responsible 
for any damages that may occur from the use of this program.

----------------------------------------------------------------------

# Plot function
new

# Number of functions to graph
1 NumFunc = 3

2 float XMin, XMax, YMin, YMax, x, F : dim F(NumFunc - 1)

# Plot ranges
3 XMin = -3.2
4 XMax = 3.2
5 YMin = -1.1
6 YMax = 1.1
7 goto 19

# Function definitions
10 F(0) = sin(x)
11 F(1) = cos(x)
12 F(2) = 0.5*x
18 return

# Clear screen
19 i = fn 42

# Declare constants
20 TOP = 16
21 BOTTOM = 145
22 HEIGHT = 130
23 LEFT = 0
24 RIGHT = 159
25 WIDTH = 160
26 X_TICK = WIDTH / 10
27 Y_TICK = HEIGHT / 10
28 INTERVAL = 2
29 NUM_INT = 80

# Initialize variables
100 float XStep
# Calculate step size based on
#   number of intervals that
#   will be used to graph
110 XStep = (XMax - XMin) / NUM_INT
# Convert NumFunc to work with zero-based arrays
120 NumFunc = NumFunc - 1

# Find X-axis
# Is X-axis on screen?
198 if (YMin = 0.0) then 230
199 if (YMax = 0.0) then 230
200 if (YMin < 0.0) and (YMax > 0.0) then 230
# If not then place it of screen
210 XAxis = BOTTOM + 2
220 goto 300
# Compute screen position
230 XAxis = int(YMax / (YMax - YMin) * HEIGHT) + TOP
240 if (XAxis = BOTTOM + 1) then XAxis = BOTTOM

# Find Y-axis
# Is Y-axis on screen?
298 if (XMin = 0.0) then 330
299 if (XMax = 0.0) then 330
300 if (XMin < 0.0) and (XMax > 0.0) then 330
# If not the place it off the screen
310 YAxis = LEFT - 1
320 goto 400
# Compute Y-axis screen position
330 YAxis = int(WIDTH * XMin / (XMin - XMax))
340 if (YAxis = RIGHT + 1) then YAxis = RIGHT

# Draw axes
400 if XAxis <= BOTTOM then grline LEFT, XAxis, RIGHT, XAxis
410 if YAxis >= LEFT then grline YAxis, TOP, YAxis, BOTTOM

# Draw ticks
# Each tick is 1/10 of the total range.
# Starting at the axis draw
#   ticks away from axis until 
#   go off edge of graph
500 i = XAxis
505 i = i - Y_TICK
510 if i < TOP then 550
520 grline YAxis - 2, i, YAxis + 2, i
540 goto 505
550 i = XAxis
555 i = i + Y_TICK
560 if i > BOTTOM then 600
570 grline YAxis - 2, i, YAxis + 2, i
590 goto 555

600 i = YAxis
605 i = i - X_TICK
610 if i < LEFT then 650
620 grline i, XAxis - 2, i, XAxis + 2
640 goto 605
650 i = YAxis
655 i = i + X_TICK
660 if i > RIGHT then 700
670 grline i, XAxis - 2, i, XAxis + 2
690 goto 655

# Start plot
# Calculate first point
# These arrays hold old and current screen Y values
700 dim Gf(NumFunc), OldGf(NumFunc)
# On screen x value
705 Gx = 0
710 x = XMin
720 gosub 10
# Set each Y value to the screen
#   position indicated by the
#   function's return
730 for i = 0 to NumFunc
731   Gf(i) = TOP + HEIGHT * (YMax - F(i)) / (YMax - YMin)
732 next i

# Loop through rest of points
800 if Gx >= RIGHT then 900
810 OldGx = Gx
820 for i = 0 to NumFunc
821   OldGf(i) = Gf(i)
822 next i
# Increment screen x by INTERVAL
830 Gx = Gx + INTERVAL
# Increment real x by calculated step
840 x = x + XStep
850 gosub 10
860 for i = 0 to NumFunc
861   Gf(i) = TOP + HEIGHT * (YMax - F(i)) / (YMax - YMin)
# Check to be sure that Y values are on graph
870 if (OldGF(i) > BOTTOM) then 885
871 if (OldGf(i) < TOP) then 885
872 if (Gf(i) > BOTTOM) then 885
873 if (Gf(i) < TOP) then 885
# Draw this segment of graph
880 grline OldGx, OldGf(i), Gx, Gf(i)
885 next i
890 goto 800

# Wait for user to press a keystroke
900 Gx =fn 34
910 i =fn 34: if (Gx=i) then  goto 910
920 end

run
