10
20
30 MODE((FNfx(135,0)AND&FF00)DIV256)OR&80:A$=FNOS_GetEnv:PROCinit:HIMEM=start%
40 PROCinfo:ON ERROR IFFNerr:PROCexit(ERR)
50 REPEAT:X%=ctrl%:Y%=X%DIV256:IFed%:PROCedit ELSE PROCmenu
60 UNTILFALSE:PROCexit(0):END
70 :
80 DEFPROCinit:ver$="0.30"
90 DIM ctrl% 31,name% 79:?name%=13
100 VDU23,128,0,0,0,0,&7E,&42,&24,&18:
110 VDU23,129,0,0,4,6,&7F,6,4,0:
120 VDU23,130,0,2,2,&22,&62,&FE,&60,&20:
130 VDU23,131,0,8,8,8,42,28,8,0:
140 start%=LOMEM+4096:mtop%=FNmemtop:end%=start%:here%=start%:top%=here%
150 ?end%=13:x%=0:y%=0:hg%=0:file$="":ed%=FALSE:ENDPROC
160 :
170 DEFFNmemtop:IF FALSE THEN
180 =FNfx(132,0)
190 SAVE:SYS "OS_GetEnv" TO ,A%:=A%
200 :
210 DEFPROCon:OSCLI"FX4,2":OSCLI"FX225,128":OSCLI"FX226,144":ENDPROC
220 DEFPROCoff:OSCLI"FX4":OSCLI"FX225,1":OSCLI"FX226,128":ENDPROC
230 :
240 DEFFNerr:IFERR=17:IFed%:PROCinfo
250 IFERR=17:ed%=NOTed%:=FALSE
260 REPORT:PRINTLEFT$(" at line "+STR$ERL,ERR<128 AND ERR<>17):=INKEY-1
270 :
280 DEFPROCinfo:CLS:PRINT"Small Text Editor v";ver$;" (C)1991 JGH"'
290 PRINT"Bytes free ";mtop%-end%'"Bytes used ";end%-start%'
300 PRINT"Editing ";file$;LEFT$("<no file>",file$="")'
310 PRINT"Screen mode ";(FNfx(135,0)AND&FF00)DIV256':ENDPROC
320 :
330 DEFPROCmenu:PROCoff:REPEATINPUTLINE"=> "A$:IFFNcmd:PROCinfo
340 UNTILFALSE:=FALSE
350 :
360 DEFFNcmd:A%=INSTR(A$+" "," "):C$=FNuc(LEFT$(A$,A%-1)):A$=MID$(A$,A%+1)
370 IFC$="MODE":=FNmode
380 IFC$="LOAD":=FNload
390 IFC$="SAVE":=FNsave
400 IFC$="NAME":file$=A$:=TRUE
410 IFC$="NEW":!start%=13:end%=start%:=TRUE
420 IFLEFT$(C$,1)="*":OSCLIC$+" "+A$:=FALSE
430 PRINT"Mistake":=FALSE
440 :
450 DEFFNload:A%=FNfile(A$,5):IFX%!10>mtop%-start%:PRINT"File too long":=FALSE
460 OSCLI"LOAD "+A$+" "+STR$~start%:end%=start%+X%!10:?end%=13:file$=A$
470 top%=start%:x%=0:y%=0:hg%=0:=TRUE
480 :
490 DEFFNsave:IFA$="":A$=file$
500 OSCLI"SAVE "+A$+" "+STR$~start%+" "+STR$~end%+" FFFF0000 FFFFFF00":=FALSE
510 :
520 DEFFNmode:A%=VALA$:IFFNfx(130,0)=&FFFF:IFFNfx(133,A%)<end%:PRINT"Bad mode":=FALSE
530 VDU 22,A%OR&80:=TRUE
540 :
550 :
560 :
570 :
580 :
590 DEFPROCprH:PROCprL(here%,here%+1+LEN$here%):ENDPROC
600 DEFPROCprL(st%,en%):LOCAL ad%
610 ad%=st%:REPEAT
620 PROCb(?ad%):ad%=ad%+1:UNTILad%>=en%:ENDPROC
630 DEFPROCx:COLOUR0:COLOUR135:ENDPROC
640 DEFPROCy:COLOUR7:COLOUR128:ENDPROC
650 DEFPROCz:COLOUR0:COLOUR129:ENDPROC
660 DEFPROCb(B%):IFhg% AND B%>63 AND B%<128 PROCx:VDUB%:PROCy:hg%=0:ENDPROC
670 IFhg% PROCx:VDU42:hg%=0:PROCy
680 IFB%=28 PROCx:VDU45:PROCy:ENDPROC
690 IFB%=29 hg%=TRUE:ENDPROC
700 IFB%>31 AND B%<127 VDUB%:ENDPROC
710 IFB%=13 VDU130,32,8,8:PRINT:ENDPROC
720 IFB%=9 VDU129:PRINTSPC(7-(POS MOD8));:ENDPROC
730 IFB%<32 COLOUR0:COLOUR129:VDUB%+64:COLOUR128:COLOUR7:ENDPROC
740 ENDPROC
750 DEFPROCscr(here%)
760 REPEAT:PROCprH:here%=here%+1+LEN$here%:UNTILVPOS>22 ORhere%>=end%
770 IFhere%>=end% PROCx:PRINT"*End*";:PROCy
780 ENDPROC
790 :
800 :
810 :
820 DEFPROCedit:CLS:PROCscr(top%):PRINTTAB(x%,y%);
830 PROCon:REPEAT:K%=GET:IFK%>126 PROChigh:UNTIL0
840 IF?here%=13 ORK%=13 PROCins(1):?here%=32:VDU9,130,8,8
850 IF?here%=9 PROCins(1):?here%=32:VDU9,129,8,8
860 IFK%=13 REPEATVDU32:UNTILPOS=0:VDU8:VDU28,0,23,POS,VPOS+1,30,11,26,31,x%,y%,130:PRINT:?here%=13:here%=here%+1:PROCprH:PRINTTAB(x%,y%):PROCq:UNTIL0
870 IFK%=9 ?here%=9:PROCprH:PRINTTAB(x%,y%);:PROCb(9):VDU8:PROCq
880 ?here%=K%:VDUK%:PROCp:UNTIL0
890 UNTIL0
900 :
910 DEFPROCp:here%=here%+1:PROCq:ENDPROC
920 DEFPROCq:x%=POS:y%=VPOS:ENDPROC
930 DEFPROChigh
940 IFK%=127 ANDhere%>start% AND ?(here%-1)>31 VDU127:here%=here%-1:?here%=32:PROCq:ENDPROC
950 IFK%=127 ANDhere%>start% AND ?(here%-1)=13 PROCleft:?here%=32:CLS:PROCscr(top%):PRINTTAB(x%,y%);:ENDPROC
960 IFK%=127 ENDPROC
970 IFK%=141 AND here%<end% PROCb(?here%):PROCp:ENDPROC
980 IFK%=141 ENDPROC
990 IFK%=142 AND here%<end% PROCprH:here%=here%+1+LEN$here%:PROCq:ENDPROC
1000 IFK%=142 ENDPROC
1010 IFK%=140 ANDhere%>start% AND ?(here%-1)>31 VDU8:here%=here%-1:PROCq:ENDPROC
1020 IFK%=140 ANDhere%>start% AND ?(here%-1)=13 PROCleft:ENDPROC
1030 IFK%=140 ENDPROC
1040 IFK%=136 PROCinschar:ENDPROC
1050 IFK%=136 ENDPROC
1060 IFK%=137 ANDhere%<end% PROCdel(1):PROCprH:PRINTTAB(x%,y%);:ENDPROC
1070 IFK%=137 ENDPROC
1080 IFK%=129 here%=top%:VDU30:PROCq:ENDPROC
1090 IFK%=130
1100 IFK%=157 PROCprL(here%,here%+LEN$here%):here%=here%+LEN$here%:PROCq:ENDPROC
1110 IFK%=156 VDU13:here%=FNthisL(here%):PROCq:ENDPROC
1120 ENDPROC
1130 DEFPROCleft:here%=here%-1:VDU11:IF?(here%-1)<>13 e%=FNthisL(here%):PROCprL(e%,e%+LEN$e%)
1140 PROCq:ENDPROC
1150 DEFFNthisL(ad%):REPEAT:ad%=ad%-1:UNTIL?(ad%-1)=13 OR ad%=start%:=ad%
1160 DEFPROCins(n%):IFend%>FNmemtop-n%-2 ENDPROC
1170 FOR A%=end% TO here% STEP-1:A%?n%=?A%:NEXT:end%=end%+n%:data%!4=end%:ENDPROC
1180 DEFPROCdel(n%):FOR A%=here% TO end%+4:?A%=A%?n%:NEXT:end%=end%-n%:data%!4=end%:ENDPROC
1190 DEFPROCinschar:IFend%>FNmemtop-2 ENDPROC
1200 PROCins(1):?here%=32:VDU32,8:PROCprL(here%,here%+1+LEN$here%):PRINTTAB(x%,y%);:ENDPROC
1210 DEFFNx(A$):="HELLO"