/* Text editor for Nascom Basic v1.3, tfurrows@sdf.org, tfurrows@grex.org This file contains details and information at the top, followed by an un-numbered code listing of the program, followed by a numbered listing of the program designed for copy/paste. The un-numbered listing is easier to manage and make changes to; line numbers are easily added in a variety of ways after major changes are made, negating the need to re-number. When numbering the code, take care to replace [TARGET] goto/gosub listings. Notes: - Written for and tested on Grant Searle Simple z80 SBC - Should run with minimal changes on bw-basic or gw-basic, etc. - Document width in the editor is set to 60 characters, for various reasons. This could be changed later if desired, but it suits me fine. A case could easily be made to have this user configurable. - Limitations in nascom basic disallow commas in input, also the input of a single space- that is to say, only a space and nothing else. - CLS doesn't clear my term, though it works on my virtual term. I use the escape sequence instead. - There is a pause after each line when saving. This is to account for issues with loading from an actual audio file. For some reason, the system wasn't able to keep up, and characters were getting dropped. The pause in the saving creates a pause during playback, which fixes the problem. - Command prompt: ? - command help listing (with stats/info) a - append a line to document i - insert a line (prompt for line to insert after, 0 for beginning) x - remove a line (prompt for line number) e - show and edit a line (prompt for line number) c - replace a character in a line r - review all lines (with numbers) l - load from input (typed, cassette, pasted, etc.), continuous s - echo document contents to screen without #'s, for cassette saving q - quit - Variable list (most, I think): DC$ - the document string array CM$ - command prompt input (string) CN - command prompt input (number) LT - line total SF - Starting free string space RF - RAM free LI$ - line input HR$ - horizontal line HT$ - horizontal line with tab stops N - number, for/next iterator I - number, for counting/breaks, general use CA - character number CR$ - replacement character PV$ - name/version string - Subroutines: - None. - Memory: about 16k for string space about 250 lines 60 char per line more memory available on Grant's 56k design to perhaps do more */ PRINT CHR$(27);"[2J" CLEAR 18000 PV$="NB Text Edit 1.3" HR$="==========" HC$=" 5 10 15 20 25 30 35 40 45 50 55 60" HT$=" ----.----.----.----.----.----.----.----.----.----.----.----." DIM DC$(250) LT=0 SF=FRE("") PRINT PV$ PRINT "? for help." REM [MAIN] PRINT HR$ CM$="" INPUT "Command";CM$ IF CM$="a" THEN GOTO [APPEND] IF CM$="i" THEN GOTO [INSERT] IF CM$="x" THEN GOTO [REMOVE] IF CM$="e" THEN GOTO [EDIT] IF CM$="c" THEN GOTO [CHARACTER] IF CM$="r" THEN GOTO [REVIEW] IF CM$="r" THEN GOTO [PARSE] IF CM$="l" THEN GOTO [LOAD] IF CM$="s" THEN GOTO [SAVE] IF CM$="?" THEN GOTO [HELP] IF CM$="q" THEN GOTO [QUIT] GOTO [MAIN] REM [APPEND] PRINT "[Append]" LT=LT+1 PRINT "Adding line #";LT IF LT>1 THEN PRINT LT-1;DC$(LT-1) PRINT HT$ LI$="" INPUT LI$ DC$(LT)=LI$ GOTO [MAIN] REM [INSERT] PRINT "[Insert]" CN=0 INPUT "Insert before line # (0=cancel)";CN CN=INT(CN) IF CN<1 THEN GOTO [MAIN] IF CN>LT THEN PRINT "Last line is";LT:GOTO [MAIN] PRINT HT$ LI$="" INPUT LI$ FOR N=LT TO CN STEP -1 DC$(N+1)=DC$(N) NEXT N DC$(CN)=LI$ LT=LT+1 GOTO [MAIN] REM [REMOVE] PRINT "[Remove]" CN=0 INPUT "Remove line # (0=cancel)";CN CN=INT(CN) IF CN<1 THEN GOTO [MAIN] IF CN>LT THEN PRINT "!) Last line is";LT:GOTO [MAIN] FOR N=CN TO LT-1 DC$(N)=DC$(N+1) NEXT N DC$(LT)="" LT=LT-1 GOTO [MAIN] REM [EDIT] PRINT "[Edit Line]" CN=0 INPUT "Edit line # (0=cancel)";CN CN=INT(CN) IF CN<1 THEN GOTO [MAIN] IF CN>LT THEN PRINT "!) Last line is";LT:GOTO [MAIN] PRINT HR$ PRINT CN;DC$(CN) PRINT HT$ LI$="" INPUT LI$ IF LI$="" THEN PRINT "Canceled.":GOTO [MAIN] DC$(CN)=LI$ GOTO [MAIN] REM [CHARACTER] PRINT "[Edit char]" CN=0 INPUT "Edit char in line # (0=cancel)";CN CN=INT(CN) IF CN<1 THEN GOTO [MAIN] IF CN>LT THEN PRINT "!) Last line is";LT:GOTO [MAIN] PRINT HC$ PRINT HT$ PRINT " ";DC$(CN) PRINT CA=0 INPUT "Replace char # (0=cancel)";CA CA=INT(CA) I=LEN(DC$(CN)) IF CA<1 THEN GOTO [MAIN] IF CA>I THEN PRINT "!) Last char is";I:GOTO [MAIN] CR$=MID$(DC$(CN),CA,1) PRINT "Replace ";CR$;" with"; LI$="": INPUT LI$ IF LI$<>"" THEN CR$=LI$ DC$(CN)=LEFT$(DC$(CN),CA-1)+LEFT$(CR$,1)+RIGHT$(DC$(CN),I-CA) PRINT DC$(CN) GOTO [MAIN] REM [REVIEW] PRINT "[Review]" IF LT=0 THEN PRINT "!) No lines yet.":GOTO [MAIN] PRINT LT;"lines total:" PRINT " ";HT$ I=0 FOR N=1 to LT PRINT STR$(N);" ";DC$(N) I=I+1 IF I=20 THEN I=0:INPUT "Continue (Y/n/c)";CM$ IF CM$="n" THEN GOTO [MAIN] IF CM$="c" THEN I=21 NEXT N GOTO [MAIN] REM [PARSE] PRINT "[Parse and Read]" IF LT=0 THEN PRINT "!) No lines yet.":GOTO [MAIN] PRINT HR$ PD=0 FOR N=1 to LT FOR N2=1 to LEN(DC$(N)) PR$=MID$(DC$(N),N2,1) IF PR$="\" AND PD=0 THEN PD=1:PR$="" IF PR$="\" AND PD=1 THEN PRINT ",";:PR$="":PD=0 IF PR$<>"\" AND PD=0 THEN PRINT PR$;:PD=0 NEXT N2 PRINT NEXT N GOTO [MAIN] REM [LOAD] PRINT "[LOAD]" PRINT "Type, paste, or PLAY lines. Enter \. on a line to end" PRINT HT$ REM [LOADPOINT] LI$="" INPUT LI$ IF LI$="\." THEN GOTO [MAIN] LT=LT+1 DC$(LT)=LI$ GOTO [LOADPOINT] REM [SAVE] PRINT "[SAVE]" IF LT=0 THEN PRINT "!) No lines yet.":GOTO 140 CM$="" PRINT "RECORD and then ENTER to list." PRINT "When done, ENTER after stopping tape." INPUT CM$ FOR N=1 to LT PRINT DC$(N) FOR D=1 to 1000:NEXT D NEXT N INPUT CM$ GOTO [MAIN] REM [HELP] RF=FRE(0):IF RF<0 THEN RF=65536+RF PRINT HR$ PRINT PV$ PRINT PRINT " Free Ram:";RF;"b / 56958 b" PRINT " Free Str:";FRE("");"b /";SF;"b" PRINT " Line Cnt:";LT PRINT PRINT "a) append i) insert line x) remove line" PRINT "e) edit line c) edit char PRINT "r) review p) parse and read" PRINT "l) load lines s) save q) quit" PRINT GOTO [MAIN] REM [QUIT] CM$="" INPUT "Quit (y/N)";CM$ IF CM$="y" THEN END GOTO [MAIN] /* line numbered */ 10 PRINT CHR$(27);"[2J" 20 CLEAR 18000 30 PV$="NBC Text Edit 1.2" 40 HR$="==========" 50 HC$=" 5 10 15 20 25 30 35 40 45 50 55 60" 60 HT$=" ----.----.----.----.----.----.----.----.----.----.----.----." 70 DIM DC$(250) 80 LT=0 90 SF=FRE("") 110 PRINT PV$ 120 PRINT "? for help." 140 REM [MAIN] 150 PRINT HR$ 160 CM$="" 170 INPUT "Command";CM$ 180 IF CM$="a" THEN GOTO 310 190 IF CM$="i" THEN GOTO 420 200 IF CM$="x" THEN GOTO 590 210 IF CM$="e" THEN GOTO 730 220 IF CM$="c" THEN GOTO 890 230 IF CM$="r" THEN GOTO 1140 240 IF CM$="p" THEN GOTO 1290 250 IF CM$="l" THEN GOTO 1470 260 IF CM$="s" THEN GOTO 1590 270 IF CM$="?" THEN GOTO 1720 280 IF CM$="q" THEN GOTO 1870 290 GOTO 140 310 REM [APPEND] 320 PRINT "[Append]" 330 LT=LT+1 340 PRINT "Adding line #";LT 350 IF LT>1 THEN PRINT LT-1;DC$(LT-1) 360 PRINT HT$ 370 LI$="" 380 INPUT LI$ 390 DC$(LT)=LI$ 400 GOTO 140 420 REM [INSERT] 430 PRINT "[Insert]" 440 CN=0 450 INPUT "Insert before line # (0=cancel)";CN 460 CN=INT(CN) 470 IF CN<1 THEN GOTO 140 480 IF CN>LT THEN PRINT "Last line is";LT:GOTO 140 490 PRINT HT$ 500 LI$="" 510 INPUT LI$ 520 FOR N=LT TO CN STEP -1 530 DC$(N+1)=DC$(N) 540 NEXT N 550 DC$(CN)=LI$ 560 LT=LT+1 570 GOTO 140 590 REM [REMOVE] 600 PRINT "[Remove]" 610 CN=0 620 INPUT "Remove line # (0=cancel)";CN 630 CN=INT(CN) 640 IF CN<1 THEN GOTO 140 650 IF CN>LT THEN PRINT "!) Last line is";LT:GOTO 140 660 FOR N=CN TO LT-1 670 DC$(N)=DC$(N+1) 680 NEXT N 690 DC$(LT)="" 700 LT=LT-1 710 GOTO 140 730 REM [EDIT] 740 PRINT "[Edit Line]" 750 CN=0 760 INPUT "Edit line # (0=cancel)";CN 770 CN=INT(CN) 780 IF CN<1 THEN GOTO 140 790 IF CN>LT THEN PRINT "!) Last line is";LT:GOTO 140 800 PRINT HR$ 810 PRINT CN;DC$(CN) 820 PRINT HT$ 830 LI$="" 840 INPUT LI$ 850 IF LI$="" THEN PRINT "Canceled.":GOTO 140 860 DC$(CN)=LI$ 870 GOTO 140 890 REM [CHARACTER] 900 PRINT "[Edit char]" 910 CN=0 920 INPUT "Edit char in line # (0=cancel)";CN 930 CN=INT(CN) 940 IF CN<1 THEN GOTO 140 950 IF CN>LT THEN PRINT "!) Last line is";LT:GOTO 140 960 PRINT HC$ 970 PRINT HT$ 980 PRINT " ";DC$(CN) 990 PRINT 1000 CA=0 1010 INPUT "Replace char # (0=cancel)";CA 1020 CA=INT(CA) 1030 I=LEN(DC$(CN)) 1040 IF CA<1 THEN GOTO 140 1050 IF CA>I THEN PRINT "!) Last char is";I:GOTO 140 1060 CR$=MID$(DC$(CN),CA,1) 1070 PRINT "Replace ";CR$;" with"; 1080 LI$="": INPUT LI$ 1090 IF LI$<>"" THEN CR$=LI$ 1100 DC$(CN)=LEFT$(DC$(CN),CA-1)+LEFT$(CR$,1)+RIGHT$(DC$(CN),I-CA) 1110 PRINT DC$(CN) 1120 GOTO 140 1140 REM [REVIEW] 1150 PRINT "[Review]" 1160 IF LT=0 THEN PRINT "!) No lines yet.":GOTO 140 1170 PRINT LT;"lines total:" 1180 PRINT " ";HT$ 1190 I=0 1200 FOR N=1 to LT 1210 PRINT STR$(N);" ";DC$(N) 1220 I=I+1 1230 IF I=20 THEN I=0:INPUT "Continue (Y/n/c)";CM$ 1240 IF CM$="n" THEN GOTO 140 1250 IF CM$="c" THEN I=21 1260 NEXT N 1270 GOTO 140 1290 REM [PARSE] 1300 PRINT "[Parse and Read]" 1310 IF LT=0 THEN PRINT "!) No lines yet.":GOTO 140 1320 PRINT HR$ 1330 PD=0 1340 FOR N=1 to LT 1350 FOR N2=1 to LEN(DC$(N)) 1360 PR$=MID$(DC$(N),N2,1) 1370 IF PR$="\" AND PD=0 THEN PD=1:PR$="" 1380 IF PR$="\" AND PD=1 THEN PRINT ",";:PR$="":PD=0 1390 IF PR$<>"\" AND PD=0 THEN PRINT PR$;:PD=0 1410 NEXT N2 1420 PRINT 1430 NEXT N 1450 GOTO 140 1470 REM [LOAD] 1480 PRINT "[LOAD]" 1490 PRINT "Type, paste, or PLAY lines. Enter \. on a line to end" 1500 PRINT HT$ 1510 REM [LOADPOINT] 1520 LI$="" 1530 INPUT LI$ 1540 IF LI$="\." THEN GOTO 140 1550 LT=LT+1 1560 DC$(LT)=LI$ 1570 GOTO 1510 1590 REM [SAVE] 1600 PRINT "[SAVE]" 1610 IF LT=0 THEN PRINT "!) No lines yet.":GOTO 140 1620 CM$="" 1630 PRINT "RECORD and then ENTER to list." 1640 PRINT "When done, ENTER after stopping tape." 1650 INPUT CM$ 1660 FOR N=1 to LT 1670 PRINT DC$(N) 1675 FOR D=1 to 1000:NEXT D 1680 NEXT N 1690 INPUT CM$ 1700 GOTO 140 1720 REM [HELP] 1725 RF=FRE(0):IF RF<0 THEN RF=65536+RF 1730 PRINT HR$ 1740 PRINT PV$ 1750 PRINT 1760 PRINT " Free Ram:";RF;"b / 56958 b" 1770 PRINT " Free Str:";FRE("");"b /";SF;"b" 1780 PRINT " Line Cnt:";LT 1790 PRINT 1800 PRINT "a) append i) insert line x) remove line" 1810 PRINT "e) edit line c) edit char 1820 PRINT "r) review p) parse and read" 1830 PRINT "l) load lines s) save q) quit" 1840 PRINT 1850 GOTO 140 1870 REM [QUIT] 1880 CM$="" 1890 INPUT "Quit (y/N)";CM$ 1900 IF CM$="y" THEN END 1910 GOTO 140