[comp.sources.amiga] v02i039: noklickstart - stop some empty A1000 drives from klicking v1.3

page@swan.ulowell.edu (Bob Page) (11/02/88)

Submitted-by: page@swan.ulowell.edu (Bob Page)
Posting-number: Volume 2, Issue 39
Archive-name: kernel/noklick13.1

[I goofed - forgot to flush the track buffer.  See text in comp.sys.amiga.
If you have the original, don't use it, use this version.  Sorry!  ..Bob]

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#	Run the following text with /bin/sh to create:
#	noklick.c
# This archive created: Wed Nov  2 00:20:46 1988
cat << \SHAR_EOF > noklick.c
/* noKlickStart for 1.3 - version 2! */
/* Bob Page - Nov 1 1988 */

/* the first version didn't flush the track buffer ... mea culpa. */

/* thanks to Bryce Nesbitt for writing noKlickStart for 1.2 */

#include <exec/memory.h>
#include <devices/trackdisk.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <stdio.h>

struct MsgPort *diskport = NULL;        /* Port for trackdisk replies */
struct MsgPort *CreatePort();
struct IOExtTD *diskreq = NULL;         /* Pointer for extended disk commands */
struct IORequest *CreateExtIO();
void   *AllocMem();
ULONG  *buf;

#ifdef AZTEC_C
_cli_parse() {}
_wb_parse() {}
#endif

main()
{
    char s[2];

    puts("noKLICKstart V1.3");
    puts("Use this on a backup of your V1.3 Kickstart disk.\n");
    puts("Insert Kickstart into drive DF0:.  Type y then RETURN");
    fputs("to continue, or just RETURN to abort. ->  ", stdout);

    gets(s);
    if (s[0] != 'y') exit(10);

    diskport = CreatePort(0L,0L);
    diskreq = (struct IOExtTD *) CreateExtIO(diskport,sizeof(struct IOExtTD));
    OpenDevice("trackdisk.device", 0L, diskreq, 0L);
    buf = (ULONG *) AllocMem(512L, MEMF_CHIP);

    diskreq->iotd_Req.io_Length = 0L;
    diskreq->iotd_Req.io_Command = TD_PROTSTATUS;
    diskreq->iotd_Req.io_Offset = 0L;
    DoIO(diskreq);
    if(diskreq->iotd_Req.io_Actual) {
	puts("noKLICKstart failed.  Perhaps your disk is write protected?");
	leave(10);
    }

    if ((GetBlock(512L, buf))) {
	puts("\nnoKLICKstart failed.  Couldn't read the disk.");
	leave(10);
    }

    if(buf[122] != 0x15267db3) WrongVer(1);
    buf[122] = 0x14a67db3;
    PutBlock(512L, buf);

    GetBlock(332L, buf);
    if(buf[26] != 0x086b0001) {		/* BCHG */
	WrongVer(0);
	GetBlock(512L, buf);
	buf[122] =  0x15267db3;		/* restore checksum */
	PutBlock(512L, buf);
	leave(10);
    }
    buf[26] = 0x08eb0001;		/* BSET */
    PutBlock(332L, buf);

    diskreq->iotd_Req.io_Command = CMD_UPDATE;
    DoIO(diskreq);			/* flush the track buffer */

    puts("\nnoKLICKstart installed.  Please perform a cold boot now.\n");
    leave(0);
}


GetBlock(num, diskbuf)
ULONG num;
ULONG *diskbuf;
{
    diskreq->iotd_Req.io_Length = 512L;
    diskreq->iotd_Req.io_Data = (APTR) diskbuf;
    diskreq->iotd_Req.io_Command = CMD_READ;
    diskreq->iotd_Req.io_Offset = num*512L;
    return(DoIO(diskreq));
}


PutBlock(num, diskbuf)
ULONG num;
ULONG *diskbuf;
{
    diskreq->iotd_Req.io_Length = 512L;
    diskreq->iotd_Req.io_Data = (APTR) diskbuf;
    diskreq->iotd_Req.io_Command = CMD_WRITE;
    diskreq->iotd_Req.io_Offset = num*512L;
    return(DoIO(diskreq));
}


leave(n)
int n;
{
    diskreq->iotd_Req.io_Length = 0L;
    diskreq->iotd_Req.io_Command = TD_MOTOR;
    DoIO(diskreq);
    FreeMem(buf, 512L);
    CloseDevice(diskreq);
    DeleteExtIO(diskreq, sizeof(struct IOExtTD));
    DeletePort(diskport);

    exit(n);
}


WrongVer(f)
int f;
{
puts("\nYou can't fool me! :-)  That's not an unmodified V1.3 (34.5) Kickstart!!");
if (f) leave(10);
}
SHAR_EOF
#	End of shell archive
exit 0
-- 
Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
Have five nice days.