Retrochallenge, Retrochallenge 2016/01

Retrochallenge 2016/01: Post 2

(This is part two of the chronicle of my Retrochallenge 2016/01 submission, which is to port some classic Star Trek text games to the Mattel Aquarius. To jump to the beginning, go here.)

STTR1_Aquarius.01
Work-in-Progress Port of STTR1 on the Aquarius

As with most of my Retrochallenge experiences, what I imagine I can accomplish in the first weekend requires the remainder of the month. So it has been with the no-frills port of the 1972 version of STTR1 to the Aquarius. My real goal is to extend a classic Star Trek text game to use Aquarius features such as color, sound, and hand controllers. But here we are halfway through January and I’m still just trying to get the original STTR1 game to run on the target platform.

As of the last several work sessions I have a foothold into the game and am able to play for a bit before encountering a mysterious syntax error at line number 1910. And torpedoes targeted towards Klingons instead say that I shouldn’t attack stars.

In this post I will enumerate the types of code changes I’ve had to make so far and provide some brief examples. At a high level there’s the trivial changes and, well, the non-trivial.

Trivial Changes

Printing Concatenated Strings

HP doesn’t require semicolons as concatenation operators.

HP Time-Shared BASIC

1580  PRINT "YOU HAVE"E" UNITS OF ENERGY"

Aquarius BASIC

1580  PRINT "YOU HAVE";E;" UNITS OF ENERGY"

Array Indexes

HP uses square brackets. Aquarius uses parentheses.

HP Time-Shared BASIC

1630  D[I]=D[I]+1

Aquarius BASIC

1630  D(I)=D(I)+1

Chained Variable Assignments

HP allows chained assignments, the Aquarius does not.

HP Time-Shared BASIC

320  E0=E=3000
330  P0=P=10

Aquarius BASIC

320  E0=3000:E=E0
330  P0=10:P=P0

Shortening Command Lines to 72 Characters

Aquarius BASIC has a maximum line length of 72 characters. The original STTR1 source for the HP contains many, many lines that exceed that limit. These are simple but somewhat tedious changes.

Max_Line_Length.01
Aquarius Guide to Home Computing pp. 1-10

 

Reformatting Output for a 40 Character Display

The teletype terminals that would be connected to an HP2000C  had generous line widths for displaying the program output. The 40 character display on a television set requires inserting line breaks into the original STTR1 text.

HP Time-Shared BASIC

3690  PRINT  USING 3700;K[I,1],K[I,2]
3700  IMAGE  "KLINGON AT SECTOR ",D,",",D," DESTROYED ****"

Aquarius BASIC

3690  PRINT "KLINGON AT SECTOR ";K(I,1);",";K(I,2);
3700  PRINT " DESTROYED ****"

Formatted Output

HP Time-Shared BASIC provides formatted printing akin to C’s printf() function. IMAGE statements define a mix of literal strings and placeholders with format codes. The PRINT USING statement points to the line containing the desired IMAGE statement and a list of variables to be substituted for the placeholders.

HP_BASIC_Print.01

HP_BASIC_Image.01

HP Time-Shared BASIC

2720  PRINT  USING 2730;H,K[I,1],K[I,2],K[I,3]
2730  IMAGE  4D," UNIT HIT ON KLINGON AT SECTOR ",D,",",D,"   (",3D," LEFT)"

Aquarius BASIC

2720  PRINT H;" UNIT HIT ON KLINGON":PRINT " AT SECTOR ";
2730  PRINT K(I,1);",";K(I,2);"  (";K(I,3);" LEFT)":PRINT

Zeroing an Array

The HP has strong matrix support and has the ability to operate on all elements in a matrix with one command.

HP_BASIC_Mat.01

HP Time-Shared BASIC

260  DIM G[8,8],C[9,2],K[3,3],N[3],Z[8,8]
...
910  MAT K=ZER

Aquarius BASIC

260  DIM G(8,8),C(9,2),K(3,3),N(3),Z(8,8)
...
910  FOR I=0 TO 3:FOR J=0 TO 3:K(I,J)=0:NEXT J:NEXT I

