'Atari to PC - changes 9B hex to 0D 0A 'Original years ago 'modified 5/7/20 for outputing unicode etc 'modified 2/25/21 for html output, html output suppresses [$00] 'modified 2/11/24 to fix html output header 'Anything < 32 or > 127 changed to [$hex] 'Converts common codes to [Clear][Up] etc 'Optionally converts codes to UTF-8 Unicode 'This is QBasic-style code, to compile with freebasic 'use the command: fbc -lang qb -exx at2pc.bas programstart: ON ERROR GOTO ferror PRINT "Atari ATASCII to PC ASCII Converter" useunicode = 0: usehtml = 0 INPUT "Output UTF-8 Unicode characters? (y/n) ", a$ a$ = LCASE$(LTRIM$(a$)) IF LEFT$(a$, 1) = "y" THEN useunicode = 1: INPUT "Output HTML code? (y/n) ", a$ a$ = LCASE$(LTRIM$(a$)): IF LEFT$(a$, 1) = "y" THEN usehtml = 1 PRINT "Using UTF-8 Unicode"; IF usehtml THEN PRINT " with HTML output"; PRINT "." END IF again: INPUT "Input file :", inpfile$ IF inpfile$ = "" THEN SYSTEM OPEN inpfile$ FOR INPUT AS #1: CLOSE #1 OPEN inpfile$ FOR BINARY AS #1 INPUT "Output file :", outfile$ IF outfile$ = "" THEN SYSTEM OPEN outfile$ FOR OUTPUT AS #2 PRINT "Converting... "; currentbyte = 0: revmin = 160: revmax = 255: rf = 0 IF usehtml THEN PRINT #2, "
" PRINT #2, ""
reverse$ = ""
normal$ = ""
revmin = 128: 'to display reversed control codes
ELSE
normal$ = "[Normal]": reverse$ = "[Reverse]"
END IF
WHILE NOT EOF(1)
lastbyte = currentbyte
GOSUB getonebyte
currentbyte = byte
IF byte = 155 THEN
IF lastbyte >= revmin THEN PRINT #2, normal$;
PRINT #2, CHR$(13); CHR$(10);
ELSE
IF byte >= revmin AND byte <= revmax THEN
IF lastbyte <= revmin THEN PRINT #2, reverse$;
byte = byte - 128: rf = 1
ELSE
rf = 0
IF lastbyte >= revmin AND lastbyte <= revmax AND lastbyte <> 155 THEN
PRINT #2, normal$;
END IF
END IF
IF byte < 32 OR byte > 127 THEN
IF usehtml AND byte = 0 AND (lastbyte = 0 OR lastbyte = 155) THEN
outstring$ = "" 'suppress extra [$00] when at the start of a line
ELSE
outstring$ = "[$" + RIGHT$("0" + HEX$(byte), 2) + "]"
END IF
ELSE
outstring$ = CHR$(byte)
IF usehtml THEN 'convert bytes that interfere with HTML
IF byte = 60 THEN outstring$ = "<"
IF byte = 38 THEN outstring$ = "&"
END IF
END IF
IF useunicode THEN
IF byte = 125 THEN outstring$ = CHR$(&HE2) + CHR$(&H86) + CHR$(&HB0)
IF byte = 126 THEN outstring$ = CHR$(&HE2) + CHR$(&H97) + CHR$(&H82) 'last was &H80
IF byte = 127 THEN outstring$ = CHR$(&HE2) + CHR$(&H96) + CHR$(&HB8)
IF outstring$ = "[$01]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&H9C)
IF outstring$ = "[$03]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&H98)
IF outstring$ = "[$04]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&HA4)
IF outstring$ = "[$05]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&H90)
IF outstring$ = "[$0D]" THEN outstring$ = CHR$(&HE2) + CHR$(&H96) + CHR$(&H94)
IF outstring$ = "[$0E]" THEN outstring$ = CHR$(&HE2) + CHR$(&H96) + CHR$(&H82)
IF outstring$ = "[$11]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&H8C)
IF outstring$ = "[$12]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&H80)
IF outstring$ = "[$13]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&HBC)
IF outstring$ = "[$14]" THEN outstring$ = CHR$(&HE2) + CHR$(&H97) + CHR$(&H8F)
IF outstring$ = "[$17]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&HAC)
IF outstring$ = "[$18]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&HB4)
IF outstring$ = "[$19]" THEN outstring$ = CHR$(&HE2) + CHR$(&H96) + CHR$(&H8C)
IF outstring$ = "[$1A]" THEN outstring$ = CHR$(&HE2) + CHR$(&H94) + CHR$(&H94)
IF outstring$ = "[$1B]" THEN outstring$ = CHR$(&HE2) + CHR$(&H90) + CHR$(&H9B)
IF outstring$ = "[$1C]" THEN outstring$ = CHR$(&HE2) + CHR$(&H86) + CHR$(&H91)
IF outstring$ = "[$1D]" THEN outstring$ = CHR$(&HE2) + CHR$(&H86) + CHR$(&H93)
IF outstring$ = "[$1E]" THEN outstring$ = CHR$(&HE2) + CHR$(&H86) + CHR$(&H90)
IF outstring$ = "[$1F]" THEN outstring$ = CHR$(&HE2) + CHR$(&H86) + CHR$(&H92)
ELSE
IF byte = 125 THEN outstring$ = "[Clear]"
IF byte = 126 THEN outstring$ = "[BS]"
IF byte = 127 THEN outstring$ = "[Del]
IF outstring$ = "[$01]" THEN outstring$ = "[|--]"
IF outstring$ = "[$03]" THEN outstring$ = "[--']"
IF outstring$ = "[$04]" THEN outstring$ = "[--|]"
IF outstring$ = "[$05]" THEN outstring$ = "[--.]"
IF outstring$ = "[$11]" THEN outstring$ = "[.--]"
IF outstring$ = "[$12]" THEN outstring$ = "[---]"
IF outstring$ = "[$13]" THEN outstring$ = "[-|-]"
IF outstring$ = "[$17]" THEN outstring$ = "[-.-]"
IF outstring$ = "[$18]" THEN outstring$ = "[-'-]"
IF outstring$ = "[$1A]" THEN outstring$ = "[`--]"
IF outstring$ = "[$1C]" THEN outstring$ = "[Up]"
IF outstring$ = "[$1D]" THEN outstring$ = "[Down]"
IF outstring$ = "[$1E]" THEN outstring$ = "[Left]"
IF outstring$ = "[$1F]" THEN outstring$ = "[Right]"
END IF
IF rf AND LEFT$(outstring$,2) = "[$" THEN 'correct reverse bytes
'side effect of handling reversed control codes too
outstring$ = "[$" + RIGHT$("0" + HEX$(currentbyte), 2) + "]" 'fix hex code
END IF
PRINT #2, outstring$;
END IF
WEND
IF usehtml THEN PRINT #2, "
"
CLOSE
PRINT "Done."
GOTO again
getonebyte:
'return one byte in byte
'has to get 2 bytes from file
'then split between calls
IF odd = 0 THEN
GET #1, , inword% 'get 2 bytes
iwv = inword%
IF iwv < 0 THEN iwv = iwv + 65536
byte = iwv - INT(iwv / 256) * 256 'return low byte
odd = 1
ELSE
byte = INT(iwv / 256) 'return high byte
odd = 0
END IF
RETURN
ferror:
CLOSE
PRINT "Error"
GOTO programstart