Classic Computer Magazine Archive COMPUTE! ISSUE 61 / JUNE 1985 / PAGE 114

Apple MLX

Machine Language Entry Program

Tim Victor, Editorial Programmer

To make it easier to enter machine language programs into your computer without typos, COMPUTE! is introducing its MLX entry program for the Apple II series. It's our best MLX yet. It runs on the II, II+, IIe, and IIc, and with either DOS 3.3 or ProDOS.

A machine language (ML) program is usually listed as a long series of numbers. It's hard to keep your place and even harder to avoid making mistakes as you type in the listing, since an incorrect line looks almost identical to a correct one. To make error-free entry easier, COMPUTE! generally lists ML programs for Commodore and Atari computers in a format designed to be typed in with a utility called "MLX." The MLX program uses a checksum system to catch typing errors almost as soon as they happen.

This month, COMPUTE! introduces MLX for the Apple II series. Apple MLX checks your typing on a line-by-line basis. It won't let you enter invalid characters or let you continue if there's a mistake in a line. It won't even let you enter a line or digit out of sequence. Best of all, you don't have to know anything about machine language to enter ML programs with MLX. Apple MLX makes typing ML programs almost foolproof.

Using Apple MLX

Type in and save some copies of Apple MLX on disk (you'll want to use MLX to enter future ML programs in COMPUTE!). It doesn't matter whether you type it in on a disk formatted for DOS 3.3 or ProDOS. Programs entered with Apple MLX, however, must be saved to a disk formatted with the same operating system as Apple MLX itself.

If you have an Apple lie or lie, make sure that the key marked CAPS LOCK is in the down position. Type RUN. You'll be asked for the starting and ending addresses of the ML program. These values vary for each program, so they're given at the beginning of the ML program listing and in the program's accompanying article. Find them and type them in.

The next thing you'll see is a menu asking you to select a function. The first is (E)NTER DATA. If you're just starting to type in a program, pick this. Press the E key, and the program asks for the address where you want to begin entering data. Type the first number in the first line of the program listing if you're just starting, or the line number where you left off if you've already typed in part of a program. Hit the RETURN key and begin entering the data.

Once you're in Enter mode, Apple MLX prints the address for each program line for you. You then type in all nine numbers on that line, beginning with the first two-digit number after the colon (:). Each line represents eight bytes and a checksum. When you enter a line and hit RETURN, Apple MLX recalculates the checksum from the eight bytes and the address. If you enter more or less than nine numbers, or the checksum doesn't exactly match, Apple MLX erases the line you just entered and prompts you again for the same line.

Invalid Characters Banned

Apple MLX is fairly flexible about how you type in the numbers. You can put extra spaces between numbers or leave the spaces out entirely, compressing a line into 18 key-presses. Be careful not to put a space between two digits in the middle of a number. Apple MLX will read two single-digit numbers instead of one two-digit number (F 6 means F and 6, not F6).

You can't enter an invalid character with Apple MLX. Only the numerals 0–9 and the letters A–F can be typed in. If you press any other key (with some exceptions noted below), nothing happens. This safeguards against entering extraneous characters. Even better, Apple MLX checks for transposed characters. If you're supposed to type in AO and instead enter OA, Apple MLX will catch your mistake.

Apple MLX also checks to make sure you're typing in the right line. The address (the number to the left of the colon) is part of the checksum recalculation. If you accidentally skip a line and try to enter incorrect values, Apple MLX won't let you continue. Just make sure you enter the correct starting address; if you don't, you won't be able to enter any of the following lines. Apple MLX will stop you.

Editing Features

Apple MLX also includes some editing features. The left- and right-arrow keys allow you to back up and go forward on the line that you are entering, so you can retype data. Pressing the CONTROL (CTRL) and D keys at the same time (delete) removes the character under the cursor, shortening the line by one character. Pressing CTRL-I (insert) puts a space under the cursor and shifts the rest of the line to the right, making the line one character longer. If the cursor is at the right end of the line, neither CTRL-D nor CTRL-I has any effect.

When you've entered the entire listing (up to the ending address that you specified earlier), Apple MLX automatically leaves Enter mode and redisplays the functions menu. If you want to leave Enter mode before then, press the RETURN key when Apple MLX prompts you with a new line address. (For instance, you may want to leave Enter mode to enter a program listing in more than one sitting; see below.)

Display Data

The second menu choice, (DISPLAY DATA, examines memory and shows the contents in the same format as the program listing. You can use it to check your work or to see how far you've gotten. When you press D, Apple MLX asks you for a starting address. Type in the address of the first line you want to see and hit RETURN. Apple MLX displays program lines until you press any key or until it reaches the end of the program.

Save And Load

Two more menu selections let you save programs on disk and load them back into the computer. These are (S)AVE FILE and (L)OAD FILE. When you press S or L, Apple MLX asks you for the filename. The first time you save an ML program, the name you assign will be the program's filename on the disk. If you press L and specify a filename that doesn't exist on the disk, you'll see a disk error message.

If you're not sure why a disk error has occurred, check the drive. Make sure there's a formatted disk in the drive and that it was formatted by the same operating system you're using for Apple MLX (Pro-DOS or DOS 3.3). If you're trying to save a file and see an error message, the disk might be full. Either save the file on another disk or quit Apple MLX (by pressing the Q key), delete an old file or two, then run Apple MLX again. Your typing should still be safe in memory.

Apple MLX: Machine Language Entry Program

100 N = 9: HOME : NORMAL : PRINT "APPLE MLX": POKE 34,2:0 NERR GOTO 610
110 VTAB 1: HTAB 20: PRINT "START ADDRESS";:
       GOSUB 530: IF A = 0 THEN PRINT CHR$ (7): GOTO 110
120 S = A
130 VTAB 2: HTAB 20: PRINT "END ADDRESS
       ";: SOSUB 530: IF S > = A OR A = 0 THEN PRINT CHR$ (7): GOTO 130
140 E = A
150 PRINT : PRINT "CHOOSE:(E)NTER DATA";:
       HTAB 22: PRINT " (D)ISPLAY DATA": HTAB 8: PRINT
       "(L)OAD FILE (S)AVE FILE (Q)UIT": PRINT
160 BET A$: FOR I = 1 TO 5: IF A$ < > MID$ ("EDLSQ",I,1) THEN NEXT : GOTO 160
170 ON I GOTO 270, 220, 180, 200: POKE 34,0: END
180 INPUT "FILENAME: ";A$: IF A$ < > "" THEN PRINT CHR$ (4);"BLOAD";A$;",A";S
190 GOTO 150
200 INPUT "FILENAME: ";A$: IF A$ < > "" THEN PRINT CHR$ (4);"BSAVE";A$;",A";S; ",L";E - S
210 GOTO 150
220 GOSUB 590: IF B = 0 THEN 150
230 FOR B = B TO E STEP 8:L = 4:A = B: GOSUB 580: PRINT A$;": ";:L = 2
240 FOR F = 0 TO 7:V(F + 1) = PEEK (B + F): NEXT : GOSUB 560:V(9) = C
250 FOR F = 1 TO N:A = V(F): GOSUB 580: PRINT
       A$" ";: NEXT : PRINT : IF PEEK (49152) < 128 THEN NEXT
260 POKE 49168,0: GOTO 150
270 GOSUB 590: IF B = 0 THEN 150
280 FOR B = B TO E STEP 8
290 HTAB 1:A = B:L = 4: GOSUB 580: PRINT A$;": ";:
       CALL 64668:AS = "":P = 0: GOSUB 330: IF L = 0 THEN 150
300 GOSUB 470: IF F < > N THEN PRINT CHR$ (7);: GOTO 290
310 IF N = 9 THEN GOSUB 560: IF C < > V(9) THEN PRINT CHR$ (7);: GOTO 290
320 FOR F = 1 TO 8: POKE B + F - 1,V(F): NEXT : PRINT : NEXT : GOTO 150
330 IF LEN (A$) = 33 THEN A$ = 0$:P - 0: PRINT CHR$ (7);
340 L = LEN (A$):O$ - A$:O - P:L$ = "": IF P > 0 THEN L$ = LEFT$ (A$,P)
350 R$ = "": IF P < L - 1 THEN R$ = RIGHT$ (A$,L - P - 1)
360 HTAB 7: PRINT L$;: FLASH : IF P < L THEN PRINT MID$ (A$,P + 1,1);: NORMAL : PRINT R$;
370 PRINT " ";: NORMAL
380 K = PEEK (49152): IF K < 128 THEN 380
390 POKE 49168,0:K = K - 128
400 IF K = 13 THEN HTAB 7: PRINT A$;" ";: RETURN
410 IF K = 32 OR K > 47 AND K < 58 OR K > 64 AND K <
       71 THEN A$ = L$ + CHR$ (K) + R$: P - P + 1
420 IF K = 4 THEN A$ = L$ + R$
430 IF K = 9 THEN A$ = L$ + " " + MID$ (A$,P + 1,1) + R$
440 IF K = 8 THEN P - P - (P > 0)
450 IF K = 21 THEN P = P + (P < L)
460 GOTO 330
470 F = 1:D = 0: FOR P = 1 TO LEN (A$):C$ = MID$ (A$,P,1):
       IF F > N AND C$ < > " " THEN RETURN
480 IF C$ < > " " THEN GOSUB 520:V(F) = J + 16 * (D = 1) * V(F):D - D + 1
490 IF D > 0 AND C$ - " " OR D = 2 THEN D = 0: F= F + 1
500 NEXT : IF D = 0 THEN F = F - 1
510 RETURN
520 J = ASC (C$):J = J - 48 - 7 * (J > 64): RETURN
530 A = 0: INPUT A$:A$ = LEFT$ (A$,4): IF LEN (A$) = 0 THEN RETURN
540 FOR P = 1 TO LEN (A$):C$ = MID$ (A$,P,1): IF C$ < "0"
       OR C$ > "9" AND C$ < "A" OR C$ > "Z" THEN A = 0: RETURN
550 GOSUB 520:A = A * 16 + J: NEXT : RETURN
560 C = INT (B / 256):C = B - 254 $ C - 255 * (C > 127):C = C - 255 * (C > 255)
570 FOR F = 1 TO 8:C = C * 2 - 255 * (C > 127) + V(F):C = C - 255 * (C > 255): NEXT : RETURN
580 I = FRE (0):A$ =" " : FOR I = 1 TO L:T = INT (A / 16):
       A$ = MID$ ("0123456789ABCDEF",A -16 * T + 1, 1) + A$: A = T: NEXT : RETURN
590 PRINT "FROM ADDRESS ";: GOSUB 530: IF S > A OR E < A 0 R A = 0 THEN B = 01 RETURN
600 B = S + 8 * INT ((A - S) / 8)1 RETURN
610 PRINT "DISK ERROR": GOTO 150