Apple, IBM ML Addresses
Can you tell me how to find the beginning and ending addresses of a machine language program for the Apple IIe?
Bill Link
Ever since we told Commodore and Atari readers how to do this, owners of other machines have been asking for equivalent routines. Here are two routines for the Apple II (DOS 3.3 and ProDOS); we've thrown in an IBM PC/PCjr routine for good measure. The Apple II DOS 3.3 routine is listed first.
10 INPUT "FILENAME : "; N$ 20 P$ = CHR$ (4) : POKE 42954, 0 30 PRINT P$; "OPEN" ;N$ 40 T = PEEK (46530) : IF T < > 132 AND T < > 4 THEN PRINT "ERROR: "N$" IS NOT A BINARY FILE" : GOTO 90 50 PRINT P$; "READ";N$ 60 SET A$, B$, C$, D$ : PRINT P$ 70 PRINT "ADDRESS:"; ASC (A$) + 256 * ASC (B$) 80 PRINT "LENGTH:"; ASC (C$) + 256 * ASC (D$) 90 PRINT : PRINT P$;"CLOSE"; N$ 100 POKE 42954, 127
Here is an equivalent routine for Apple II machines running ProDOS:
10 D$ = CHR$ (4) : INPUT "FILE NAME: ";N$ 20 IF LEN (N$) < 15 THEN N$ = N$ + " " : GOTO 15 30 PRINT D$; "PREFIX" 40 INPUT PN$ 50 PRINT D$; "OPEN"; PN$ ;",TDIR" 60 PRINT D$; "READ"; PN$ 70 INPUT F$ : IF MID$ (F$, 2, 15) < > N$ THEN 70 80 PRINT D$; "CLOSE "; PN$ 90 IF MID$ (F$, 18, 3) < > "BIN" THEN PRINT "ERROR : "N$" IS NOT A BINARY FILE" : END 100 D = 0 : H$ = MID$ (F$, 76, 4) : FOR I = 1 TO 4 : H = ASC ( MID$ (F$, 75 + I, 1)) : D = D * 16 + H - 48 - 7 * (H > 57) : NEXT 110 PRINT "ADDRESS:";D 120 PRINT "LENGTH : "; MID$ (F$, 67, 5)
While the ProDOS CATALOG command provides the same information as the second example, this program also demonstrates how to open and read a disk file from BASIC, something that's not immediately apparent to many users. The final example finds starting and ending addresses on the IBM PC/PCjr:
10 INPUT "File name";A$ 20 OPEN A$ FOR INPUT AS #1 30 IF INPUT*(1,1) <> CHR$ (253) THEN PRINT "Error: "A$"is not a binary file" : GOTO 70 40 PRINT : GOSUB 90 : PRINT "Starting segment : ";S 50 GOSUB 90 : PRINT "Starting address : ";S 60 GOSUB 90 : PRINT "File length : ";S 70 CLOSE 1 80 END 90 S = ASC (INPUT$ (1, 1)) + 256 * ASC (INPUT$ (1, 1)) : RETURN