Classic Computer Magazine Archive COMPUTE! ISSUE 64 / SEPTEMBER 1985 / PAGE 10

 
Readers Feedback

 The Editors and Readers of COMPUTE!



Commodore ML Addresses
I own a Commodore 64. How can I find the beginning and ending addresses of a machine language program stored on disk?
Eric Adams

The following program does the job on any Commodore computer with a disk drive (except the 128 in CP/M mode). The first two bytes of a disk program file contain the load address in low byte/high byte format. This program finds the beginning, then reads to the end of the file. The end address equals the start address plus the number of bytes read. (Of course, a disk data file-which holds data rather than a program-has no load address.)

1 INPUT"FILENAME";F$:A$="0:"+F
  $+",P,R":OPEN 2,8,2,A$
2 GET#2,A$:GOSUB 5:L=A:GET#2,A
  $:GOSUB 5:SA=L+256*A:PRINT"S
  TART";SA
3 GET#2,A$:IF ST=0 THEN SA=SA+
  1:GOTO 3
4 PRINT"END";SA: CLOSE 2:END
5 IF A$="" THEN A$=CHR$(0)
6 A=ASC(A$):RETURN

    Tape users can find beginning and ending addresses with only two program lines. The following routine runs as listed on the Commodore 64, VIC-20, and PET. Plus/4 and 16 users should subtract 10 from the four addresses in line 2 (replace 829 with 819, 830 with 820, and so on). Commodore 128 users (in 128 mode) should replace the same four addresses with 2817, 2818, 2819, and 2820. The header data stored at the beginning of a tape file contains the program's starting and ending addresses. The method shown here simply OPENS the file to read the header into the tape buffer, then PEEKS the addresses from the buffer.

1 INPUT"FILENAME";F$:OPEN 2,1,
  0,A$:CLOSE 2
2 PRINT"START";PEEK(829)+256*P
  EEK(830);CHR$(13);"END";PEEK
  (831)+256*PEEK(832)