
  Star Trek Programs for the Atari 800
  ====================================

ENTERPRI.BAS, ENTPDOCS.BAS - an extensive version of Star Trek using
a 10x10 sector grid, an 8x8 quadrant grid and uses clock directions for
navigation. It seems to be inspired by the INTELLEC MDS version but it
is different code and uses a somewhat different command structure.
The author and source of this program is not known by me, probably
was found on a BBS sometime in the late '80's.

STARTREK.BAS, STARTREK.DOC - Ed Spoon's real-time version of Star Trek
which "tried to get away from the monotonus Enter coordinates/star chart
Star Trek clones of the past". Not sure what to do with it... by the time
I figure something out I'm being blasted to bits. I guess I'm more used
to the non-real-time version but it certainly is interesting and different.

TREK.BAS, TREKMOD.BAS, trekmod_docs.txt - my hack derived from the 1978
Super Star Trek program. TREK.BAS is the original from the late '80's,
TREKMOD.BAS has a few cosmetic fixes (old text not getting cleared etc)
and adds a level prompt that affects Klingon strength and the chances
that they will shoot first. In this version of Trek the SRS display is
fixed to the top part of the screen and is automatically updated after
every command (unless damaged), the SRS command remains but it's only
useful to clear clutter from the status area or to reprint the screen
if it gets messed up (cursoring off the prompt, bug, etc). The distance
calculator shows the game distance rather than the geometric distance.
Only TREKMOD.BAS is on the disk image, no need to include the buggier
version too.

TREKS.atr - an Atari 2.5 format disk image containing these programs along
with a self-running loader. Can boot using the Atari800 simulator or with
The Altirra simulator for Windows. BASIC must be enabled to run the programs,
in the Atari800 simulator press F5 to enable BASIC if it is not enabled.
The "AUTORUN.SYS" loader/viewer program on the disk image will display
(basic on) when BASIC is enabled.

Boot_TREKSatr - a Linux script that boots the TREKS.atr disk with BASIC
enabled. Requires atari800, if a terminal isn't running then uses xterm.

Run_Atari800_Basic and Run_Atari800_NoBasic - general purpose Linux scripts
for booting Atari disk images using xterm and atari800, associate .atr files
to these scripts. Similar batch files can be made for Windows.

The Atari800 simulator is here: https://atari800.github.io/index.html
For Linux it usually be installed using your distribution's package
manager. The Atari800 simulator now includes 100% legal Altierra roms
so no more scrounging around for the rom files. My "math art" package
contains updated Altirra roms and scripts for running Atari800 with a
simulated hard drive: http://newton.freehostia.com/etcfiles/maprogs.zip

The Altirra web site is here: http://www.virtualdub.org/altirra.html

The *_BAS.txt and *_BAS.htm listing files include UTF-8 imitations of some
of the Atari screen control codes, they are meant only for reading. To produce
the listings I used the setup from the maprogs.zip files that enable simulated
hard disks H1 to H4 as files in those folders. After booting with the maprogs
setup F1 to attach the treks.atr disk to D2: then F5 to boot into BASIC then
went to DOS to run cartridge (BASIC), from there I could load the programs
(LOAD "D2:NAME.BAS") then list them to files (LIST "H4:FILE.LST"). I used my
AT2PC program to convert the "Atascii" listings into PC-compatible files using
unicode characters to display some of the more common symbols and control
characters. Recently I modified the program to output HTML using CSS so that
it could properly display reversed text, and while at it added a few more
conversions. Not every possible code is converted, instead I just added
the conversions needed for the code I wanted to convert.

Here's the updated AT2PC program...

----------------- begin at2pc2.bas -------------------------
'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]
'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, "<head><meta charset="; utf - 8; "/>"
 PRINT #2, "<style type="; CHR$(34); "text/css"; CHR$(34); ">"
 PRINT #2, ".normal {font-size:16px;color:#6B89D7;background-color:#143382;}"
 PRINT #2, ".reverse {color:#143382;background-color:#6B89D7;}"
 PRINT #2, "</style></head><body class="; CHR$(34); "normal"; CHR$(34); "><pre>"
 reverse$ = "<span class=" + CHR$(34) + "reverse" + CHR$(34) + ">"
 normal$ = "</span>"
 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$ = "&lt;"
    IF byte = 38 THEN outstring$ = "&amp;"
   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, "</pre></body>"
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
----------------- end at2pc2.bas ---------------------------

Here is more information about the conversions...
(contains UTF-8 unicode characters)

------- begin copy/pasted stuff from one of my info files ---------

