home *** CD-ROM | disk | FTP | other *** search
Wrap
GW-BASIC | 1984-04-24 | 15.0 KB | 357 lines
10 ' TWOSCREN Author : W W LYONS 30 GOSUB 640 60 KEY 5, "" 70 KEY 6, "TWOSCREN" + CHR$(13) 'Put primary program name here 80 KEY 10, "edit " 'I use this more than 'screen' 90 KEY 8, " DRAW " + CHR$(34) 100 KEY 7, " " + CHR$(13) 110 KEY 9, "key on" + CHR$(13) 120 KEY OFF 128 SCREENFORMAT = 0 140 DIM MONITORBUFFER%(8001) 150 '. Opening statement 160 CLS : LOCATE 3,28 : PRINT "Two screen graphing program" 170 LOCATE 7,5 : PRINT "This program is written for the IBM Personal Computer. I hope you find it" 180 PRINT "useful. The author is human and makes mistakes. Any information prepared by" : PRINT "this program is not guaranteed in any way and is to be used at your personal " 190 PRINT "risk and discretion. All of these disclaimers notwithstanding, I hope that you" : PRINT "find the program useful and will share it with others. Please feel free to" 200 PRINT "share the program in unmodified form." 210 PRINT : PRINT " If you found the program useful or if you have discovered errors or if you" : PRINT "have any hints or suggestions, please contact me at" : PRINT 220 LOCATE ,30 : PRINT "W W Lyons" : LOCATE ,30 : PRINT "4065 Beechwood Drive NW" : LOCATE ,30 : PRINT "Atlanta GA 30327" 230 PRINT : PRINT " Please do not distribute the program in modified form." : PRINT : LOCATE ,30 : PRINT "Thanks for your cooperation." 240 LOCATE 25,50 : COLOR 31 : INPUT "Press ENTER to proceed. " , ANS : COLOR 7 250 '!Beginning of main program - all setup complete 260 GOSUB 640 'Let's be sure we are on the display 270 CLS : GOTO 440 'PRINT "Press h for menu " 280 'PRINT "continuation -or- Press h for more information. 290 A$ = INKEY$ 310 IF A$ ="1" GOTO 740 'Define format of graphics screen 320 'IF A$ ="2" GOTO xxxx ' 330 IF A$ ="3" GOTO 2400 'Draw a line on a graph 340 'IF A$ ="4" GOTO xxxx ' 350 'IF A$ ="5" GOTO xxxx ' 360 'IF A$ ="6" GOTO xxxx ' 370 'IF A$ ="7" GOTO xxxx ' 380 IF A$ ="8" GOTO 680 'Clear monitor screen 390 'IF A$ ="9" GOTO xxxx ' 400 IF A$ ="d" GOTO 3210 'Turn on data print option 410 IF A$ ="h" GOTO 440 'Display MENU 420 IF A$ ="p" THEN PRINT "Bytes not used by BASIC =" FRE(X) 430 GOTO 290 440 CLS 450 A = 16 : LOCATE 5,1 460 PRINT TAB(A+20) " MENU" : PRINT 470 PRINT TAB(A-1) "KEY FUNCTION" : PRINT 480 'PRINT TAB(A) "0 explanation" 490 PRINT TAB(A) "1 Define format of graphics screen" 500 'PRINT TAB(A) "2 " 510 PRINT TAB(A) "3 Draw a graph" 520 'PRINT TAB(A) "4 " 530 'PRINT TAB(A) "5 " 540 'PRINT TAB(A) "6 " 550 'PRINT TAB(A) "7 " 560 PRINT TAB(A) "8 Clear monitor screen" 570 'PRINT TAB(A) "9 " 580 LOCATE 22,20 590 PRINT "PRESS the key indicated to obtain the desired FUNCTION" : PRINT 600 GOTO 290 610 'Subroutine to switch to monitor 615 KEY OFF 620 DEF SEG = 0 : A = PEEK(&H410) : POKE &H410, (A AND &HCF) OR &H20 630 RETURN 640 'Subroutine to switch to monochrome display 650 DEF SEG = 0 : A = PEEK(&H410) : POKE &H410, A OR &H30 660 WIDTH 80 : SCREEN 0 670 RETURN 680 'Clear monitor screen 690 GOSUB 610 'Switch to monitor 700 SCREEN 1 710 SOUND 600,5 720 GOSUB 640 'Switch to display 730 GOTO 270 740 'Define format of graphics device 750 CLS 760 A = 16 : LOCATE 5,1 770 PRINT TAB(A+20) " MENU" : PRINT 780 PRINT TAB(A-1) "KEY FUNCTION" : PRINT 790 'PRINT TAB(A) "0 explanation" 800 PRINT TAB(A) "1 One full screen graph" 810 PRINT TAB(A) "2 Two graphs side by side" 820 'PRINT TAB(A) "3 " 830 PRINT TAB(A) "4 Four graphs" 840 'PRINT TAB(A) "5 " 850 PRINT TAB(A) "6 Place legends on graphs" 860 'PRINT TAB(A) "7 " 870 PRINT TAB(A) "8 One graph with your definition" 880 LOCATE 22,20 890 PRINT "PRESS the key indicated to obtain the desired FUNCTION" : PRINT 900 A$ = INKEY$ 910 IF A$ ="1" GOTO 1060 'Define one full screen graph 920 IF A$ ="2" GOTO 1270 'Define two graphs side by side 930 'IF A$ ="3" GOTO xxxx ' 940 IF A$ ="4" GOTO 1380 'Define four graphs 950 'IF A$ ="5" GOTO xxxx ' 960 IF A$ ="6" GOTO 1030 'Place legends on graphs 970 'IF A$ ="7" GOTO xxxx ' 980 IF A$ ="8" GOTO 1530 'Define a single graph interactively 1000 'IF A$ ="0" GOTO xxxx ' 1010 GOTO 900 1020 'Definition of graph parameters 1030 'MENU options which are not yet implemented 1040 INPUT "This option not implemented. Press enter to return to MENU" , ANS$ 1050 GOTO 270 1060 'Define one full screen graph 1070 SCREENFORMAT = 1 1080 CLS : LOCATE 10,1,0 1090 PRINT "You have selected a full screen graph. Do you want it centered?" 1100 INPUT " (Enter c if you want the graph centered) " , ANS$ 1110 IF ANS$ = "c" OR ANS$ = "C" GOTO 1140 1120 GOSUB 2120 : GOTO 1150 'Set parameters for one large graph - lower left 1140 GOSUB 2080 'Set parameters for one large graph - centered 1150 PRINT : PRINT "Your graph will now appear on the other screen" 1160 SOUND 100,30 1170 GOSUB 610 'Switch to monitor 1180 SCREEN 1 1190 'Common exit for all screen definition options **** **** **** 1200 GOSUB 3240 'Go draw abscissas and tics 1210 LOCATE 24,1 : PRINT "Sample text 4567890" ; 1220 GET (0,0) - (319,199), MONITORBUFFER% 1230 SOUND 500,5 1240 GOSUB 640 'Switch to display 1250 SOUND 600,5 1260 GOTO 270 1270 'Define two graphs side by side 1280 SCREENFORMAT = 2 1290 GOSUB 2160 'Set parameters of left graph of side by side pair 1300 CLS : LOCATE 10,1,0 1310 PRINT "You have selected a two graph format which will now appear on the monitor" 1320 SOUND 100,30 1330 GOSUB 610 'Switch to monitor 1340 SCREEN 1 1350 GOSUB 3240 'Go draw abscissas and tics 1360 GOSUB 2200 'Set parameters of right graph of side by side pair 1370 GOTO 1190 1380 'Define four graphs on one screen 1390 SCREENFORMAT = 4 1400 CLS : LOCATE 10,1,0 1410 PRINT "You have selected four graphs which will now appear on the monitor" 1420 SOUND 100,60 1430 GOSUB 610 'Switch to monitor 1440 SCREEN 1 1450 GOSUB 2240 'Set parameters for upper left graph 1460 GOSUB 3240 'Go draw abscissas and tics 1470 GOSUB 2280 'Set parameters for lower left graph 1480 GOSUB 3240 'Go draw abscissas and tics 1490 GOSUB 2320 'Set parameters for upper right graph 1500 GOSUB 3240 'Go draw abscissas and tics 1510 GOSUB 2360 'Set parameters for lower right graph 1520 GOTO 1190 1530 'Define one graph interactively 1540 SCREENFORMAT = 8 : CLS : LOCATE 1,1,0 1550 PRINT "The graph format is defined as follows:" 1560 PRINT " l <ybeg" 1570 PRINT " -l- <yuppertic = yut" 1580 PRINT " l xo,yo" 1590 PRINT " hunit -l- xorigin,yorigin xend" 1600 PRINT " ^^^ l / /" 1610 PRINT " !---!---!---!---!---l---!---!---!---!---" 1620 PRINT " / l \" 1630 PRINT " xbeg -l-] xrighttic = xrt" 1640 PRINT " xlefttic = xlt l ]vunit" 1650 PRINT " -l-] resolution x y" 1660 PRINT " xtd = xticdisplace l medium 0-319 0-199" 1670 PRINT " xts = xticsize -l- high 0-639 0-199" 1680 PRINT " ytd = yticdisplace \" 1690 PRINT " yts = yticsize yend" 1700 PRINT " ylowertic = ylt" 1710 GOSUB 2120 'Set parameters for one large graph - lower left 1720 FOR I = 1 TO 3 1730 LOCATE 18,1 1740 PRINT "The values of the parameters are ae follows:" 1750 PRINT "xorigin =" XO "yorigin =" YO "hunit =" HU "vunit =" VU 1760 PRINT "xbeg =" XBEG "xend =" XEND "ybeg =" YBEG "yend =" YEND ; 1770 PRINT "xtd =" XTD "xts =" XTS "ytd =" YTD "yts =" YTS 1780 PRINT "xlt, xrt, yut, and ylt are derived, not defined" 1790 PRINT SPC(79) : PRINT SPC(79) : LOCATE 22,1 1800 ON I GOTO 1810, 1890, 1970 1810 PRINT "Enter new xorigin, yorigin, hunit, and vunit if you wish (0 and - values will be ignored) " 1820 LOCATE 22,11 : COLOR 15 : PRINT "xorigin, yorigin, hunit, and vunit" 1830 COLOR 7 : LOCATE 23,13 : INPUT "", XOI, YOI, HUI, VUI 1840 IF XOI > 0 THEN XO = XOI 1850 IF YOI > 0 THEN YO = YOI 1860 IF HUI > 0 THEN HU = HUI 1870 IF VUI > 0 THEN VU = VUI 1880 GOTO 2040 1890 PRINT "Enter new xbeg, xend, ybeg, and yend (0 and - values will be ignored) " 1900 LOCATE 22,11 : COLOR 15 : PRINT "xbeg, xend, ybeg, and yend" 1910 COLOR 7 : LOCATE 23,13 : INPUT "", XBEGI, XENDI, YBEGI, YENDI 1920 IF XBEGI > 0 THEN XBEG = XBEGI 1930 IF XENDI > 0 THEN XEND = XENDI 1940 IF YBEGI > 0 THEN YBEG = YBEGI 1950 IF YENDI > 0 THEN YEND = YENDI 1960 GOTO 2040 1970 PRINT "Enter new xtd, xts, ytd, and yts (0 and - values will be ignored) " 1980 LOCATE 22,11 : COLOR 15 : PRINT "xtd, xts, ytd, and yts" 1990 COLOR 7 : LOCATE 23,13 : INPUT "", XTDI, XTSI, YTDI, YTSI 2000 IF XTDI > 0 THEN XTD = XTDI 2010 IF XTSI > 0 THEN XTS = XTSI 2020 IF YTDI > 0 THEN YTD = YTDI 2030 IF YTSI > 0 THEN YTS = YTSI 2040 NEXT I 2050 CLS : LOCATE 10,1,0 : PRINT "The graph you have defined will now appear on the other screen" 2060 SOUND 100,30 : GOSUB 610 'Switch to monitor 2070 SCREEN 1 : GOTO 1190 2080 'Subroutine to set parameters of single large graph - centered 2090 XO = 160 : YO = 100 : HU = 12 : VU = 10 2100 XBEG = 40 : XEND = 280 : YBEG = 0 : YEND = 199 2110 XTD = 2 : XTS = 4 : YTD = 2 : YTS = 4 : RETURN 2120 'Subroutine to set parameters of single large graph - lower left 2130 XO = 20 : YO = 180 : HU = 12 : VU = 10 2140 XBEG = 20 : XEND = 284 : YBEG = 0 : YEND = 180 2150 XTD = 2 : XTS = 4 : YTD = 2 : YTS = 4 : RETURN 2160 'Subroutine to set parameters of left graph of side by side pair 2170 XO = 80 : YO = 100 : HU = 12 : VU = 10 2180 XBEG = 8 : XEND = 152 : YBEG = 20 : YEND = 179 2190 XTD = 2 : XTS = 4 : YTD = 2 : YTS = 4 : RETURN 2200 'Subroutine to set parameters of right graph of side by side pair 2210 XO = 240 : YO = 100 : HU = 12 : VU = 10 2220 XBEG = 168 : XEND = 312 : YBEG = 20 : YEND = 179 2230 XTD = 2 : XTS = 4 : YTD = 2 : YTS = 4 : RETURN 2240 'Subroutine to set parameters of upper left graph of four 2250 XO = 80 : YO = 50 : HU = 12 : VU = 10 2260 XBEG = 8 : XEND = 152 : YBEG = 10 : YEND = 90 2270 XTD = 2 : XTS = 4 : YTD = 2 : YTS = 4 : RETURN 2280 'Subroutine to set parameters of lower left graph of four 2290 XO = 80 : YO = 150 : HU = 12 : VU = 10 2300 XBEG = 8 : XEND = 152 : YBEG = 110 : YEND = 190 2310 XTD = 2 : XTS = 4 : YTD = 2 : YTS = 4 : RETURN 2320 'Subroutine to set parameters of upper right graph of four 2330 XO = 240 : YO = 50 : HU = 12 : VU = 10 2340 XBEG = 168 : XEND = 312 : YBEG = 10 : YEND = 90 2350 XTD = 2 : XTS = 4 : YTD = 2 : YTS = 4 : RETURN 2360 'Subroutine to set parameters of lower right graph of four 2370 XO = 240 : YO = 150 : HU = 12 : VU = 10 2380 XBEG = 168 : XEND = 312 : YBEG = 110 : YEND = 190 2390 XTD = 2 : XTS = 4 : YTD = 2 : YTS = 4 : RETURN 2400 'Draw lines on graphs 2410 IF SCREENFORMAT = 1 GOTO 2480 2420 IF SCREENFORMAT = 8 GOTO 2480 2430 IF SCREENFORMAT = 2 GOTO 2550 2440 IF SCREENFORMAT = 4 GOTO 2650 2450 CLS : LOCATE 10,1 : SOUND 40,20 : PRINT "The monitor is not formatted." 2460 INPUT "Press enter to return to the MENU" , ANS$ 2470 GOTO 270 2480 'Draw on full screen graph 2490 CLS : LOCATE 6,10 2500 PRINT "The monitor is formatted for a single full screen graph" 2510 ID$ = "" 2520 GOSUB 2910 'Get definition of line, control screens, and draw line 2530 IF ANS$ = "m" GOTO 440 2540 GOTO 2480 2550 'Draw on two graph display 2560 CLS : LOCATE 6,10 2570 PRINT "The monitor is formatted for two side by side graphs" 2580 INPUT "Press enter for left graph or enter r for right graph " , ANS$ 2590 GOSUB 2160 'Select left graph 2600 ID$ = "left" : IF ANS$ = "r" THEN ID$ = "right" : GOSUB 2200 2610 PRINT : PRINT "The " ID$ " graph will be used" 2620 GOSUB 2910 'Get definition of line, control screens, and draw line 2630 IF ANS$ = "m" GOTO 440 2640 GOTO 2550 2650 'Draw on four graph display 2660 CLS : LOCATE 6,10 2670 PRINT "The monitor is formatted for four graphs" 2680 PRINT "Enter 1, 2, 3, or 4 for:" 2690 INPUT " Upper Left Upper Right Lower Left Lower Right " , ANS 2700 IF ANS = 1 THEN ID$ = "upper left" : GOSUB 2240 : GOTO 2770 2710 IF ANS = 2 THEN ID$ = "upper right" : GOSUB 2320 : GOTO 2770 2720 IF ANS = 3 THEN ID$ = "lower left" : GOSUB 2280 : GOTO 2770 2730 IF ANS = 4 THEN ID$ = "lower right" : GOSUB 2360 : GOTO 2770 2740 SOUND 50,5 2750 INPUT "You have not selected a proper choice. Press enter to try again",A 2760 GOTO 2660 2770 PRINT : PRINT "The " ID$ " graph will be used" 2780 GOSUB 2910 'Get definition of line, control screens, and draw line 2790 IF ANS$ = "m" GOTO 440 2800 GOTO 2650 2810 'Subroutine to enter m and b for y = mx + b 2820 LOCATE 12,30 2830 PRINT "For the expression y = mx + b" 2840 LOCATE 14,40 2850 INPUT "Enter a value for m " , M 2860 ' Test value of m 2870 LOCATE 16, 40 2880 INPUT "Now, enter a value for b " , B 2890 ' TEST VALUE OF B 2900 RETURN 2910 'Subroutine to get line parameters, control screens, and draw line 2920 'Subroutine to get m and b, control screens, and draw line 2930 GOSUB 2810 'Enter m and b for y = mx + b 2940 GOSUB 3070 'Leave message on display 2950 GOSUB 610 'Switch to monitor 2960 SCREEN 1 2970 PUT (0,0), MONITORBUFFER% 'Restore previous screen 2980 GOSUB 3390 'Draw line 2990 GET (0,0) - (319,199), MONITORBUFFER% 'and now save again 3000 GOSUB 640 'Switch back to display 3010 GOSUB 3070 'Put message back on display (must be a better way) 3020 GOSUB 3130 'Display data 3030 LOCATE 20,20 3040 PRINT "Press enter if you wish to enter another expression" 3050 INPUT " or enter m to return to the MENU. " , ANS$ 3060 RETURN 3070 'Subroutine to present expression 3080 CLS 3090 LOCATE 10, 10, 0 3100 PRINT "The graph for the expression y =" M "x +" B "is shown on the " 3110 PRINT ID$ " graph on the other screen" 3120 RETURN 3130 'Subroutine to print out all variables 3140 IF DATAPRINT = 0 GOTO 3200 3150 LOCATE 16,1 3160 PRINT "xorigin =" XORIGIN "yorigin =" YORIGIN "hunit =" HUNIT "vunit =" VUNIT 3170 PRINT "m =" M "b =" B 3180 PRINT "x1 =" X1 "y1 =" Y1 "x2 =" X2 "y2 =" Y2 3190 PRINT "px1 =" PX1 "py1 =" PY1 "px2 =" PX2 "py2 =" PY2 3200 RETURN 3210 'Turn on data print option 3220 DATAPRINT = 1 3230 GOTO 270 3240 'Subroutine to draw x and y coordinates with tics 3250 XLT = XO - HU*INT((XO - XBEG)/HU) : XRT = XO + HU*INT((XEND - XO)/HU) 3260 YUT = YO - VU*INT((YO - YBEG)/VU) : YLT = YO + VU*INT((YEND - YO)/VU) 3270 'Draw abscissas 3280 LINE (XBEG, YO) - (XEND, YO) 3290 LINE (XO, YBEG) - (XO, YEND) 3300 FOR XC = XLT TO XRT STEP HU 3310 IF XC = XO GOTO 3330 3320 LINE (XC, YO-YTD) - (XC, YO-YTD+YTS) 'Draw vertical tic 3330 NEXT 3340 FOR YC = YUT TO YLT STEP VU 3350 IF YC = YO GOTO 3370 3360 LINE (XO-XTD, YC) - (XO-XTD+XTS, YC) 'Draw horizontal tic 3370 NEXT 3380 RETURN 3390 'Subroutine to draw line defined by y = mx + b 3400 'y abscissa is inverted!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3410 XUL = INT((XO - XBEG)/HU) : XUR = INT((XEND - XO)/HU) 3420 YUU = INT((YO - YBEG)/VU) : YUL = INT((YEND - YO)/VU) 3430 IF ABS(M) > 9.9999E-05 GOTO 3460 'If m <UNK! {00F7}> 0 let's draw a straight line 3440 X1 = - XUL : X2 = + XUR : Y1 = B : Y2 = B 3450 GOTO 3580 3460 X1 = - XUL : Y1 = M*X1 + B 3470 IF Y1 >= - YUL AND Y1 <= + YUU GOTO 3520 3480 IF Y1 < - YUL GOTO 3500 3490 Y1 = + YUU : GOTO 3510 3500 Y1 = - YUL 3510 X1 = (Y1 - B) / M 3520 X2 = + XUR : Y2 = M*X2 + B 3530 IF Y2 >= - YUL AND Y2 <= + YUU GOTO 3580 3540 IF Y2 < - YUL GOTO 3560 3550 Y2 = + YUU : GOTO 3570 3560 Y2 = - YUL 3570 X2 = (Y2 - B) / M 3580 PX1 = XO+(X1*HU) : PY1 = YO-(Y1 * VU) 3590 PX2 = XO+(X2*HU) : PY2 = YO-(Y2 * VU) 3600 LINE (PX1,PY1) - (PX2,PY2), 1 3610 RETURN