1571-10.TXT rev 1a 96-11-06 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * THIS DOCUMENT IS COPYRIGHT (C) 1988, 1996 BY HERNE DATA SYSTEMS LTD. THE MATERIAL CONTAINED HEREIN MAY BE FREELY USED FOR PERSONAL INFORMATION ONLY. IF YOU REPRODUCE IT, THIS COPYRIGHT NOTICE MUST NOT BE REMOVED. THIS MATERIAL MAY NOT BE EXPLOITED FOR COMMERCIAL PURPOSES. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Herne Data Systems Ltd., PO Box 250, Tiverton, ON N0G 2T0 CANADA. Voice/fax 519-366-2732, e-mail herne@herne.com, internet: http://www.herne.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * AUTO BOOTING on the C-128 with a 1541 or 1571 Drive The C-128 has the ability to automatically load and run either a machine language or BASIC program from disk when it is first turned on or the reset button is pressed. In this process, known as AUTOBOOTING, the computer loads track 1, sector 0 into memory at address 2186 in bank 0 (part of the BASIC stack area) and checks it for a certain combination of bytes. If the byte pattern is matched, the machine language instructions in the remainder of the sector are executed. This feature works with both the 1571 and 1541 disk drives, as well as with most other compatible Commodore and non-Commodore drives. For AutoBooting, the first three bytes of track 1, sector 0 must be the characters "CBM" followed by four CHR$(0)s. This can be followed by an optional message to be displayed during boot-up of up to 16 characters. The message is followed by two more CHR$(0)s. This sequence is followed by some machine language instructions and a BASIC command string consisting of either RUN"filename" or BOOT"filename" for BASIC or macine language programs, respectively. The final byte is another CHR$(0). The machine language instructions are: LDX #address low LDY #address high JMP AEA5 where address low and address high are the low and high bytes of the beginning of the RUN or BOOT string that follows. This address may change depending on the length of the boot message string. The JMP instruction goes to the area of ROM for handling BASIC commands. Listing one, AUTOBOOT MAKER is a short BASIC 7 program which allows you to write the required byte pattern to make a boot disk. One word of caution, however. Since the program uses the random disk block write method to write the boot sector, the boot disk should not be subjected to the DOS VALIDATE or BASIC 7 COLLECT command. Either of these commands may cuase the boot sector to be overwritten and in any case will cause it to become un-allocated. AUTOBOOT MAKER will warn you if it finds track 1, sector 0 already allocated. If you get such a message, you can either overwrite the existing sector or try another disk. If the disk already has a boot sector written, the old data will be replaced by the new. In any event, it is perhaps better to write a boot sector on a new disk immediately after formatting it. This ensures that the sector does not have any valid data on it. Interestingly, the BASIC command string used in the boot sector is not limited to BOOT"filename" or RUN"filename", but can be any valid immediate mode BASIC command. By changing lines 70 and 80 of the program to contain the appropriate command string such as: 70 BO$=BO$+"DIRECTORY"+CHR$(0) you could have an automatic display of the disk directory on boot up. Other useful applications include DLOADing a program (without running it); BLOADing a machine language utility, sprite data, function key definitions, custom title screen, etc.; or perhaps merely changing the screen colors with a couple of COLOR commands. The only apparent restriction on the command string is that its total length must be less than one BASIC line and must contain only one logical line (i.e. no CHR$(13)s). All statements must be immediate mode (i.e. INPUT, GET etc. are not allowed). Of course, most of the above applications (except for the DLOAD) can be performed by a RUN"filename" type command string. However, while these programs are easily accessible to prying eyes from the disk directory, a person needs a disk sector editor to view or change the contents of a custom boot sector command string. LISTING One: 10 BO$="CBM":C0$=CHR$(0):FORI=1TO4:BO$=BO$+C0$:NEXT:COLOR0,7:COLOR4,7:PRINT" " 20 PRINT"BOOT MESSAGE":INPUT" MAX 16 CHARS";ME$:ME$=LEFT$(ME$,16): SA=2831+LEN(ME$) 30 INPUT" BOOT FILE NAME";BF$:INPUT" {B}ASIC OR {M}ACH. LANG.";FT$:PRINT" " 40 PRINT" BOOT MESSAGE: "ME$:PRINT" BOOT FILE NAME: "BF$;: IFFT$="M"THENPRINT" MACH. LANG.":ELSEPRINT" BASIC" 50 INPUT" OK {Y/N}";O$:IFO$<>"Y"THEN10 60 BO$=BO$+ME$+C0$+C0$+CHR$(162)+CHR$(SA AND255)+CHR$(160)+ CHR$(SA/256)+CHR$(76)+CHR$(165)+CHR$(175) 70 IFFT$="M"THENBO$=BO$+"BOOT":ELSEBO$=BO$+"RUN" 80 BO$=BO$+CHR$(34)+BF$+CHR$(0):OPEN15,8,15:OPEN8,8,8,"#":IFDSTHENDCLOSE:GOTO110 90 PRINT#15,"U1:";8;0;1;0:PRINT#15,"B-A:";0;1;0:IFDS=65THEN120 100 PRINT#15,"B-P:";8;0:PRINT#8,BO$;:PRINT#15,"U2:";8;0;1;0:DCLOSE: IFDSTHEN110:ELSEEND 110 PRINT" DISK ERROR >> ";DS$:GOTO40 120 PRINT" BOOT SECTOR ALREADY IN USE":INPUT" OVER-WRITE {Y/N}";OW$: IFOW$="Y"THEN100:ELSE40