The Atari used $9B as the end-of-line character, these are replaced with
the usual CR LF sequence. Atari programs often use reverse text and embedded
screen control and graphics characters, the most common codes have been
replaced with similar-looking Unicode (UTF-8) characters. There is no easy
way to get reverse text so this is indicated by [Reverse] text [Normal].

Control character conversions...
$7D --> ↰    (E286B0)	Clear screen
$FE --> ◀    (E29780)	Delete character from right
$1C --> ↑    (E28691)	Cursor up
$1D --> ↓    (E28693)	Cursor down
$1E --> ←    (E28690)	Cursor left
$1F --> →    (E28692)	Cursor right

Graphics character conversions...
$11 --> ┌    (E2948C)
$12 --> ─    (E29480)
$05 --> ┐    (E29490)
$1A --> └    (E29494)
$03 --> ┘    (E29498)
$01 --> ├    (E2949C)
$13 --> ┼    (E294BC)
$04 --> ┤    (E294A4)
$17 --> ┬    (E294AC)
$18 --> ┴    (E294B4)

More conversions are possible but stopped there as that covered just about
everything I used. Anything not recognized is converted to [$xx] where xx
is the hex character code.

The at2pc.bas program is written in QBasic, the most stable programming
language I use (:-). The program can be compiled for just about any x86
Linux or Windows computer using the FreeBasic compiler. The logic is
quite simple, shouldn't be difficult to convert it to just about any
programming language that can read and write arbitrary bytes.

2/25/21 - updated at2pc2.bas program...

This updated version of the converter can output HTML directly, so it can
use CSS codes to properly reverse text instead of [Reverse] [Normal] tags.

Also does a few more conversions...
$0D --> ▔    (E29694)
$0E --> ▂    (E29682)
$14 --> ●    (E2978F)
$19 --> ▌    (E2968C)
$1B --> ␛    (esc E2909B)
$7E --> ◂    (E29782, replaces $FE code)
$7F --> ▸    (E296B8)

------- end copy/pasted stuff -------------------------------------

I changed the back triangle character because the unicode code I was using
sometimes displayed as wide characters. To get UTF-8 byte sequences for the
characters I used the following FreeBasic program, with it I found potential 
replacements from the Wikipedia unicode and Atascii entries (not all the
listed equivalents worked for me) and it converts the Unicode hex string
into a list of UTF-8 bytes.

------- begin file hex2utf.fbc -------------------------
'for scripting: #!/usr/local/bin/fbcscript
'hex2utf8.fbc - converts hex unicode to UTF encoded bytes - 200511
'prompts for hex string for a unicode character (often stated as U+somehex,
'don't enter the U+ part, just the hex) then prints the encoded byte
'sequence in decimal and hex and displays the character (if possible).
'Loops until 0 or an empty string is entered.
'fbscript version - uses fbscript to temporarily compile and run
'using the freebasic compiler (fbc -lang qb -exx)
color 15,1:cls
print "*** Unicode to UTF-8 ***"
dim bytenum(4)
again:
input "Unicode hex string: ",a$
n=int(val("&h"+a$))
if n<=0 then goto programend
if n>55295 and n<57344 then goto badnumber
if n<128 then goto onebyte
if n>127 and n<2048 then goto twobyte
if n>2047 and n<65536 then goto threebyte
if n>65535 and n<1114112 then goto fourbyte
badnumber:
print "Invalid code":goto again
onebyte:
nbytes=1 : bytenum(1)=n
goto showresults
twobyte:
nbytes=2
bytenum(1)=192+(n AND 1984)/64
bytenum(2)=128+(n AND 63)
goto showresults
threebyte:
nbytes=3
bytenum(1)=224+(n AND 61440)/4096
bytenum(2)=128+(n AND 4032)/64
bytenum(3)=128+(n AND 63)
goto showresults
fourbyte:
nbytes=4
bytenum(1)=240+(n AND 1835008)/262144
bytenum(2)=128+(n AND 258048)/4096
bytenum(3)=128+(n AND 4032)/64
bytenum(4)=128+(n AND 63)
showresults:
print "Decimal ";
for i=1 to nbytes
 print bytenum(i);
next i : print
print "Hex      ";
for i=1 to nbytes
 print right$("0"+hex$(bytenum(i)),2);"  ";
next i : print
print "Display  ";
for i=1 to nbytes
 print chr$(bytenum(i));
next i : print
goto again
programend:
system
------- begin file hex2utf.fbc -------------------------

- Terry Newton (wtn90125@yahoo.com)