Jumped GOTO

HP Time-Shared BASIC provides a variation of the ON x GOTO line1 line2… seen in other BASICs on micros but not found on the Aquarius. And…Was GOTO originally intended to be GO TO (two words)!?

HP_BASIC_Goto.01

HP Time-Shared BASIC

1270  PRINT "COMMAND:";
1280  INPUT A
1290  GOTO A+1 OF 1410,1260,2330,2530,2800,3460,3560,4630

Aquarius BASIC

1270  PRINT "COMMAND:";
1280  INPUT A
1290  IF A=0 THEN 1410
1292  IF A=1 THEN 1260
1293  IF A=2 THEN 2330
1294  IF A=3 THEN 2530
1295  IF A=4 THEN 2800
1296  IF A=5 THEN 3460
1297  IF A=6 THEN 3560
1298  IF A=7 THEN 4630

Non-Trivial Changes

Fundamental Differences in String Variables

HP_BASIC_Strings.01

HP Time-Shared BASIC

HP BASIC strings are implemented as a one-dimensional array of bytes. The command DIM S$ [n] reserves n bytes for string S$.

Throughout the original STTR1 code, much of the game’s “graphical” representation is accomplished by injecting the symbols for the Enterprise (‘<*>’), stars (‘ * ‘), and Klingons (‘+++’) into large strings, exploiting HP’s treatment of Strings as special cases of matrices.

However, HP BASIC strings are limited to 72 characters. For this reason, the young Mr. Mayfield had to split the 192 (8 x 8 x 3) characters needed to represent the Short Range Scan view across 3 string variables Q$, R$, and S$. And then add code to cascade across the variables when trying to inspect  a particular spot in a quadrant.

Strings   ---------------------------------
Q$[01-24]:      *              <*>         
Q$[25-48]:                                  
Q$[49-72]:                                  
R$[01-24]:                      *       *  
R$[25-48]:   *               *       *      
R$[49-72]:                                  
S$[01-25]:           *                      
S$[01-48]:                                   
          ---------------------------------
          COMMAND:?

270  DIM C$[6],D$[72],E$[24],A$[3],Q$[72],R$[72],S$[48]
...
980  A$="<*>"
...
5510  REM ******  INSERTION IN STRING ARRAY FOR QUADRANT ******
5520  S8=Z1*24+Z2*3-26 (Note: Z1 and Z2 are values between 1 and 8)
5530  IF S8>72 THEN 5560
5540  Q$[S8,S8+2]=A$
5550  GOTO 5600
5560  IF S8>144 THEN 5590
5570  R$[S8-72,S8-70]=A$
5580  GOTO 5600
5590  S$[S8-144,S8-142]=A$
5600  RETURN

Aquarius BASIC

Strings do not need to be declared before use. The command DIM Q$ (64) creates an array of 64 (maybe 65) strings. For the Aquarius version of STTR1, strings will need to be used in a totally different way. Since the game’s “graphics” are stored as 3-character  strings, I’ve opted to create an array of strings. In a 8×8 quadrant, Q$ will provide (64) 3-character strings.

270  DIM Q$(64)
...
980  A$="<*>"
...
5510  REM ******  INSERTION IN STRING ARRAY FOR QUADRANT ******
5520  S8=(Z1-1)*8+Z2 (Note: Z1 and Z2 are values between 1 and 8)
5540  Q$(S8)=A$
5600  RETURN

Memory

FreeRAM_16K
No-Frills STTR1 Consumes Most of the 16K on an Aquarius

The target platform is an Aquarius with 16K RAM. If I drop the STTR1 code into an Aquarius emulator, FRE(0) shows that 1K of RAM is remaining. If I want to add new features, then the existing program will need to be put on a diet. Otherwise OM (Out of Memory) errors will begin to appear.

Solutions include: moving the embedded instructions to a separate, stand-alone program, combining multiple BASIC commands onto a single line, and creating an array of resource strings to use in place of repeated literals, like “KLINGON”, “TORPEDO”, and “ENTERPRISE”.

Up Next

Documenting the important variables used in STTR1.


 

Advertisements