[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LF/CR conversion



mmphosis <markstock@mail.com> wrote:
: REM convert linefeed to return
: REM * Applesoft BASIC, DOS 3.3 (might work with PRODOS)
: REM * maximum line length limited to 255 characters
: REM * use of GET may be slow
: 
: 10 FR$ = "SOURCE.TXT"
: 20 FW$ = "DESTINATION.TXT"
: 30 D$ = CHR$(4) : M$ = CHR$(13) : J$ = CHR$(10) : ?
: D$"OPEN"FR$M$D$"OPEN"FW$
: 40 ONERR GOTO 80
: 50 ? D$"READ"FR$
: 60 GET C$ : IF C$ <> J$ THEN T$ = T$ + C$: IF LEN(T$) < 255 THEN 60
: 70 ? M$D$"WRITE"FW$M$T$ : T$ = "" : GOTO 50
: 80 POKE 216,0 : E = PEEK(222) : IF E = 5 THEN IF LEN(T$) THEN ?
: M$D$"WRITE"FW$T$
: 90 ? D$"CLOSE"FW$M$D$"CLOSE"FR$ : IF E <> 5 THEN ? "ERROR "E : STOP

A couple of ideas here...
I believe this code should work in ProDOS.  In DOS 3.3, you should add a 
naked "PRINT" before the write instruction in line 70.  Alternatively, in 
30 set D$=CHR$(13)+CHR$(4).  The trouble with that approach is that while 
it solves the problem of GET preventing a DOS command from executing in 
DOS 3.3, it will also prevent BASIC.SYSTEM from recognizing the ^D as a 
ProDOS command.  So to keep the code DOS-independent, just fix line 70:

70 PRINT:PRINT M$;D$"WRITE "FW$;M$;T$ : T$ = "" : GOTO 50 

Here's another thought...ProDOS will allow you to load any file as a 
binary image.  So why not do it this quick way:

10 HOME:PRINT "Input pathname:  ";:INPUT "";IP$
20 PRINT "Output pathname:  ";:INPUT "";OP$
30 PRINT CHR$(4);"BLOAD ";IP$;",A$2000,TTXT"
40 L = PEEK(48858)*256+PEEK(48857)+1
50 CALL 768
60 PRINT CHR$(4);"CREATE ";OP$;",TTXT"
70 PRINT CHR$(4);"BSAVE ";OP$;",A$2000,L";L;",TTXT"
80 HOME : END

combined with...
0300:        CLC
0301:        LDA $BEDA
0304:        ADC #$20
0306:        STA $07
0308:        LDA #$00
030A:        STA $06
030C:        LDY $BED9
030F: lp1    LDA ($06),Y
0310:        CMP #$0A
0312:        BNE $0318      ; skip
0314:        LDA #$0D
0316:        STA ($06),Y
0318: skip   CMP #$8A
031A:        BNE $0320      ; skip2
031C:        LDA #$8D
031E:        STA ($06),Y
0320: skip2  DEY
0321:        BNE $30F       ; lp1
0323:        DEC $07
0325:        LDA #$1F
0327:        CMP $07
0329:        BNE $30F
032B:        RTS

My programming skills are really rusty in both Applesoft and in 6502, and 
I have probably missed something.  But that should load the text file as 
a binary image into the hires screen space, then start at the end of the 
file and work backward, changing all of the ^J's into ^M's, respecting 
the status of the high bit.  Having walked the entire image (index sits 
at $1FFF), control returns to Applesoft which saves the processed file.

--Dave Althoff, ][.
    /X\        _      *** Respect rides. They do not respect you. ***
   /XXX\      /X\     /X\_      _     /X\__      _     _        _____
  /XXXXX\    /XXX\   /XXXX\_   /X\   /XXXXX\    /X\   /X\      /XXXXX
_/XXXXXXX\__/XXXXX\/XXXXXXXX\_/XXX\_/XXXXXXX\__/XXX\_/XXX\_/\_/XXXXXX