10 REM SPELL 20 REM A spelling check program 30 REM For B/B+/E/M/C (with discs) 40 REM by Alan Blundell 50 REM (c) 1989 60 : 70 *FX 3 0 80 MODE 7 90 PROCinit 100 REPEAT 110 PROCopenfile 120 REPEAT 130 PROCaddtolist(FNreadword) 140 UNTIL eof% 150 CLOSE #handle% 160 PROCcheck 170 PROCaction 180 PRINT ''TAB(9)"Press any key .. "; 190 throwaway$=FNgetkey 200 UNTIL 0 210 END 220 : 230 DEFPROCinit 240 PRINT '"SPELLCHECK" 250 PRINT "__________" 260 VDU 28,0,24,39,4 270 size%=7*1024 280 DIM listbuf% size% 290 listbufend%=listbuf%+size%-1 300 DIM wordbuf% 100 310 maxunits%=28 320 DIM dictbuf% maxunits%*256 330 DIM index% 211 340 DIM block% 12 350 osgbpb=&FFD1 360 PROCasm 370 ON ERROR PROCerror:END 380 ENDPROC 390 : 400 DEFPROCopenfile 410 REPEAT 420 REPEAT 430 CLS 440 PRINT TAB(8,15)"Press ESCAPE to quit." 450 PRINT TAB(8,16)"Press RETURN for menu" 460 PROCcursor(1) 470 INPUT TAB(0,1)"Filename : "filename$ 480 PROCcursor(0) 490 IF LEN(filename$)=0 PROCutilities 500 UNTIL LEN(filename$)>0 510 PRINT TAB(8,15) SPC(21) 520 PRINT TAB(8,16) SPC(21) 530 handle%=OPENIN(filename$) 540 UNTIL handle%>0 550 eof%=FALSE 560 listtop%=listbuf% 570 wordcount%=0 580 unique%=0 590 PRINT TAB(0,3)"Number of words : 0" 600 PRINT TAB(0,4)"Number of unique words : 0" 610 ENDPROC 620 : 630 DEFPROCutilities 640 CLS 650 PRINT TAB(13)"UTILITIES" 660 PRINT TAB(13)"_________" 670 PRINT '"1. Remove word(s) from dictionary" 680 PRINT '"2. Convert dictionary to text file" 690 PRINT '"3. Convert text file to dictionary" 700 PRINT '"4. Create new dictionary" 710 PRINT '"5. OS '*' command" 720 PRINT '"6. Back to spellcheck" 730 PRINT ''"Choose (1-6) : "; 740 PROCcursor(1) 750 *FX 21 0 760 REPEAT 770 key$=GET$ 780 UNTIL INSTR("123456*"+CHR$(13),key$) 790 PROCcursor(0) 800 PRINT key$ 810 IF key$="1" THEN CHAIN "DicWipe" 820 IF key$="2" THEN CHAIN "DicConv" 830 IF key$="3" THEN CHAIN "TxtConv" 840 IF key$="4" THEN CHAIN "MakeDic" 850 IF key$="5" THEN PROCoscli 860 IF key$="*" THEN PROCoscli 870 ENDPROC 880 : 890 DEFFNreadword 900 LOCAL char%,word$ 910 REPEAT 920 char%=(BGET #handle%) AND 223 930 UNTIL (char%>64 AND char%<91) OR EOF #handle% 940 IF EOF #handle% eof%=TRUE : = "" 950 word$=CHR$(char%) 960 REPEAT 970 char%=(BGET #handle%) AND 223 980 IF (char%>64 AND char%<91) word$=word$+CHR$(char%) 990 UNTIL char%<65 OR char%>90 OR EOF #handle% 1000 IF EOF #handle% eof%=TRUE 1010 wordcount%=wordcount%+1 1020 PRINT TAB(18,3);wordcount%; 1030 =word$ 1040 : 1050 DEFPROCaddtolist(word$) 1060 LOCAL length% 1070 IF LEN(word$)<2 ENDPROC 1080 IF FNfindword(listbuf%,listtop%,word$) ENDPROC 1090 listptr%=!buffptr% 1100 length%=LEN(word$)+1 1110 IF length%>listbufend%-listtop% PROCbufferfull:ENDPROC 1120 IF listtop%=listptr% GOTO 1170 1130 !source%=listptr% 1140 !dest%=listptr%+length% 1150 !len%=listtop%-listptr% 1160 CALL move 1170 listtop%=listtop%+length% 1180 $listptr%=word$ 1190 unique%=unique%+1 1200 PRINT TAB(25,4);unique% 1210 ENDPROC 1220 : 1230 DEFPROCbufferfull 1240 PRINT TAB(0,6)"Buffer full - closing file." 1250 PRINT "Words already read will be checked." 1260 PRINT "Press a key to continue .. "; 1270 eof%=TRUE 1280 throwaway$=FNgetkey 1290 PRINT TAB(0,6) SPC(110) 1300 ENDPROC 1310 : 1320 DEFPROCcheck 1330 PRINT TAB(0,5)"Checking against dictionary"; 1340 PRINT TAB(0,6)"Words still to check : ";unique% 1350 handle%=OPENIN("Diction") 1360 IF handle%=0 PRINT '''"No dictionary!":END 1370 PROCgbpb(3,handle%,index%,212,0) 1380 listptr%=listbuf% 1390 oldletter%=-1 1400 REPEAT 1410 letter%=?listptr%-65 1420 word$=$(listptr%+1) 1430 IF letter%<>oldletter% PROCloaddict(letter%):oldletter%=letter% 1440 IF FNfindword(dictbuf%,dicttop%,word$) PROCremove(listptr%) ELSE listptr%=listptr%+LEN($listptr%)+1 1450 UNTIL listptr%=listtop% 1460 IF unique%>1 PRINT ';unique%;" words not in dictionary :" 1470 IF unique%=1 PRINT '"One word not in dictionary :" 1480 IF unique%=0 PRINT '"All words found in dictionary" 1490 IF unique%>0 PROClist 1500 CLOSE #handle% 1510 ENDPROC 1520 : 1530 DEFPROCremove(listptr%) 1540 length%=LEN($listptr%)+1 1550 IF listptr%+length%=listtop% GOTO 1600 1560 !source%=listptr%+length% 1570 !dest%=listptr% 1580 !len%=listtop%-listptr%-length% 1590 CALL move 1600 listtop%=listtop%-length% 1610 unique%=unique%-1 1620 PRINT TAB(23,6);unique%;" " 1630 ENDPROC 1640 : 1650 DEFPROClist 1660 VDU 14 1670 listptr%=listbuf% 1680 PRINT 1690 REPEAT 1700 IF POS>(38-LEN($listptr%)) PRINT 1710 PRINT $listptr%;" "; 1720 listptr%=listptr%+LEN($listptr%)+1 1730 UNTIL listptr%=listtop% 1740 VDU 15 1750 PRINT 1760 ENDPROC 1770 : 1780 DEFPROCaction 1790 LOCAL key$,corrections% 1800 IF unique%=0 ENDPROC 1810 PRINT '"Add words to dictionary or make"'"corrections? (y/n) : "; 1820 key$=FNgetkey 1830 IF key$="Y" PRINT "Yes" ELSE PRINT "No" 1840 IF key$<>"Y" ENDPROC 1850 handle%=OPENUP("Diction") 1860 PROCgbpb(3,handle%,index%,212,0) 1870 oldletter%=-1 1880 PROCexecfileinit 1890 corrections%=0 1900 listptr%=listbuf% 1910 PRINT '"A(dd), C(orrect) or I(gnore) :"' 1920 REPEAT 1930 word$=$listptr% 1940 PRINT word$;" (A/C/I) : "; 1950 key$=FNgetkey 1960 IF key$="A" PRINT "Add":PROCaddword(word$) 1970 IF key$="C" PRINT "Correct":PROCcorrect(word$):corrections%=corrections%+1 1980 IF INSTR("AC",key$)=0 PRINT "Ignore" 1990 listptr%=listptr%+LEN($listptr%)+1 2000 UNTIL listptr%=listtop% 2010 PROCsavedict 2020 PROCgbpb(1,handle%,index%,212,0) 2030 CLOSE #handle% 2040 PROCexecfileend 2050 IF corrections%>0 THEN PROCcallwp 2060 ENDPROC 2070 : 2080 DEFPROCaddword(word$) 2090 letter%=ASC(word$)-65 2100 word$=RIGHT$(word$,LEN(word$)-1) 2110 IF letter%<>oldletter% PROCchangedict 2120 IF FNfindword(dictbuf%,dicttop%,word$) ENDPROC 2130 length%=LEN(word$)+1 2140 IF length%>(dictsize%-dictlen%) PRINT '"Not enough room - word not added!":ENDPROC 2150 dictptr%=!buffptr% 2160 IF dicttop%=dictptr% GOTO 2210 2170 !source%=dictptr% 2180 !dest%=dictptr%+length% 2190 !len%=dicttop%-dictptr% 2200 CALL move 2210 dicttop%=dicttop%+length% 2220 $dictptr%=word$ 2230 dictlen%=dictlen%+length% 2240 index%!(letter%*8+4)=dictlen% 2250 ENDPROC 2260 : 2270 DEFPROCcorrect(word$) 2280 LOCAL correct$,key$ 2290 PRINT "Please type the correct spelling"'word$; 2300 *FX 21 0 2310 PROCcursor(1) 2320 INPUT " : "correct$ 2330 PROCcursor(0) 2340 IF correct$="" ENDPROC 2350 PROCexec("CHANGE "+word$+" "+correct$) 2360 PRINT "Add to dictionary? (y/n) : "; 2370 key$=FNgetkey 2380 IF key$="Y" PRINT "Yes" ELSE PRINT "No" 2390 IF key$="Y" PROCaddword(correct$) 2400 ENDPROC 2410 : 2420 DEFPROCexecfileinit 2430 handle2%=OPENOUT("CORRECT") 2440 PROCexec("*WORD") 2450 PROCexec("LOAD "+filename$) 2460 ENDPROC 2470 : 2480 DEFPROCexec(comm$) 2490 LOCAL pos% 2500 FOR pos%=1 TO LEN(comm$) 2510 BPUT #handle2%,ASC(MID$(comm$,pos%,1)) 2520 NEXT 2530 BPUT #handle2%,13 2540 ENDPROC 2550 : 2560 DEFPROCexecfileend 2570 PROCexec("SAVE "+filename$) 2580 PROCexec("*BASIC") 2590 PROCexec("CHAIN ""SPELL""") 2600 CLOSE #handle2% 2610 ENDPROC 2620 : 2630 DEFPROCcallwp 2640 PROCcursor(1) 2650 PRINT '"Making corrections - Please wait .. "; 2660 *FX 3 2 2670 *FX 21 0 2680 FOR loop%=1 TO 13 2690 OSCLI("FX 138 0 "+STR$(ASC(MID$("*EXEC CORRECT",loop%,1)))) 2700 NEXT 2710 *FX 138 0 13 2720 END 2730 : 2740 DEFPROCchangedict 2750 PROCsavedict 2760 PROCloaddict(letter%) 2770 oldletter%=letter% 2780 ENDPROC 2790 : 2800 DEFPROCloaddict(letter%) 2810 A%=3 2820 fileptr%=index%!(letter%*8) 2830 dictsize%=index%!((letter%+1)*8)-fileptr% 2840 dictlen%=index%!(letter%*8+4) 2850 dicttop%=dictbuf%+dictlen% 2860 PROCgbpb(A%,handle%,dictbuf%,dictsize%,fileptr%) 2870 ENDPROC 2880 : 2890 DEFPROCsavedict 2900 IF oldletter%=-1 ENDPROC 2910 A%=1 2920 PROCgbpb(A%,handle%,dictbuf%,dictsize%,fileptr%) 2930 ENDPROC 2940 : 2950 DEFPROCasm 2960 DIM code% &B0 2970 source%=&70 2980 dest%=&72 2990 len%=&74 3000 buffptr%=&70 3010 buffend%=&74 3020 searchptr%=&76 3030 result%=&78 3040 temp%=&78 3050 FOR pass = 0 TO 2 STEP 2 3060 P%=code% 3070 [ 3080 OPT pass 3090 .move 3100 \-------- 3110 SEC 3120 LDA dest% 3130 SBC source% 3140 TAX 3150 LDA dest%+1 3160 SBC source%+1 3170 TAY 3180 TXA 3190 CMP len% 3200 TYA 3210 SBC len%+1 3220 BCS moveleft 3230 BCC moveright 3240 .moveleft 3250 LDY #0 3260 LDX len%+1 3270 BEQ mlskip 3280 .mlloop 3290 LDA (source%),Y 3300 STA (dest%),Y 3310 INY 3320 BNE mlloop 3330 INC source%+1 3340 INC dest%+1 3350 DEX 3360 BNE mlloop 3370 .mlskip 3380 LDX len% 3390 BEQ moveout 3400 .mlloop2 3410 LDA (source%),Y 3420 STA (dest%),Y 3430 INY 3440 DEX 3450 BNE mlloop2 3460 .moveout 3470 RTS 3480 3490 .moveright 3500 CLC 3510 LDA len%+1 3520 PHA 3530 ADC source%+1 3540 STA source%+1 3550 CLC 3560 PLA 3570 ADC dest%+1 3580 STA dest%+1 3590 LDY len% 3600 BEQ mrskip 3610 .mrloop 3620 DEY 3630 LDA (source%),Y 3640 STA (dest%),Y 3650 CPY #0 3660 BNE mrloop 3670 .mrskip 3680 LDX len%+1 3690 BEQ moveout 3700 .mrloop2 3710 DEC source%+1 3720 DEC dest%+1 3730 .mrloop3 3740 DEY 3750 LDA (source%),Y 3760 STA (dest%),Y 3770 CPY #0 3780 BNE mrloop3 3790 DEX 3800 BNE mrloop2 3810 RTS 3820 \ 3830 .search 3840 LDY #255 3850 .sloop 3860 INY 3870 LDA (buffptr%),Y 3880 CMP #13 3890 BEQ foundword 3900 CMP (searchptr%),Y 3910 BEQ sloop 3920 BCC nextword 3930 .notfound 3940 LDY #0 3950 STY result% 3960 RTS 3970 .foundword 3980 LDA (searchptr%),Y 3990 CMP #13 4000 BNE incptr 4010 LDY #1 4020 STY result% 4030 RTS 4040 .nextword 4050 INY 4060 LDA (buffptr%),Y 4070 CMP #13 4080 BNE nextword 4090 .incptr 4100 INY 4110 STY temp% 4120 LDY #255 4130 CLC 4140 LDA buffptr% 4150 ADC temp% 4160 STA buffptr% 4170 LDA buffptr%+1 4180 ADC #0 4190 STA buffptr%+1 4200 CMP buffend%+1 4210 BCC sloop 4220 LDA buffptr% 4230 CMP buffend% 4240 BCC sloop 4250 JMP notfound 4260 ] 4270 NEXT 4280 ENDPROC 4290 : 4300 DEFFNfindword(buf%,top%,word$) 4310 IF buf%=top% !buffptr%=buf%:=0 4320 !buffptr%=buf% 4330 !buffend%=top% 4340 !searchptr%=wordbuf% 4350 $wordbuf%=word$ 4360 CALL search 4370 =?result% 4380 : 4390 DEFFNgetkey 4400 LOCAL key% 4410 PROCcursor(1) 4420 *FX 21 0 4430 key%=GET 4440 PROCcursor(0) 4450 =CHR$(key% AND 223) 4460 : 4470 DEFPROCcursor(on%) 4480 VDU 23,1,on%;0;0;0; 4490 ENDPROC 4500 : 4510 DEFPROCgbpb(A%,handle%,address%,size%,fileptr%) 4520 X%=block% MOD 256 4530 Y%=block% DIV 256 4540 block%?0=handle% 4550 block%!1=address% 4560 block%!5=size% 4570 block%!9=fileptr% 4580 CALL osgbpb 4590 ENDPROC 4600 : 4610 DEFPROCoscli 4620 PROCcursor(1) 4630 CLS 4640 PRINT "Press RETURN to go back to SPELLCHECK"' 4650 REPEAT 4660 INPUT LINE '"*"command$ 4670 OSCLI(command$) 4680 UNTIL command$="" 4690 PROCcursor(0) 4700 ENDPROC 4710 : 4720 DEFPROCerror 4730 PROCcursor(1) 4740 CLOSE #0 4750 IF ERR=17 CLS:END 4760 PRINT ''' 4770 REPORT 4780 PRINT " at line ";ERL 4790 PRINT ' 4800 ENDPROC