Put Your USR Code Into A BASIC Program Automatically

F. T. Meiere

Entering machine language into a BASIC program can be tedious, but with AUTOTYPE, you just enter the file name and a BASIC subroutine is automatically written for you.

This utility routine automatically reads machine language code into your BASIC program as a graphic string. It DIMensions the string properly and successfully handles the troublesome quote and carriage return. All you type is RUN. If your fancy turns to READ and POKE, then minor changes will put the code in DATA statements. None of the ideas are new, but the key step is POKE 842, 13 from COMPUTE!, August 1981, #15. My thanks to our sharp-eyed editor who pointed out the potential of this POKE which has been around for some time (e.g., Santa Cruz Software "Memory Map for the Atari"). For entertainment and debugging, you may want to skip the input of actual code, read in the integers from 1 to 255, and watch your Atari program itself.

To enter a USR program as a string, create relocatable machine code and save it to disk or cassette. ENTER this program AUTOTYPE temporarily in your BASIC program. GOTO 9000. The proper string will be entered and displayed on the screen. The whole program can be SAVEd or just the desired portion LISTed to disk or cassette. Alternatively, AUTOTYPE can be RUN separately and the string LISTed and ENTERed as needed.

Line 9000-9310: The disk file containing USR code is OPENed and the first six bytes of DOS information are removed. Cassette users will OPEN #C1, 4, 0, "C :". The remainder of the section makes the program user friendly by setting default values and error messages. The program can be shortened by omitting this whole section, providing the USR file is opened and values given to NAME$, LN1 and INCR.

Line 10020: PDIM dimensions the string.

Line 10030: LNUM prints the line number and the string name. XPR is the position of the first string entry on the current line.

Line 10050: PSPEC enters the quote and carriage return (EOL) separately using CHR$. Lines 10410 and 10420 make sure there is information to enter and remove the quote mark which would normally follow the line number.

Line 10060: CHR$(27) = ESC ensures that the control characters will print. If you POKE 766, 1 to do this, then LNUM cannot clear the screen.

Line 10070: The final quote is added and LENT enters the whole line into this program.

Line 10220: POKE 842, 13 makes the Atari shoot carriage returns continuously after the STOP. This enters the string as printed on the screen. However, when the CONT printed by line 10120 is encountered, the program will resume with line 10230 POKE 842, 12 which returns the computer to normal.

If the USR code is not relocatable, you may want to enter it as DATA and POKE it into memory. The following changes will enter the code as DATA statements.

9130 TRAP 40000
10060 ? X; ","; : IF PEEK(84) = 4 THEN IF PEEK(85) > 30 THEN GOSUB LENT
10070 NEXT I : GOSUB LENT
10110 ? CHR$(125) : ? : ? L; " DATA "; : XPR = PEEK(85)
10205 ? CHR$(126)

Omit the references to PDIM and PSPEC on Line 10020, and omit Line 10050 and Lines 10300 to the end.

One final comment: There are at least three ways to save USR code as part of a BASIC program. 1) Put it in as a SUBR$ string and call USR(ADR(SUBR$)). 2) Put it in DATA statements and POKE it into RAM at a fixed address. 3) Load it immediately following your program and change the pointers to fool BASIC into saving your code along with the program. BASIC does not normally save string space and option 3 can be rather tricky. However, many descriptions, including those in the Atari manuals, are misleading. I recommend that you consider your specific needs and take any other program (including this one) with a grain of salt.

PROGRAM. Put Your USR Code into A BASIC Program Automatically.

9000 REM Convert USR code to a string
9010 AUTOTYPE = 10000 : XYZ = 9200
9020 DIM FILE$(15), NAME$(15) : CO = 0 : C1 = 1 : C2 = C1 + C1
9030 GRAPHICS 0 : POSTION 10, C1 : ? "AUTOTYPE " : ? : ? "Convert USR code to a string "
9040 ? : ? "Please enter information below" : ? "For default values (..) hit RETURN"
9050 ? : ? "USR code FILE NAME "; : INPUT NAME$ : IF NAME$ : = " " THEN 9050
9060 FILE$ = NAME$ : TRAP 9070 : IF NAME$(1, 1) = "D" THEN IF (NAME$(2, 2) = " : " OR NAME$(3, 3) = " : ") THEN 9080
9070 FILE$(1, 2) = "D : " : FILE$ = NAME$
9080 TRAP 9300 : OPEN #C1, 4, 0, FILE$ GOSUB XYZ
9090 IF (X< >255 or Y< >255) THEN ? "NOT LORD FILE", FILE$ : GOTO 9310
9100 GOSUB XYZ : L = Z : GOSUB XYZ : BYTES = Z - L + C1
9110 LN1 = 100 : TRAP 9120 : ? "First line number (100) "; : INPUT LN1
9120 INCR = 10 : TRAP 9130 : ? "Incr. Line number (10) "; : INPUT INCR
9130 TRAP 40000 : ? "USR String name (SUBR$) "; : INPUT NAME$ = "SUBR$" : L = 5
9140 NAME$(L) = "$"
9150 GOSUB TUTOTYPE : CLOSE #C1 : END
9200 REM XYZ - get x&y, calculate z
9210 GET #C1, X : GET #C1, Y : Z = X + 256 * Y : RETURN
9300 ? "NO FILE NAMED", FILE$
9310 ? : ? "Hit RETURN to Run again "; : INPUT NAME$ : RUN
10000 REM {3 SPACES} AUTOTYPE {3 SPACES}
10010 REM Type lines in program
10020 LNUM = 10100 : LENT = 10200 : PDIM = 10300 : PSPEC = 10400 : L = LNI : GOSUB PDIM
10030 K = CO : FOR I = C1 TO BYTES : IF K = CO THEN GOSUB LNUM
10040 GET #C1, X : K = K + C1 : REM code byte
10050 IF (X = 34 OR X = 155) THEN GOSUB PSPEC : GO TO 10070
10060 ? CHR$(27); CHR$(X); : IF K = 80 THEN ? CHR$(34) : GOSUB LENT
10070 NEXT I : IF K< >0 THEN ? CHR$(34) : GOSUB LENT
10080 IGRAPHICS CO : LIST C1, 8999 : RETURN
10100 REM LNUM - print line # and intro
10110 ? CHR$(125) : ? : ? L;" "; NAME * ; " (";I;") = "; CHR$(34); : XPR = PEEK(85)
10120 POSITION C2, 6 : ? "CONT" : POSITION XPR, 2 : RETURN
10200 REM LENT-enter line
10210 ? CHR$(126) : POSITION CO, CO : K = CO : L = L + IN CR
10220 POKE 842, 13 : STOP : REM auto < CR >
10230 POKE 842, 12 : REM stop auto < CR >
10240 RETURN
10300 REM PDIM–print DIM statement
10310 ? CHR$(125) : ? : ? L; " DIM "; NAME$; "(";BYTES;")"
10320 POSITION C2, 6 : ? "CONT" : GOSUB LENT : RETURN
10400 REM PSPEC-quote and < CR >
10410 IF PEEK(85)< >XPR THEN ? CHR$(34) : GOSUB LENT : GOSUB LNUM
10420 ? CHR$(30); "CHR$(";X;")" : GOSUB LENT : RETURN

Return to Table of Contents | Previous Section | Next Section