[comp.sys.cbm] 1581 hacking

fred@cbmvax.UUCP (Fred Bowen) (11/12/87)

Let me kill two, no, three birds with one posting.  First, here's an example
of an autobooting 1581 file (something different than an autoboot c128 disk).
Lots of folks are having a tough time figuring out how to do them correctly.
Second, the example given will change the step rate of the drive temporarily,
kinda like soft setting the device number.  Depending upon the guts of your
drive, this might be a Good Thing or a Bad Thing.  Third, it can tell you
indirectly whether the 1581 has a WD1770 or a WD1772 in it.   Interested?

Please refer to the 1581 User's Guide.  Look up Utility Loader and Auto
Boot Loader (pages 87-88 in my book).  If you use the Sector Editor from the
1581 Test/Demo disk to look at my file, you would see something like this:

		00  ->	00 15 00 05 10 A2 05 A9
		08  ->	03 1D DA 01 9D DA 01 CA
		10  ->	10 F5 4C 5A FF 53

where
	00 15	is the next track, sector  (in this case, no next track
		and pointing to the last valid character in this sector).
		These two bytes are necessary in all DOS files.  Auto Boot
		files can be only 1 sector in size.

	00 05	is where you want your utility to load in DOS memory. (Here,
		we'll use buffer #2 which is located at $0500).

	10	is the number of bytes in the program.  (16 in this case, you
		can count them below...)

and then the program

	A2 05		LDX #5
	A9 03		LDA #3
	1D DA 01	ORA $01DA,X	;WDvars
	9D DA 01	STA $01DA,X
	CA		DEX
	10 F5		BPL *-11
	4C 5A FF	JMP $FF5A	;CBMBOOTRTN

and finally

	53	is the 8-bit checksum (including all carries) of everything
		above EXCEPT the first two bytes ($00 $15).

This should be the contents of a file named "COPYRIGHT CBM 86".  It does not
matter if it is a USR type file.  PRG is okay and a little bit easier to
play with, actually.  Here's a quick way to create the file without messing
with the Sector Editor, assuming you are using the 80-column screen:

	1. Enter the ML monitor (if you don't know how, best not try this).
	2. Starting at $0500 (convenient- same address as the disk buffer
	   the program will be executing from!), enter the data starting
	   with the number of bytes ($10 above) to the checksum ($53 above).
	   This should put you at address $511.
	3. Now simply save this to disk- be sure to enter the starting and
	   ending addresses, and the filename, exactly:

		       S"COPYRIGHT CBM 86",8,0500,0512

That's it- you now have a DOS autoboot file.  To execute it, stick the disk
into the drive and either turn the drive off & on, or type DCLEAR.  The
program is loaded by the DOS and executed- in this case slightly modifying
the sundry commands the DOS issues to the drive controller by changing the
step rate.  The following BASIC script simply moves the head from track 1
to track 80.  Try running it on a drive with and without the above patches
and just listen to the difference:

OPEN1,8,15: OPEN2,8,2,"#": PRINT#1,"U1";2;0;1;0: PRINT#1,"U1";2;0;80;0: DCLOSE

What you hear is one of two things.  If your drive has a WD1770 controller in
her, she'll sound  s l o w  because this patch just gave you a 30ms step rate.
If your drive has a WD1772 controller in her, she'll sound much faster because
this same patch just gave her a 3ms step rate.  Normally, the 1581 will have
either a 6ms or a 12ms step rate, depending upon the jumper at J1  (it should
be shorted for a 6ms step rate).   If you ran the script and could not hear
any difference, you probably messed up entering the program and it did not
autoboot.  Get out the Sector Editor, find & fix what's wrong, and try again.

Now, I recommend a maximum step rate of 6ms.  But it's your data.  Unless you
are running something that is beating the hell out of the disk all day long,
you really are not gonna see much savings- it takes alot of track changes,
saving 3ms each, to save even 1 lousy second.  But it was fun...  I leave the
reader with the task of writing a program based upon what you have learned
here to report (A) what controller is present and (B) the state of the jumper
at J1 (no fair peeking! :-)   Extra credit if the program can be run without
anything but a 1581 and a diskette (i.e., no computer).

--
-- 
Fred Bowen			uucp:	{ihnp4|rutgers|caip}!cbmvax!fred
				arpa:	cbmvax!fred@RUTGERS.EDU
				tele:	215 431-9100

Commodore Electronics, Ltd.,  1200 Wilson Drive,  West Chester,  PA,  19380