home *** CD-ROM | disk | FTP | other *** search
-
- /* PopInfo v2.0
-
- A Workbench utility to show you the info that Workbench doesn't.
-
- © Copyright 1988 Jonathan Potter
- Placed in the Public Domain (NOT Shareware) and is NOT to be sold for
- profit.. a MAXIMUM of $10 may be charged for a copying fee, etc..
-
- HISTORY:
-
- around mid-September : v1.0 written -
- this was so simple & buggy that it was
- never released..
- 1-October-1988 : v2.0 written -
- a total rewrite took 2 days
- or around 11 hours
-
- COMPILE:
-
- Compiles with Manx Aztec C v3.6a using 32 bit ints with
-
- cc +l -s PopInfo
- as ReadBlock
- ln -o PopInfo +cdb PopInfo.o ReadBlock.o -lc32
-
- BUGS:
-
- none known of.. no doubt there are some....
-
- AUTHOR:
- Jonathan Potter
- 3 William Street
- Clarence Park
- South Australia (a boring place to live)
- Australia 5034 (can't wait to get back to London!!!)
-
- Enjoy the program! And,
-
- I'll see you on the Dark Side of the Moon!!! */
-
-
- /* includes */
- #include <exec/tasks.h>
- #include <exec/memory.h>
- #include <intuition/intuition.h>
- #include <devices/trackdisk.h>
- #include <devices/timer.h>
- #include <libraries/dosextens.h>
-
- /* windows */
- struct NewWindow Credits={
- 235,65,170,73,
- -1,-1,
- NULL,
- SMART_REFRESH|NOCAREREFRESH,
- NULL, NULL,
- NULL,
- NULL, NULL,
- 0,0,0,0,
- WBENCHSCREEN
- };
- struct NewWindow SWindow={
- 0,0,12,10,
- -1,-1,
- ACTIVEWINDOW,
- ACTIVEWINDOW,
- NULL,NULL,
- "P",
- NULL,NULL,
- 0,0,0,0,
- WBENCHSCREEN
- };
- struct NewWindow MWindow={
- 0,0,444,0,
- -1,-1,
- CLOSEWINDOW|INACTIVEWINDOW|MOUSEBUTTONS,
- WINDOWCLOSE|INACTIVEWINDOW|ACTIVATE|NOCAREREFRESH|SMART_REFRESH|RMBTRAP,
- NULL,NULL,
- "PopInfo v2.0",
- NULL,NULL,
- 0,0,0,0,
- WBENCHSCREEN
- };
- struct NewWindow LWindow={
- 0,0,586,170,
- -1,-1,
- NULL,
- ACTIVATE|WINDOWDEPTH|RMBTRAP|NOCAREREFRESH|SMART_REFRESH,
- NULL,NULL,
- "",
- NULL,NULL,
- 0,0,0,0,
- WBENCHSCREEN
- };
-
- /* a few structs */
- struct IntuitionBase *IntuitionBase;
- struct Window *Window, *CWindow;
- struct timerequest Time_Req;
- struct MsgPort *Timer_Port;
- struct Port *diskport;
- struct IOStdReq *diskreq;
- struct IntuiMessage *Msg, *GetMsg();
- struct FileLock *lock, *Lock();
- struct InfoData *data;
- struct DateStamp now;
- struct DosLibrary *DosBase;
- struct DeviceList *devlist;
- struct RootNode *rootnode;
- struct DosInfo *dosinfo;
- struct RastPort *RP;
- struct GfxBase *GfxBase;
-
- /* some strings, etc.. */
- char txt[80], bwn[]="Bootblock of disk in DFx:";
- unsigned char diskbuffer[3*512];
- /* a working bootblock */
- unsigned char bootblock[]={'D','O','S',0,0xc0,0x20,0x0f,0x19,0x00,0x00,0x03,
- 0x70,0x43,0xfa,0x00,0x18,0x4e,0xae,0xff,0xa0,0x4a,0x80,0x67,0x0a,0x20,
- 0x40,0x20,0x68,0x00,0x16,0x70,0x00,0x4e,0x75,0x70,0xff,0x60,0xfa,0x64,
- 0x6f,0x73,0x2e,0x6c,0x69,0x62,0x72,0x61,0x72,0x79,0x00,0x00,0x00,0x00,
- 0x00};
-
- /* intuitext structures... i HATE intuitext */
- struct IntuiText mesg={
- 1,0,JAM1,10,12,(struct TextAttr *) NULL,txt,(struct IntuiText *) NULL };
-
- struct IntuiText vbb2={
- 0,1,JAM2,10,18,(struct TextAttr *) NULL,(UBYTE *)"with non-standard bootblocks?",
- NULL};
- struct IntuiText vbb1={
- 0,1,JAM2,10,8,(struct TextAttr *) NULL,(UBYTE *)"View first two sectors of disk(s)",
- &vbb2};
- struct IntuiText vbbp={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Yup",NULL};
- struct IntuiText vbbn={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Nup",NULL};
-
- struct IntuiText il1={
- 0,1,JAM2,10,8,(struct TextAttr *) NULL,(UBYTE *)"Install this disk?",
- NULL};
- struct IntuiText ilp={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Yup",NULL};
- struct IntuiText iln={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Nup",NULL};
-
- struct IntuiText rus2={
- 0,1,JAM2,10,18,(struct TextAttr *) NULL,(UBYTE *)"to install this disk?",
- NULL};
- struct IntuiText rus1={
- 0,1,JAM2,10,8,(struct TextAttr *) NULL,(UBYTE *)"Are you sure that you want",
- &rus2};
- struct IntuiText rusp={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Yup",NULL};
- struct IntuiText rusn={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Nup",NULL};
-
- struct IntuiText cvb1={
- 0,1,JAM2,10,8,(struct TextAttr *) NULL,(UBYTE *)"Continue viewing bootblocks?",
- NULL};
- struct IntuiText cvbp={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Yup",NULL};
- struct IntuiText cvbn={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Nup",NULL};
-
- struct IntuiText wp2={
- 0,1,JAM2,10,18,(struct TextAttr *) NULL,(UBYTE *)"Try it again?",NULL};
- struct IntuiText wp1={
- 0,1,JAM2,10,8,(struct TextAttr *) NULL,(UBYTE *)"ERROR! Disk is write protected!",
- &wp2};
- struct IntuiText wpp={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Yup",NULL};
- struct IntuiText wpn={
- 0,1,JAM2,7,3,(struct TextAttr *) NULL,"Nup",NULL};
-
- /* start */
- main()
- {
- int oldpri,numdevs,nondos,nodisk,flag,sbbflag,a,b,c,x,y,dnum,sum,lastsum,error;
- int nsbb[4];
- UBYTE devname[4];
- char *bbmess, *status;
- register unsigned int *iptr;
- unsigned int *ptr;
-
- oldpri=SetTaskPri(FindTask(0),18);
-
- OpenAll(); /* open all the libraries, etc.. */
-
- for(;;) { /* infinite */
- waitaround: /* yup.. */
- Wait(1L<<Window->UserPort->mp_SigBit); /* wait for something to happen */
- Msg=GetMsg(Window->UserPort); /* something's happened.. */
- if (Msg->Class==CLOSEWINDOW) { /* say goodbye */
- ReplyMsg(Msg);
- CloseWindow(Window);
- CloseLibrary(IntuitionBase);
- CloseLibrary(DosBase);
- CloseDevice(&Time_Req);
- DeletePort(Timer_Port);
- DeletePort(diskport);
- DeleteStdIO(diskreq);
- SetTaskPri(FindTask(0),oldpri);
- exit(0); /* bye! */
- }
- if (Msg->Class==ACTIVEWINDOW) { /* clicked on small window */
- ReplyMsg(Msg);
- if (Msg->MouseX > 12 || Msg->MouseY > 10) goto waitaround;
- if (flag==1) break;
- flag=1;
- CloseWindow(Window); /* close little window */
- numdevs=countdevices(); /* count number of devices present in */
- if (numdevs>16) numdevs=16; /* system and set medium window */
- MWindow.Height=50+(9*numdevs); /* size accordingly */
- Window=(struct Window *) OpenWindow(&MWindow); /* open medium */
- wprint("Unit Bytes Used Free Ers WPS SBB",0,1);
- wprint("____ _____ ____ ____ ___ ___ ___",0,2);
- y=12;
- Forbid(); /* better to be safe.. */
- rootnode=(struct RootNode *) DosBase->dl_Root;
- dosinfo=(struct DosInfo *) BADDR(rootnode->rn_Info);
- devlist=(struct DeviceList *) BADDR(dosinfo->di_DevInfo);
- while (devlist) { /* scan devicelist */
- if (devlist->dl_Type!=NULL) { /* is right type? */
- devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
- continue;
- }
- conbstr((BPTR) devlist->dl_Name,devname);
- strcat(devname,":");
- if (DLT_DEVICE!=NULL || devlist->dl_Task) {
- iptr[0]=0;
- dnum=-1;
- nodisk=0;
- nondos=0;
- bbmess="N/A";
- status="R/W";
- if (devname[0]==68 && devname[1]==70) dnum=devname[2]-48;
- if (dnum!=-1) { /* device is a DFx: */
- bbmess="Yes";
- error=OpenDevice("trackdisk.device",dnum,diskreq,0);
- diskreq->io_Command=TD_CHANGESTATE; /* disk there? */
- DoIO(diskreq);
- if (diskreq->io_Actual!=0) { /* nup */
- nodisk=1;
- CloseDevice(diskreq);
- goto display; /* aaargh! a goto */
- }
- diskreq->io_Command=TD_PROTSTATUS; /* write */
- DoIO(diskreq); /* protected ? */
- if (diskreq->io_Actual!=0) status="R O"; /* yup */
- error=ReadBlock(); /* read boot block */
- diskreq->io_Command=TD_MOTOR; /* shut motor up */
- diskreq->io_Length=0;
- DoIO(diskreq);
- CloseDevice(diskreq);
- ptr=diskbuffer;
- iptr=diskbuffer;
- if (iptr[0]!=ID_DOS_DISK) { /* a dos disk? */
- nondos=1; /* this includes unformatted disks */
- goto display;
- }
- sum=0;
- for (a=0;a<256;a++) { /* calculate checksum */
- lastsum=sum;
- sum=sum+ptr[a];
- if (lastsum>sum) sum++;
- }
- if (sum!=0) { /* if sum isn't 0, disk isn't */
- nsbb[dnum]=0; /* bootable */
- bbmess="NBB";
- goto display;
- }
- ptr=&diskbuffer[4];
- for (x=0;x<39;x++) {
- if (diskbuffer[8+x]!=bootblock[8+x]) {
- nsbb[dnum]=5; /* disk has a non standard */
- sbbflag=1; /* bootblock.. virus? or just a */
- bbmess="No"; /* special bootblock.. */
- }
- }
- }
- display:
- dnum=0;
- if (nodisk!=1 && nondos!=1) { /* dos disk present */
- lock=Lock(devname,ACCESS_READ);
- Info(lock,data);
- sprintf(txt,"%-4s %-9ld %-9ld %-9ld %-3ld %-3s %-3s",
- devname,
- data->id_BytesPerBlock*data->id_NumBlocks,
- data->id_BytesPerBlock*data->id_NumBlocksUsed,
- (data->id_BytesPerBlock*data->id_NumBlocks)-
- (data->id_BytesPerBlock*data->id_NumBlocksUsed),
- data->id_NumSoftErrors,
- status,
- bbmess);
- PrintIText(Window->RPort,&mesg,0,y);
- y+=9;
- UnLock(lock);
- }
- else if (nodisk==1) { /* no disk there */
- sprintf(txt,"%-4s No disk present in drive.", devname);
- PrintIText(Window->RPort,&mesg,0,y);
- y+=9;
- nodisk=0;
- }
- else if (nondos==1) { /* not a dos disk */
- sprintf(txt,"%-4s Not a DOS disk.", devname);
- PrintIText(Window->RPort,&mesg,0,y);
- y+=9;
- nondos=0;
- }
- }
- devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
- }
- Permit(); /* phew */
- y+=5;
- sprintf(txt,"FREE MEMORY FAST:%-7ld CHIP:%-6ld TOTAL:%-7ld",
- (AvailMem(MEMF_FAST) >> 10) * 1024,
- (AvailMem(MEMF_CHIP) >> 10) * 1024,
- ((AvailMem(MEMF_FAST) >> 10) * 1024) +
- ((AvailMem(MEMF_CHIP) >> 10) *1024));
- PrintIText(Window->RPort,&mesg,0,y);
- DateStamp(&now);
- sprintf(txt," TIME %02d:%02d:%02d",
- now.ds_Minute/60, now.ds_Minute%60,
- now.ds_Tick/TICKS_PER_SECOND);
- PrintIText(Window->RPort,&mesg,0,y+9);
- Time_Req.tr_time.tv_secs=0;
- Time_Req.tr_time.tv_micro=250000;
- SendIO((char *) &Time_Req.tr_node);
- if (sbbflag==1) { /* non standard bootblock */
- sbbflag=0; /* wanna view it (them) ? */
- error=AutoRequest(Window, &vbb1, &vbbp, &vbbn, 0,0,320,70);
- if (error!=TRUE) goto lbandf; /* nup */
- CloseWindow(Window); /* yup */
- for (c=0;c<4;c++) { /* go through df's 0 to 3 */
- if (nsbb[c]==5) { /* if 5, has non standard bootblock */
- nsbb[c]=0;
- Window=(struct Window *) OpenWindow(&LWindow);
- bwn[23]=c+48; /* set the window title */
- SetWindowTitles(Window, bwn, -1);
- RP=Window->RPort;
- error=OpenDevice("trackdisk.device",c,diskreq,0);
- error=ReadBlock(); /* read the bootblock again */
- diskreq->io_Command=TD_MOTOR;
- diskreq->io_Length=0;
- DoIO(diskreq); /* shut motor up */
- CloseDevice(diskreq);
- SetAPen(RP,3);
- Move(RP, 14+(12*8), 165);
- Text(RP, "Block 0", 7);
- Move(RP, 324+(12*8), 165);
- Text(RP, "Block 1", 7);
- SetAPen(RP, 1);
- x=0; y=0;
- SetAPen(RP,1);
- SetDrMd(RP,JAM2);
- for (a=0;a<512;a=a+32) { /* display the bootblock */
- Move(RP,10+(x*8),20+(y*9));
- Text(RP,&diskbuffer[a],32);
- Move(RP,320+(x*8),20+(y*9));
- Text(RP,&diskbuffer[a+512],32);
- y++;
- }
- error=AutoRequest(Window,&il1,&ilp,&iln,0,0,320,70);
- if (error==TRUE) { /* yep! install it */
- error=AutoRequest(Window,&rus1,&rusp,&rusn,0,0,320,70);
- if (error!=TRUE) goto forgetit; /* no thanks */
- error=OpenDevice("trackdisk.device",c,diskreq,0);
- tryagain:
- diskreq->io_Command=TD_PROTSTATUS;
- DoIO(diskreq);
- if (diskreq->io_Actual != 0) { /* write protected */
- error=AutoRequest(Window,&wp1,&wpp,&wpn,0,0,320,70);
- if (error==TRUE) goto tryagain; /* try again */
- CloseDevice(diskreq);
- goto forgetit; /* forget it! */
- }
- for (x=0;x<1024;x++) /* write bootblock to disk */
- diskbuffer[x]=0;
- CopyMem(bootblock,diskbuffer,50);
- diskreq->io_Length=1024;
- diskreq->io_Data=&diskbuffer[0];
- diskreq->io_Command=CMD_WRITE;
- diskreq->io_Offset=0L;
- DoIO(diskreq);
- diskreq->io_Command=CMD_UPDATE;
- DoIO(diskreq);
- diskreq->io_Length=0; /* once again.. shut the */
- diskreq->io_Command=TD_MOTOR; /* bloody motor up */
- DoIO(diskreq);
- }
- forgetit: /* view rest of bootblocks? (if any) */
- error=AutoRequest(Window,&cvb1,&cvbp,&cvbn,0,0,320,70);
- CloseWindow(Window);
- if (error!=TRUE) { /* no thanks */
- Window=(struct Window *) OpenWindow(&SWindow);
- flag=0;
- goto waitaround;
- }
- }
- }
- Window=(struct Window *) OpenWindow(&SWindow);
- flag=0;
- goto waitaround;
- lbandf: /* this stops IDCMP sending an inactivewindow */
- Msg=GetMsg(Window->UserPort); /* just because we clicked */
- if (Msg->Class!=INACTIVEWINDOW) goto lbandf; /* on the */
- lbandf2: /* requester box... */
- Msg=GetMsg(Window->UserPort);
- if (Msg->Class==INACTIVEWINDOW) {
- ReplyMsg(Msg);
- goto waitaround;
- }
- goto lbandf2;
- }
- }
- if (Msg->Class==INACTIVEWINDOW) { /* clicked outside window */
- ReplyMsg(Msg);
- if (flag=0) break;
-
- flag=0;
- CloseWindow(Window); /* bye bye medium */
- Window=(struct Window *) OpenWindow(&SWindow); /* hello small */
- }
- if (Msg->Class==MOUSEBUTTONS && Msg->Code==MENUDOWN) {
- /* right mouse button */
- ReplyMsg(Msg);
- CWindow=(struct Window *) OpenWindow(&Credits); /* open credits */
- sprintf(txt,"PopInfo v2.0");
- PrintIText(CWindow->RPort,&mesg,27,1);
- sprintf(txt,"© Copyright 1988");
- PrintIText(CWindow->RPort,&mesg,11,10);
- sprintf(txt,"Jonathan Potter");
- PrintIText(CWindow->RPort,&mesg,15,20);
- sprintf(txt,"PUBLIC DOMAIN 1988");
- PrintIText(CWindow->RPort,&mesg,3,40);
- for (;;) { /* wait until menu button released */
- Msg=GetMsg(Window->UserPort);
- if (Msg->Code==MENUUP)
- break;
- }
- CloseWindow(CWindow); /* close credits window */
- }
- goto waitaround;
- }
- }
-
- OpenAll() /* open all the libraries */
- {
- IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
- Window=(struct Window *) OpenWindow(&SWindow); /* open window */
- if (Window==NULL) { /* not enough memory for window */
- DeletePort(diskport);
- DeleteStdIO(diskreq);
- CloseLibrary(IntuitionBase);
- exit(0);
- }
- DosBase=(struct DosLibrary *) OpenLibrary(DOSNAME,0L);
- diskport=CreatePort(0,0);
- diskreq=CreateStdIO(diskport);
- GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",0);
- Timer_Port=CreatePort("Timer Port",0);
- OpenDevice(TIMERNAME,UNIT_VBLANK, (char *) &Time_Req,0);
- lock=(struct FileLock *) AllocMem(sizeof(struct FileLock),MEMF_CHIP|MEMF_CLEAR);
- data=(struct InfoData *) AllocMem(sizeof(struct InfoData),MEMF_CHIP|MEMF_CLEAR);
- Time_Req.tr_node.io_Message.mn_ReplyPort=Timer_Port;
- Time_Req.tr_node.io_Command=TR_ADDREQUEST;
- Time_Req.tr_node.io_Flags=0;
- Time_Req.tr_node.io_Error=0;
- }
-
- wprint(string,x,y) /* a simple intuitext print routine */
- char *string;
- int x,y;
- {
- sprintf(txt,string);
- PrintIText(Window->RPort,&mesg,x,y);
- }
-
- conbstr(bp,buf) /* convert a bstr to char */
- BSTR bp;
- char *buf;
- {
- register UBYTE *cp;
- register int len,i;
- cp=(UBYTE *) BADDR(bp);
- len=(int) *(cp++);
- len=(len>20)?20:len;
- for (i=0;i<len;i++) buf[i]=*(cp++);
- buf[i]='\0';
- }
-
- countdevices() /* count devices in system */
- {
- int devices;
- devices=0;
- Forbid(); /* afraid so */
- rootnode=(struct RootNode *) DosBase->dl_Root;
- dosinfo=(struct DosInfo *) BADDR(rootnode->rn_Info);
- devlist=(struct DeviceList *) BADDR(dosinfo->di_DevInfo);
- while (devlist) {
- if (devlist->dl_Type!=NULL) {
- devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
- continue;
- }
- if (DLT_DEVICE!=NULL || devlist->dl_Task) ++devices;
- devlist=(struct DeviceList *) BADDR(devlist->dl_Next);
- }
- Permit(); /* wop */
- return(devices);
- }
-
-