Greetings,
Michael
Code: Select all
*=$033c
; 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 ...
.GetLine
JSR $D7F7 ; FAC#1 to Integer in $14/$15
LDA $15
BNE GetLine_02 ; sec. address >= 256 -> error
LDX $14
JSR $E11B ; CHKIN for channel in $14
LDY #$00
STY $FE ; reset buffer pointer
.GetLine_00
JSR $E10F ; CHRIN
CMP #$0D
BEQ GetLine_01 ; exit loop, if CR
LDY $FE
STA ($37),Y ; store into buffer
INY
STY $FE
CPY #$FF ; maximum length reached?
BNE GetLine_00 ; no
.GetLine_01
JSR $FFCC ; restore I/O
LDY $FE
JMP $D3A2 ; return string length in FAC#1
.GetLine_02
JMP $D248 ; flag error
; ... and is completed with:
.Assign
JSR $CEFD ; check for ','
JSR $D08B ; get variable address
STA $14 ; which is the descriptor
STY $15 ; for a string
LDY #$00
LDA ($14),Y
PHA ; push length
INY
LDA ($14),Y
PHA ; push low byte
INY
LDA ($14),Y
STA $15 ; store high byte
PLA
STA $14 ; store low byte
PLA
STA $FE ; store length
LDY #$00
.Assign_00
CPY $FE
BEQ Assign_01
LDA ($37),Y ; copy from buffer to string
STA ($14),Y
INY
BNE Assign_00
.Assign_01
RTS ; scary, but it works.