Code: Select all
; REL file READ RECORD written 2008 by Michael Kircher
; writing a record into a REL file with PRINT# is okay, but reading it
; back with INPUT# is a bit of a nuisance, since INPUT# is restricted to
; 88 (on the 64: 80) chars, and also barfs at anything unexpected, like
; commas, quotes, and colons.
; this pair of routines reads in a complete record up to (but not including)
; the terminating CR, and assigns it to a string, without any those problems.
; - if the USR vector is not at 828, lower RAMTOP with POKE56,PEEK(56)-1:CLR
; - prepare Z$ once: Z$="I'M 17 CHARS LONG":Z$=Z$+Z$+Z$+Z$+Z$:Z$=Z$+Z$+Z$
; - POKE the following code to address 828
; - set up the USR vector with: POKE1,60:POKE2,3
; INPUT#channel,R$ is now replaced by: R$=LEFT$(Z$,USR(channel)):SYS873,R$
; which calls ...
JSR $D7F7 ; FAC#1 to Integer in $14/$15
BNE GetLine_02 ; sec. address >= 256 -> error
JSR $E11B ; CHKIN for channel in $14
STY $FE ; reset buffer pointer
JSR $E10F ; CHRIN
BEQ GetLine_01 ; exit loop, if CR
STA ($37),Y ; store into buffer
CPY #$FF ; maximum length reached?
BNE GetLine_00 ; no
JSR $FFCC ; restore I/O
JMP $D3A2 ; return string length in FAC#1
JMP $D248 ; flag error
; ... and is completed with:
JSR $CEFD ; check for ','
JSR $D08B ; get variable address
STA $14 ; which is the descriptor
STY $15 ; for a string
PHA ; push length
PHA ; push low byte
STA $15 ; store high byte
STA $14 ; store low byte
STA $FE ; store length
LDA ($37),Y ; copy from buffer to string
RTS ; scary, but it works.