Login
Search for:


Previous | Next

From: Marko_Mäkelä
Date: 2002-03-04
Subject: Re: C16 + 4 opcode list
Grósz Attila wrote:
> Well, I am not Marko, maybe he won't be angry if I answer
> this question: the PRG files do not at all have a header.

No, I won't be angry. :-) But I'd say that the LOAD and SAVE commands use a two-byte header in the sequentially arranged files they can process. (Nothing prevents you from using e.g. SEQ or USR files for programs, just type SAVE"PROGRAM,S",8 or LOAD"PROGRAM,S",8.)

The two first bytes of program files specify the loading address, least significant byte first. On the C64, they're usually $01 $08, meaning
$0801. On the plus/4, I don't remember where BASIC programs start, but it's probably $1001 or $1801 or something like that.

Usually programs have an additional BASIC language header, typically consisting of a SYS statement, and optionally a comment. In the BASIC header (directly following the loading address), the first 16-bit word
(2 bytes, little endian) is the link to the next BASIC program line (0
at end of program), and the second word is the line number, very often the year when the program was published. Then comes the SYS token, $9e,
followed by the PETSCII of the start address, and optionally some garbage that is terminated with a zero byte. On the C64, 0SYS2061 would be $01 $08 $xx $xx $00 $00 $9e $32 $30 $36 $31 $00 $00 $00, and the machine language (at $080d) would follow the three zero bytes that mark the end of BASIC program.

Attila, you said that you wrote the disassembler. Are you familiar with d65, which I wrote in 1993 but never really finished? It tries to detect data blocks reliably by conducting a reachability analysis of the program flow, banning nonsensial code. Also, it knows several 6502
"dialects". If you specify an instruction set that has no undocumented opcodes, it will detect such codes as data.

Marko

Copyright © Plus/4 World Team, 2001-2024