/*
Present for Nascom Basic
v1.1, [email protected], [email protected]

Need to create that next big presentation using only your home-built z80
computer running ROM Basic? Never fear, Present for Nascom Basic is here.
Much is copied from NB Text Edit- almost everything- and a presentation
script parser is added.

NB Present uses a very simple script type language, interpreting lines in a
linear fashion. Command lines always start with : and a letter, lines starting
with anything else are treated as text and displayed. Here are the script
commands:

       :c - Clear Screen
       :l - Large text, follow with the text you want to print, 15 char max
       :h - Horizontal rule
       :p - pause (wait for user to press enter)
       :t - tab over <n> spaces, no line break (so you can type text there)
       :b - <n> blank lines, follow with the number of blanks you want

For now, NB Present doesn't handle commas, nor does it provide a method for
creating/parsing them like NB Edit does. Keep your presentations succinct and
you won't have to worry about it. Also, you can't use underscore, as it is
interpreted by Nascom Basic as backspace. It's not my fault.

Notes:
- String space and max lines are allocated for the most common use scenarios;
 which is many script command lines without many characters. You may run out
 of lines or string space, depending on how you use this. However, that's
 really not very likely I think.

- 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)
       r - review all lines (with numbers)
       p - presentation mode, start the present script processor
       l - load from input (typed, cassette, pasted, etc.), continuous
       s - echo document contents to screen without #'s, for cassette saving
       q - quit

- Variable list (some/most/all?)
       AZ$ - larger ascii letter art, a-z, 0-9, and space
       PV$ - name/version string
       HR$ - horizontal rule
       HT$ - horizontal tabline
       SF - string free space
       RF - RAM free
       CM$ - command prompt input (string)
       CN - command prompt input (number)
       N,N1,N2,etc. - number, for/next iterator, misc use
       S,S1,S2,etc. - number, for/next iterator inside sub
       LA - Letter ASC value
       FC$ - first character, misc use
       BN$ - banner string

*/

/* large letter defs in line numbered version below */

