Article View: net.micro.cbm
Article #2225Re: Tokenize text files.
From: Fred Bowen
Date: Tue, 19 Aug 1986 17:51
Date: Tue, 19 Aug 1986 17:51
80 lines
3837 bytes
3837 bytes
> I'm trying to figure out how to tokenize a text file that I downloaded
> with the modem. Right now it is a CBM ascii sequential file.
> ...
> The solution I have in mind is to write a machine language
> routine to open the file and run it through the keyboard buffer just
> as though it had been typed in. Any other ways this could be done?
> What about the program or direct mode in register 157? Any help would
> be appreciated.
>
> Mike Nelson
> ihuxf!cuda
> AT&T Bell Labs
I hate myself for it, but I just had to try it. Sort of like a brain teaser
but worse. The little program below does the trick on a c128. Now you can
edit your BASIC programs with a real editor. (The CBM Editor that comes with
the c64 assembler is not a real editor :-). What it does is opens a channel
to a SEQ disk file, and makes it the default input channel. BASIC then sucks
'keys' directly from the file instead of the keyboard/screen, merrily crunchin'
and a linkin' as she reads. We simply have to wedge IMAIN to catch the status
set by reading the last line from disk so that normal I/O can be restored after
the 'load'. I do not suggest you try this on a c64- the 64 does not do a
clean job of allowing I/O redirection! Note this program expects everything,
including line numbers, to be in petscii (same for as if you had listed your
BASIC program to disk via OPEN/CMD/LIST). I really hate myself for this.
1 REM LOAD A BASIC LIST (SEQ) FILE, CRUNCH & LINK IT ON C128
2 REM 19AUGUST86 FRED BOWEN
3 REM
10 READ A$,B$: ADR=DEC(A$): PRG=ADR
20 DO: POKE ADR,DEC(B$): ADR=ADR+1: READB$: LOOP UNTIL B$="END"
30 INPUT "[cls]FILENAME TO LOAD & LINK"; F$
40 POKE DEC("34A"),13: POKEDEC("34B"),13: POKEDEC("D0"),2
50 PRINT "[cls][d][d]OPEN 8,8,8,";CHR$(34);F$;",S,R";CHR$(34);":SYS";PRG;",,8"
60 PRINT "CLOSE 8[home]";
70 NEW
100 DATA 1800
110 DATA 86,15,20,C6,FF,AD,02,03,AE,03,03,85,FB,86,FC,A9
120 DATA 20,A2,18,8D,02,03,8E,03,03,A2,00,86,7F,86,90,EA
130 DATA A5,90,D0,03,6C,FB,00,20,CC,FF,A9,00,85,15,A5,FB
140 DATA A6,FC,8D,02,03,8E,03,03,6C,02,03,END
where [cls] is CHR$(147) clear screen and [d] is CHR$(17) cursor down.
What the ML looks like:
01800 86 15 STX $15 ;BASIC's CHANNL
01802 20 C6 FF JSR $FFC6 ;CHKIN
01805 AD 02 03 LDA $0302 ;save BASIC's IMAIN vector
01808 AE 03 03 LDX $0303
0180B 85 FA STA $FB
0180D 86 FB STX $FC
0180F A9 20 LDA #$20 ;point IMAIN to us
01811 A2 18 LDX #$18
01813 8D 02 03 STA $0302
01816 8E 03 03 STX $0303
01819 A2 00 LDX #$00
0181B 86 7F STX $7F ;clear RUNMOD
0181D 86 90 STX $90 ;clear STATUS
0181F EA NOP
01820 A5 90 LDA $90 ;begin our IMAIN wedge- check STATUS
01822 D0 03 BNE $1827 ;branch if not clear
01824 6C FA 00 JMP ($00FB) ;else continue normal IMAIN
01827 20 CC FF JSR $FFCC ;CLRCH
0182A A9 00 LDA #$00
0182C 85 15 STA $15 ;clear BASIC's CHANNL too
0182E A5 FA LDA $FB ;restore IMAIN
01830 A6 FB LDX $FC
01832 8D 02 03 STA $0302
01835 8E 03 03 STX $0303
01838 6C 02 03 JMP ($0302) ;done. return to READY
--
Fred Bowen uucp: {ihnp4|seismo|caip}!cbmvax!fred
arpa: cbmvax!fred@seismo.CSS.GOV
tele: 215 431-9100
Commodore Electronics, Ltd., 1200 Wilson Drive, West Chester, PA, 19380
Technical Details
Message-ID:
<659@cbmvax.cbmvax.cbm.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!caip!cbmvax!fredReferences:
<2956@ihuxf.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!caip!cbmvax!fred From: fred@cbmvax.cbm.UUCP (Fred Bowen) Newsgroups: net.micro.cbm Subject: Re: Tokenize text files. Message-ID: <659@cbmvax.cbmvax.cbm.UUCP> Date: Tue, 19-Aug-86 13:51:18 EDT Article-I.D.: cbmvax.659 Posted: Tue Aug 19 13:51:18 1986 Date-Received: Thu, 21-Aug-86 02:15:03 EDT References: <2956@ihuxf.UUCP> Organization: Commodore Technology, West Chester, PA Lines: 80