0100 ;------------------- 0110 ; 0120 ;I/O Subroutines 0130 ; 0140 ;For the TEXT EDITOR 0150 ; 0160 ;FILE: IOSUB 0170 ; 0180 ;------------------- 0190 ; 0200 ;OPEN a file/device 0210 ; 0220 ;This routine will open whatever 0230 ;file or device is named in 0240 ;the string - FILNAM. It I/O 0250 ;mode is transfered in IODIR. It 0260 ;will also pause the VBI's. 0270 ; 0280 OPENFIL JSR CLOSE1 0290 INC PAUSE? 0300 LDX #$10 0310 LDA #3 0320 STA ICCOM,X 0330 LDA # FILNAM 0360 STA ICBAH,X 0370 LDA IODIR 0380 STA AUX1,X 0390 LDA #0 0400 STA AUX2,X 0410 JMP CIOV 0420 ; 0430 ;Close IOCB #1 0440 ; 0450 CLOSE1 LDX #$10 0460 LDA #12 0470 STA ICCOM,X 0480 JMP CIOV 0490 ; 0500 ;Open Printer 0510 ; 0520 OPENP LDY #2 0530 OPENP1 LDA PDEV,Y 0540 STA FILNAM,Y 0550 DEY 0560 BPL OPENP1 0570 LDA #8 0580 STA IODIR 0590 BNE OPENFIL 0600 ; 0610 ;Custom Input Routine 0620 ; 0630 ;This is my famous INPUT routine 0640 ;that I used in DEBUG+ and 0650 ;about 10 other programs. It 0660 ;will fetch a 24 character 0670 ;string from the keyboard and 0680 ;return it in MYBUF, terminated 0690 ;by a EOL ($9B). 0700 ; 0710 INPUT LDA #0 ;length = 0 0720 STA CEND 0730 INC IPUT ;signal input 0740 JSR ERMYBF ;and buffer 0750 GETC JSR GETKEY ;get a key 0760 CMP #27 ;ESCape? 0770 BNE GOTCHR ;nope. 0780 DEC IPUT 0790 SEC ;signal error 0800 RTS ;and leave 0810 GOTCHR LDY #ILEGS 0820 AND #$7F 0830 CHKLEG CMP ILLEG,Y 0840 BEQ GETC 0850 DEY 0860 BPL CHKLEG 0870 LDA OLDAC 0880 INPDEL CMP #126 ;Delete? 0890 BNE NOTDEL ;no. 0900 DEC CEND ;lower length 0910 BPL TS2 ;<0? no. 0920 LDA #0 ;make zero. 0930 STA CEND 0940 TS2 JSR TST1 ;test length 0950 LDA CEND ;get length 0960 BEQ GETC ;if not 0 go! 0970 LDY CEND ;put in a spc 0980 CPY #24 0990 BNE DODEL 1000 DEY 1010 DODEL LDA #0 1020 STA COMLN,Y ;erase char 1030 STA COMLN+1,Y ;erase cursor 1040 BEQ GETC ;get next. 1050 NOTDEL CMP #156 ;Delete Line? 1060 BEQ GETC ;yes. 1070 LDY CEND 1080 STA MYBUF,Y 1090 CMP #EOL ;EOL? 1100 BEQ ATEND ;done! 1110 JSR ASC2IC ;make icode 1120 CPY #24 1130 BNE SHCH 1140 DEY 1150 SHCH STA COMLN,Y ;to screen 1160 INY 1170 CPY #25 1180 BCC TST9 1190 DEY 1200 TST9 STY CEND 1210 JSR TST1 ;length? 1220 JMP GETC ;do again. 1230 ATEND LDA MYBUF 1240 CMP #EOL 1250 BEQ INPUT 1260 LDA #0 1270 STA COMLN,Y ;erase cursor 1280 STA IPUT 1290 CLC ;show good input 1300 RTS ;bye. 1310 ; 1320 ;Test INPUT length 1330 ; 1340 TST1 LDA CEND 1350 BNE TL1 1360 STA COMLN 1370 STA COMLN+1 1380 TL1 RTS 1390 ; 1400 ;Get and copy Filename 1410 ; 1420 ;This calls INPUT to fetch a 1430 ;filename, if ESC is pressed 1440 ;it returns to MAIN. Otherwise 1450 ;it converts the filename to 1460 ;upper-case and moves it to the 1470 ;FILNAMe buffer. 1480 ;If the user tried to use the 1490 ;E: or S: devices for file I/O 1500 ;the routine defaults to D: 1510 ; 1520 COPFIL JSR INPUT 1530 BCC COP0 1540 PLA 1550 PLA 1560 JMP CLRWIN 1570 ; 1580 COP0 LDX #0 1590 LDA MYBUF+1 ;second char 1600 CMP #': 1610 BEQ YZERO 1620 LDA MYBUF+2 ;third char 1630 CMP #': 1640 BEQ YZERO 1650 LDY #2 1660 COP1 LDA D1TXT,Y 1670 STA FILNAM,Y 1680 DEY 1690 BPL COP1 1700 LDY #3 1710 BNE COPMYBF 1720 YZERO LDY #0 1730 COPMYBF LDA MYBUF,X 1740 JSR CONL2U 1750 STA FILNAM,Y 1760 CMP #EOL 1770 BEQ COPFILD 1780 INY 1790 INX 1800 CPX #25 1810 BNE COPMYBF 1820 COPFILD LDA FILNAM 1830 CMP #'E 1840 BEQ INSDD 1850 CMP #'S 1860 BNE COPFILD2 1870 INSDD LDA #'D 1880 STA FILNAM 1890 COPFILD2 RTS 1900 ; 1910 ;Perform I/O Operation 1920 ; 1930 PERFIO LDX #$10 1940 STA ICCOM,X 1950 LDA MEMST 1960 STA ICBAL,X 1970 LDA MEMST+1 1980 STA ICBAH,X 1990 JMP CIOV 2000 ; 2010 ;Convert lower to UPPER 2020 ; 2030 ;This simply check to see of 2040 ;the char is lower-case or a 2050 ;CONTROL character, if so it 2060 ;converts it to upper-case. 2070 ; 2080 CONL2U CMP #EOL 2090 BEQ CNNCR 2100 CMP #123 2110 BCS CNNCR 2120 CMP #97 2130 BCC CNL2 2140 SEC 2150 SBC #$20 2160 CNL2 CMP #$20 2170 BCS CNNCR 2180 CLC 2190 ADC #$40 2200 CNNCR RTS 2210 ; 2220 ;LPRINT MYBUF to printer 2230 ; 2240 ;This is similar to the BASIC 2250 ;LPRINT statement. It sends 2260 ;MYBUF to the printer, setting 2270 ;a max output of 80 chars, 2280 ;terminated with an EOL. 2290 ; 2300 LPRINTR LDX #$10 2310 LDA #$09 2320 STA ICCOM,X 2330 LDA # MYBUF 2360 STA ICBAH,X 2370 LDA #80 2380 STA ICBLL,X 2390 LDA #0 2400 STA ICBLH,X 2410 JMP CIOV 2420 ; 2430 ;Print a CR to printer 2440 ; 2450 ;This simply sends out a blank 2460 ;line to the printer by first 2470 ;erasing MYBUF (a precaution) 2480 ;then putting an EOL in the 2490 ;first position in MYBUF, then 2500 ;it falls through to LPRINT. 2510 ; 2520 LPCR JSR ERMYBF 2530 LDA #EOL 2540 STA MYBUF 2550 ; 2560 ;Print a line and check for 2570 ;page break. 2580 ; 2590 ;This first sends out the line 2600 ;in MYBUF, then bumps the 2610 ;number of lines printed, 2620 ;checks to see if we should do 2630 ;a FORM FEED, if so we do and 2640 ;then we increase the PAGENUM. 2650 ;If an error happens during the 2660 ;print LPRINT returns the CIO 2670 ;error code in the Y-reg. 2680 ; 2690 LPRINT JSR LPRINTR 2700 BMI LPERR 2710 INC LINES 2720 LDA LINES 2730 CMP #62 2740 BCC LPOUT 2750 LDA #EOL 2760 STA MYBUF 2770 JSR LPRINTR 2780 JSR LPRINTR 2790 JSR LPRINTR 2800 INC PAGENUM 2810 LDA #0 2820 STA LINES 2830 LPOUT LDA #0 2840 LPERR RTS 2850 ; 2860 ;This is the directory routine. 2870 ;It first asks what drive to 2880 ;get the directory from (12348) 2890 ;and then will get and print 2900 ;the directory, putting 2 file- 2910 ;names per line. If the end of 2920 ;the screen is reached before 2930 ;the directory is done, we will 2940 ;wait for a key, then clear the 2950 ;screen and start at the top 2960 ;again. 2970 ; 2980 DODIR PRINT DIRMS 2990 JSR GETKEY 3000 LDY #4 3010 DIRLP1 CMP DIRNUMS,Y 3020 BEQ GOTDIRN 3030 DEY 3040 BPL DIRLP1 3050 RTS 3060 ; 3070 GOTDIRN STA DIRTXT+1 3080 LDY #6 3090 DIRLP2 LDA DIRTXT,Y 3100 STA FILNAM,Y 3110 DEY 3120 BPL DIRLP2 3130 LDA #6 3140 STA IODIR 3150 JSR CLOSE1 3160 JSR OPENFIL ;open disk 3170 BPL DIRGOOD 3180 PRINT DIRER 3190 JSR CLOSE1 3200 DEC PAUSE? 3210 JMP GETKEY 3220 DIRGOOD JSR CLRSCR 3230 LDA #2 3240 CLC 3250 ADC # SCMEM 3280 ADC #0 3290 STA SCR+1 3300 LDA #0 3310 STA COLS 3320 STA LINES 3330 DIRLP3 JSR READIR 3340 BMI DIRDONE 3350 LDY #0 3360 DIRLP4 LDA MYBUF,Y 3370 CMP #EOL 3380 BEQ ENTRYFIN 3390 JSR ASC2IC 3400 STA (SCR),Y 3410 INY 3420 BNE DIRLP4 3430 ENTRYFIN INC COLS 3440 LDA COLS 3450 CMP #2 3460 BCC ADD20 3470 LDA #0 3480 STA COLS 3490 INC LINES 3500 LDA LINES 3510 CMP #20 3520 BEQ PAUSEDIR 3530 ADD20 LDA SCR 3540 CLC 3550 ADC #20 3560 STA SCR 3570 LDA SCR+1 3580 ADC #0 3590 STA SCR+1 3600 JMP DIRLP3 3610 ; 3620 PAUSEDIR PRINT DIRPS 3630 JSR GETKEY 3640 CMP #27 3650 BEQ DIRLEAVE 3660 PRINT DIRMS 3670 JMP DIRGOOD 3680 ; 3690 DIRDONE PRINT DIRFN 3700 JSR GETKEY 3710 DIRLEAVE JSR CLOSE1 3720 DEC PAUSE? 3730 JMP CLRSCR 3740 ; 3750 ;This routine will get one 3760 ;directory entry from the disk 3770 ;and put it in MYBUF. 3780 ; 3790 READIR LDX #$10 3800 LDA #5 3810 STA ICCOM,X 3820 LDA # MYBUF 3850 STA ICBAH,X 3860 LDA #20 3870 STA ICBLL,X 3880 LDA #0 3890 STA ICBLH,X 3900 JMP CIOV 3910 ; 3920 ;This routine relies on the 3930 ;fact that all text is stored 3940 ;in ICODE in memory, else all 3950 ;is lost. 3960 ; 3970 SCRDRAW LDA #2 3980 CLC 3990 ADC # SCMEM 4020 ADC #0 4030 STA SCR+1 4040 LDA TOPLN 4050 SEC 4060 SBC MEMST 4070 STA TEMP 4080 LDA TOPLN+1 4090 SBC MEMST+1 4100 ORA TEMP 4110 BCS ADROK 4120 LDA MEMST 4130 STA TOPLN 4140 LDA MEMST+1 4150 STA TOPLN+1 4160 ADROK LDA TOPLN 4170 STA TEXTP 4180 LDA TOPLN+1 4190 STA TEXTP+1 4200 LDX #1 4210 PPAGE LDY #0 4220 PLINE LDA (TEXTP),Y 4230 STA LBUFF,Y 4240 INY 4250 CMP #$7F 4260 BNE RCRET 4270 STX CURY 4280 STY CURX 4290 LDA CHARUNDR 4300 RCRET AND #$7F 4310 CMP #EOLCHAR 4320 BEQ BREAK 4330 CPY #38 4340 BNE PLINE 4350 DEY 4360 SLOOP LDA (TEXTP),Y 4370 AND #$7F 4380 CMP #$7F 4390 BNE NXCUR 4400 LDA CHARUNDR 4410 NXCUR CMP #0 4420 BEQ SBRK ;IF = 0 4430 DEY 4440 BNE SLOOP 4450 LDY #37 ;LINELEN-1 4460 SBRK INY 4470 BREAK STY TEMP 4480 LDY #0 4490 COPY LDA LBUFF,Y 4500 STA (SCR),Y 4510 INY 4520 CPY TEMP 4530 BNE COPY 4540 CLC 4550 TYA 4560 ADC TEXTP 4570 STA TEXTP 4580 LDA TEXTP+1 4590 ADC #0 4600 STA TEXTP+1 4610 TYA 4620 STA LENTABLE-1,X 4630 CLRLN CPY #38 4640 BEQ CLEARED 4650 LDA #64 ;SOME CHAR 4660 STA (SCR),Y 4670 INY 4680 JMP CLRLN 4690 CLEARED CLC 4700 LDA SCR 4710 ADC #40 4720 STA SCR 4730 BCC INCNOT 4740 INC SCR+1 4750 INCNOT INX 4760 CPX #21 ;LINE COUNTER 4770 BEQ PDONE 4780 JMP PPAGE 4790 PDONE LDA TEXTP 4800 STA BOTSCR 4810 LDA TEXTP+1 4820 STA BOTSCR+1 4830 RTS 4840 ; 4850 ;This routine will find the 4860 ;length of the line just off 4870 ;the top of the screen. Thus 4880 ;allowing the user to cursor 4890 ;off the top of the screen 4900 ; 4910 CUROFF LDA CURMEM 4920 CMP MEMST 4930 BNE NPAST 4940 LDA CURMEM+1 4950 CMP MEMST+1 4960 BNE NPAST 4970 LDY #$FF 4980 RTS ;finished. 4990 NPAST LDA #0 5000 STA TEXTP 5010 LDA CURMEM+1 5020 SEC 5030 SBC #4 5040 STA TEXTP+1 5050 CMP MEMST+1 5060 BCS NP1 5070 LDA MEMST 5080 STA TEXTP 5090 LDA MEMST+1 5100 STA TEXTP+1 5110 NP1 LDY #0 5120 PLN1 LDA (TEXTP),Y 5130 INY 5140 CMP #EOLCHAR 5150 BEQ BRKL 5160 CPY #38 5170 BNE PLN1 5180 DEY 5190 SLP1 LDA (TEXTP),Y 5200 BEQ SPBRK 5210 DEY 5220 BNE SLP1 5230 LDY #37 5240 SPBRK INY 5250 BRKL CLC 5260 TYA 5270 ADC TEXTP 5280 STA TEXTP 5290 LDA TEXTP+1 5300 ADC #0 5310 STA TEXTP+1 5320 CMP CURMEM+1 5330 BCC NP1 5340 LDA TEXTP 5350 CMP CURMEM 5360 BCC NP1 5370 ALLD RTS