PRINT CHR$(27)+"[2J"
CLEAR 18000
WIDTH 79
DIM AZ$(40,5)
PV$="NB Present 1.1"
HR$="=========="
HT$="  ----.----.----.----.----.----.----.----.----.----.----.----."
DIM DC$(600)
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$="r" THEN GOTO [REVIEW]
IF CM$="l" THEN GOTO [LOAD]
IF CM$="s" THEN GOTO [SAVE]
IF CM$="p" THEN GOTO [PRESENT]
IF CM$="?" THEN GOTO [HELP]
IF CM$="?:" THEN GOTO [HELP:]
IF CM$="cls" THEN PRINT CHR$(27)+"[2J"
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 [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 [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"
PRINT "e) edit line    x) remove line"
PRINT "r) review       p) present"
PRINT "cls) clear      ?:) script help
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]

REM [SUB BANNER]
FOR S1=1 to 5
FOR S=1 to LEN(BN$)
LA=ASC(MID$(BN$,S,1))
IF LA=32 THEN LA=37
IF LA>47 AND LA<58 THEN LA=LA-21
IF LA>64 AND LA<91 THEN LA=LA-64
IF LA>96 AND LA<123 THEN LA=LA-96
PRINT AZ$(LA,S1);
NEXT S
PRINT
NEXT S1
RETURN

REM [PRESENT]
FOR N=1 to LT
FC$=MID$(DC$(N),1,1)
IF FC$<>":" THEN PRINT DC$(N):GOTO [NEXTN]
FC$=MID$(DC$(N),2,1)
IF FC$="l" THEN BN$=MID$(DC$(N),3):GOSUB [BANNER]
IF FC$="h" THEN FOR N1=1 to 79:PRINT "=";:NEXT N1:PRINT
IF FC$="c" THEN PRINT CHR$(27)+"[2J"
IF FC$="b" THEN N1=VAL(MID$(DC$(N),3)):FOR N2=1 to N1:PRINT:NEXT N2
IF FC$="t" THEN PRINT SPC(VAL(MID$(DC$(N),3)));
IF FC$="p" THEN INPUT CM$:CM$=""
NEXT N
PRINT "Presentation Completed."
GOTO [MAIN]

REM [HELP]
PRINT
PRINT "Script Commands:"
PRINT
PRINT ":l<text> - large text banner, 15 char max"
PRINT ":h       - horizontal line"
PRINT ":c       - clear screen"
PRINT ":b<n>    - line break <n> times"
PRINT ":t<n>    - tab/space <n> times"
PRINT ":p       - pause until user presses enter"
PRINT
GOTO [MAIN]

/* line numbered */

2 PRINT CHR$(27)+"[2J"
4 CLEAR 18000
6 WIDTH 79
8 DIM AZ$(40,5)
10 PV$="NB Present 1.1"
12 HR$="=========="
14 HT$="  ----.----.----.----.----.----.----.----.----.----.----.----."
16 DIM DC$(600)
18 LT=0
20 SF=FRE("")
22 PRINT PV$
24 PRINT "? for help."

50 AZ$(1,1)=".---.":AZ$(1,2)="|   |":AZ$(1,3)="|---|"
51 AZ$(1,4)="|   |":AZ$(1,5)="'   '"
52 AZ$(2,1)=".--. ":AZ$(2,2)="|   )":AZ$(2,3)="|--: "
53 AZ$(2,4)="|   )":AZ$(2,5)="'--' "
54 AZ$(3,1)=" .--.":AZ$(3,2)=":    ":AZ$(3,3)="|    "
55 AZ$(3,4)=":    ":AZ$(3,5)=" `--'"
56 AZ$(4,1)=".--. ":AZ$(4,2)="|   :":AZ$(4,3)="|   |"
57 AZ$(4,4)="|   ;":AZ$(4,5)="'--' "
58 AZ$(5,1)=".---.":AZ$(5,2)="|    ":AZ$(5,3)="|--- "
59 AZ$(5,4)="|    ":AZ$(5,5)="'---'"
60 AZ$(6,1)=".---.":AZ$(6,2)="|    ":AZ$(6,3)="|--- "
61 AZ$(6,4)="|    ":AZ$(6,5)="'    "
62 AZ$(7,1)=" .--.":AZ$(7,2)=":    ":AZ$(7,3)="| --."
63 AZ$(7,4)=":   |":AZ$(7,5)=" `--'"
64 AZ$(8,1)=".   .":AZ$(8,2)="|   |":AZ$(8,3)="|---|"
65 AZ$(8,4)="|   |":AZ$(8,5)="'   '"
66 AZ$(9,1)="--.--":AZ$(9,2)="  |  ":AZ$(9,3)="  |  "
67 AZ$(9,4)="  |  ":AZ$(9,5)="--'--"
68 AZ$(10,1)=".---.":AZ$(10,2)="    |":AZ$(10,3)="    |"
69 AZ$(10,4)="    ;":AZ$(10,5)="`--' "
70 AZ$(11,1)=".   .":AZ$(11,2)="|  / ":AZ$(11,3)="|-'  "
71 AZ$(11,4)="|  \ ":AZ$(11,5)="'   `"
72 AZ$(12,1)=".    ":AZ$(12,2)="|    ":AZ$(12,3)="|    "
73 AZ$(12,4)="|    ":AZ$(12,5)="'---'"
74 AZ$(13,1)=".   .":AZ$(13,2)="|\ /|":AZ$(13,3)="| v |"
75 AZ$(13,4)="|   |":AZ$(13,5)="'   '"
76 AZ$(14,1)=".   .":AZ$(14,2)="|\  |":AZ$(14,3)="| \ |"
77 AZ$(14,4)="|  \|":AZ$(14,5)="'   '"
78 AZ$(15,1)=" .-. ":AZ$(15,2)=":   :":AZ$(15,3)="|   |"
79 AZ$(15,4)=":   ;":AZ$(15,5)=" `-' "
80 AZ$(16,1)=".--. ":AZ$(16,2)="|   )":AZ$(16,3)="|--' "
81 AZ$(16,4)="|    ":AZ$(16,5)="'    "
82 AZ$(17,1)=" .-. ":AZ$(17,2)=":   :":AZ$(17,3)="|   |"
83 AZ$(17,4)=": ( ;":AZ$(17,5)=" `-`-"
84 AZ$(18,1)=".--. ":AZ$(18,2)="|   )":AZ$(18,3)="|--' "
85 AZ$(18,4)="|  \ ":AZ$(18,5)="'   `"
86 AZ$(19,1)=" .-. ":AZ$(19,2)="(   )":AZ$(19,3)=" `-. "
87 AZ$(19,4)="(   )":AZ$(19,5)=" `-' "
88 AZ$(20,1)=".---.":AZ$(20,2)="  |  ":AZ$(20,3)="  |  "
89 AZ$(20,4)="  |  ":AZ$(20,5)="  '  "
90 AZ$(21,1)=".   .":AZ$(21,2)="|   |":AZ$(21,3)="|   |"
91 AZ$(21,4)=":   ;":AZ$(21,5)=" `-' "
92 AZ$(22,1)=".   .":AZ$(22,2)="|   |":AZ$(22,3)="|   |"
93 AZ$(22,4)=" \ / ":AZ$(22,5)="  v  "
94 AZ$(23,1)=".   .":AZ$(23,2)="|   |":AZ$(23,3)="| . |"
95 AZ$(23,4)="\/^\/":AZ$(23,5)=" `  `"
96 AZ$(24,1)=".   .":AZ$(24,2)=" \ / ":AZ$(24,3)="  /  "
97 AZ$(24,4)=" / \ ":AZ$(24,5)="'   '"
98 AZ$(25,1)=".   .":AZ$(25,2)=" \ / ":AZ$(25,3)="  :  "
99 AZ$(25,4)="  |  ":AZ$(25,5)="  '  "
100 AZ$(26,1)=".---.":AZ$(26,2)="   / ":AZ$(26,3)="  /  "
101 AZ$(26,4)=" /   ":AZ$(26,5)="'---'"
102 AZ$(27,1)=" .-. ":AZ$(27,2)=":   :":AZ$(27,3)="|   |"
103 AZ$(27,4)=":   ;":AZ$(27,5)=" `-' "
104 AZ$(28,1)="  .  ":AZ$(28,2)=".'|  ":AZ$(28,3)="  |  "
105 AZ$(28,4)="  |  ":AZ$(28,5)="'---'"
106 AZ$(29,1)=" .-. ":AZ$(29,2)="(   )":AZ$(29,3)="  .' "
107 AZ$(29,4)=" /   ":AZ$(29,5)="'---'"
108 AZ$(30,1)=".--. ":AZ$(30,2)="    )":AZ$(30,3)=" --: "
109 AZ$(30,4)="    )":AZ$(30,5)="`--' "
110 AZ$(31,1)=".  . ":AZ$(31,2)="|  | ":AZ$(31,3)="'--|-"
111 AZ$(31,4)="   | ":AZ$(31,5)="   ' "
112 AZ$(32,1)=".---.":AZ$(32,2)="|    ":AZ$(32,3)="'--. "
113 AZ$(32,4)=".   )":AZ$(32,5)=" `-' "
114 AZ$(33,1)="   , ":AZ$(33,2)="  /  ":AZ$(33,3)=" /-. "
115 AZ$(33,4)="(   )":AZ$(33,5)=" `-' ":
116 AZ$(34,1)=".---.":AZ$(34,2)="    /":AZ$(34,3)="   / "
117 AZ$(34,4)="  /  ":AZ$(34,5)=" '   "
118 AZ$(35,1)=" .-. ":AZ$(35,2)="(   )":AZ$(35,3)=" >-< "
119 AZ$(35,4)="(   )":AZ$(35,5)=" `-' "
120 AZ$(36,1)=" .-. ":AZ$(36,2)="(   )":AZ$(36,3)=" `-/ "
121 AZ$(36,4)="  /  ":AZ$(36,5)=" '   "
122 AZ$(37,1)="     ":AZ$(37,2)="     ":AZ$(37,3)="     "
123 AZ$(37,4)="     ":AZ$(37,5)="     "

200 REM [MAIN]
210 PRINT HR$
220 CM$=""
230 INPUT "Command";CM$
240 IF CM$="a" THEN GOTO 360
250 IF CM$="i" THEN GOTO 470
260 IF CM$="x" THEN GOTO 640
270 IF CM$="e" THEN GOTO 780
280 IF CM$="r" THEN GOTO 940
290 IF CM$="l" THEN GOTO 1090
300 IF CM$="s" THEN GOTO 1210
310 IF CM$="p" THEN GOTO 1690
320 IF CM$="?" THEN GOTO 1340
322 IF CM$="?:" THEN GOTO 1820
324 IF CM$="cls" THEN PRINT CHR$(27)+"[2J"
330 IF CM$="q" THEN GOTO 1490
340 GOTO 200

360 REM [APPEND]
370 PRINT "[Append]"
380 LT=LT+1
390 PRINT "Adding line #";LT
400 IF LT>1 THEN PRINT LT-1;DC$(LT-1)
410 PRINT HT$
420 LI$=""
430 INPUT LI$
440 DC$(LT)=LI$
450 GOTO 200

470 REM [INSERT]
480 PRINT "[Insert]"
490 CN=0
500 INPUT "Insert before line # (0=cancel)";CN
510 CN=INT(CN)
520 IF CN<1 THEN GOTO 200
530 IF CN>LT THEN PRINT "Last line is";LT:GOTO 200
540 PRINT HT$
550 LI$=""
560 INPUT LI$
570 FOR N=LT TO CN STEP -1
580 DC$(N+1)=DC$(N)
590 NEXT N
600 DC$(CN)=LI$
610 LT=LT+1
620 GOTO 200

640 REM [REMOVE]
650 PRINT "[Remove]"
660 CN=0
670 INPUT "Remove line # (0=cancel)";CN
680 CN=INT(CN)
690 IF CN<1 THEN GOTO 200
700 IF CN>LT THEN PRINT "!) Last line is";LT:GOTO 200
710 FOR N=CN TO LT-1
720 DC$(N)=DC$(N+1)
730 NEXT N
740 DC$(LT)=""
750 LT=LT-1
760 GOTO 200

780 REM [EDIT]
790 PRINT "[Edit Line]"
800 CN=0
810 INPUT "Edit line # (0=cancel)";CN
820 CN=INT(CN)
830 IF CN<1 THEN GOTO 200
840 IF CN>LT THEN PRINT "!) Last line is";LT:GOTO 200
850 PRINT HR$
860 PRINT CN;DC$(CN)
870 PRINT HT$
880 LI$=""
890 INPUT LI$
900 IF LI$="" THEN PRINT "Canceled.":GOTO 200
910 DC$(CN)=LI$
920 GOTO 200

940 REM [REVIEW]
950 PRINT "[Review]"
960 IF LT=0 THEN PRINT "!) No lines yet.":GOTO 200
970 PRINT LT;"lines total:"
980 PRINT " ";HT$
990 I=0
1000 FOR N=1 to LT
1010 PRINT STR$(N);" ";DC$(N)
1020 I=I+1
1030 IF I=20 THEN I=0:INPUT "Continue (Y/n/c)";CM$
1040 IF CM$="n" THEN GOTO 200
1050 IF CM$="c" THEN I=21
1060 NEXT N
1070 GOTO 200

1090 REM [LOAD]
1100 PRINT "[LOAD]"
1110 PRINT "Type, paste, or PLAY lines. Enter \. on a line to end"
1120 PRINT HT$
1130 REM [LOADPOINT]
1140 LI$=""
1150 INPUT LI$
1160 IF LI$="\." THEN GOTO 200
1170 LT=LT+1
1180 DC$(LT)=LI$
1190 GOTO 1130

1210 REM [SAVE]
1220 PRINT "[SAVE]"
1230 IF LT=0 THEN PRINT "!) No lines yet.":GOTO 140
1240 CM$=""
1250 PRINT "RECORD and then ENTER to list."
1260 PRINT "When done, ENTER after stopping tape."
1270 INPUT CM$
1280 FOR N=1 to LT
1290 PRINT DC$(N)
1295 FOR D=1 to 1000:NEXT D
1300 NEXT N
1310 INPUT CM$
1320 GOTO 200

1340 REM [HELP]
1345 RF=FRE(0):IF RF<0 THEN RF=65536+RF
1350 PRINT HR$
1360 PRINT PV$
1370 PRINT
1380 PRINT "  Free Ram:";RF;"b / 56958 b"
1390 PRINT "  Free Str:";FRE("");"b /";SF;"b"
1400 PRINT "  Line Cnt:";LT
1410 PRINT
1420 PRINT "a) append       i) insert line"
1430 PRINT "e) edit line    x) remove line"
1440 PRINT "r) review       p) present"
1450 PRINT "l) load lines   s) save         q) quit"
1460 PRINT
1470 GOTO 200

1490 REM [QUIT]
1500 CM$=""
1510 INPUT "Quit (y/N)";CM$
1520 IF CM$="y" THEN END
1530 GOTO 200

1550 REM [SUB BANNER]
1560 FOR S1=1 to 5
1570 FOR S=1 to LEN(BN$)
1580 LA=ASC(MID$(BN$,S,1))
1590 IF LA=32 THEN LA=37
1600 IF LA>47 AND LA<58 THEN LA=LA-21
1610 IF LA>64 AND LA<91 THEN LA=LA-64
1620 IF LA>96 AND LA<123 THEN LA=LA-96
1630 PRINT AZ$(LA,S1);
1640 NEXT S
1650 PRINT
1660 NEXT S1
1670 RETURN

1690 REM [PRESENT]
1700 FOR N=1 to LT
1710 FC$=MID$(DC$(N),1,1)
1720 IF FC$<>":" THEN PRINT DC$(N):GOTO 1790
1730 FC$=MID$(DC$(N),2,1)
1740 IF FC$="l" THEN BN$=MID$(DC$(N),3):GOSUB 1550
1750 IF FC$="h" THEN FOR N1=1 to 79:PRINT "=";:NEXT N1:PRINT
1760 IF FC$="c" THEN PRINT CHR$(27)+"[2J"
1770 IF FC$="b" THEN N1=VAL(MID$(DC$(N),3)):FOR N2=1 to N1:PRINT:NEXT N2
1775 IF FC$="t" THEN PRINT SPC(VAL(MID$(DC$(N),3)));
1780 IF FC$="p" THEN INPUT CM$:CM$=""
1790 NEXT N
1795 PRINT "Presentation completed."
1800 GOTO 200

1820 REM [HELP]
1830 PRINT
1840 PRINT "Script Commands:"
1850 PRINT
1860 PRINT ":l<text> - large text banner, 15 char max"
1870 PRINT ":h       - horizontal line"
1890 PRINT ":c       - clear screen"
1900 PRINT ":b<n>    - line break <n> times"
1910 PRINT ":t<n>    - tab/space <n> times"
1920 PRINT ":p       - pause until user presses enter"
1930 PRINT
1940 GOTO 200