__stkargs int setup_timer(LONG unit, struct timerequest ** tr) { struct MsgPort *timerport; struct timerequest *req; if (*tr) return 1; if (!(timerport = (struct MsgPort *) CreatePort(0L, 0L))) { *tr = NULL; printf("setup_timer: could not create port\n"); return 0; } if (!(req = (struct timerequest *) CreateExtIO(timerport ,sizeof(struct timerequest)) )) { DeletePort(timerport); *tr = NULL; printf("setup_timer: could not get request\n"); return 0; } if (OpenDevice(TIMERNAME, unit, (struct IORequest *) req, 0L)) { CloseDevice((struct IORequest *) req); DeleteExtIO((struct IORequest *) req); DeletePort(timerport); printf("setup_timer: could not open timer\n"); *tr = NULL; return 0; } *tr = req; return 1; }
/* functions */ void cleanup_narrator() { if (wmes) CloseDevice(wmes); if (WPort) DeletePort(WPort); if (RPort) DeletePort(RPort); if (wmes) DeleteExtIO(wmes); if (rmes) DeleteExtIO(rmes); }
void cleanup() { if(OpenedConsole) CloseConsole(writeReq); if(readReq) DeleteExtIO(readReq); if(readPort) DeletePort(readPort); if(writeReq) DeleteExtIO(writeReq); if(writePort) DeletePort(writePort); if(win) CloseWindow(win); if(IntuitionBase) CloseLibrary(IntuitionBase); }
void UnInitialize() { DelDevice(); if (PktPort) { DeletePort(PktPort); PktPort = NULL; } if (AuxPort) { DeletePort(AuxPort); AuxPort = NULL; } }
main() { ulong i; Enable_Abort = 0; td_mp = CreatePort(0L,0L); if(!td_mp) exit(99); td_iob = CreateStdIO(td_mp); if(!td_iob) { DeletePort(td_mp); exit(99); } if(OpenDevice("trackdisk.device",0L,td_iob,0L)) { printf("Unable to open floppy device driver.\n"); DeleteStdIO(td_iob); DeletePort(td_mp); exit(99); } diskbuf = AllocMem(TD_BUFSIZE,MEMF_PUBLIC|MEMF_CHIP); if(!diskbuf) { printf("Unable to obtain %ld byte buffer in chip memory.\n",TD_BUFSIZE); CloseDevice(td_iob); DeleteStdIO(td_iob); DeletePort(td_mp); exit(99); } for(i=0;i<80;i+=NUMTRKS) { printf("Reading tracks %ld to %ld.\n",i,i+NUMTRKS-1); td_iob->io_Command = CMD_READ; td_iob->io_Data = (APTR) diskbuf; td_iob->io_Length = TD_BUFSIZE; td_iob->io_Offset = 11L * 1024L * i; DoIO(td_iob); if(td_iob->io_Error) { printf("Floppy read failed, error number %d.\n",td_iob->io_Error); break; } } td_iob->io_Command = TD_MOTOR; td_iob->io_Length = 0; DoIO(td_iob); FreeMem(diskbuf,TD_BUFSIZE); CloseDevice(td_iob); DeleteStdIO(td_iob); DeletePort(td_mp); }
__stkargs void cleanup_timer(struct timerequest ** tr) { struct MsgPort *tp; struct timerequest *tmp; UBYTE pFlags; if (*tr) { tmp = *tr; tp = tmp->tr_node.io_Message.mn_ReplyPort; if (tp) { /* abort the current request */ pFlags = tp->mp_Flags; /* still needed for DeletePort */ tp->mp_Flags = PA_IGNORE; AbortIO((struct IORequest *) tmp); WaitIO((struct IORequest *) tmp); while (GetMsg(tp)); Forbid(); tp->mp_Flags = pFlags; DeletePort(tp); Permit(); } CloseDevice((struct IORequest *) tmp); DeleteExtIO((struct IORequest *) tmp); } *tr = NULL; }
VOID __saveds PingFunc( VOID ) { struct MsgPort *ClientPort, *ReplyPort; struct Library *SysBase; BlankMsg PingMsg; SysBase = *( struct Library ** )4L; if( ReplyPort = CreateMsgPort()) { PingMsg.bm_Mess.mn_ReplyPort = ReplyPort; PingMsg.bm_Mess.mn_Length = sizeof( BlankMsg ); PingMsg.bm_Type = BM_PING; /* Stealthimania, to alleviate processing at the blanker */ PingMsg.bm_Mess.mn_Node.ln_Name = ( UBYTE * )( &Blanking ); for( ;; ) { if( SetSignal( 0L, SIGBREAKF_CTRL_C ) & SIGBREAKF_CTRL_C ) break; if( ClientPort = FindPort( "GarshneClient" )) { PingMsg.bm_Flags = 0L; PutMsg( ClientPort, ( struct Message * )( &PingMsg )); WaitPort( ReplyPort ); GetMsg( ReplyPort ); } } DeletePort( ReplyPort ); } }
void rexx_exit (void) { if (ARexxPort) { struct RexxMsg *msg; gui_rexx_s *gui = &gui_rexx[ON_EXIT]; if (gui->port[0] && gui->cmd_on[0]) { if (ADDRESS(gui->port, gui->cmd_on) != RC_OK) { write_log ("%s:%s:%s\n", gui->port, gui->cmd_on, RESULT); } gui->port[0] = '\0'; } Forbid (); while ((msg = (struct RexxMsg*)GetMsg (ARexxPort))) { msg->rm_Result1 = RC_ERROR; msg->rm_Result2 = 0; ReplyMsg ((void*)msg); } DeletePort (ARexxPort); Permit (); ARexxPort = NULL; } #ifdef __amigaos4__ if (IRexxSys) { DropInterface ((struct Interface *)IRexxSys); IRexxSys = NULL; } #endif if (RexxSysBase) { CloseLibrary ((void*)RexxSysBase); RexxSysBase = NULL; } }
struct timerequest *create_timer ( ULONG unit ) { /* return a pointer to a timer request. If any problem, return NULL */ LONG error; struct MsgPort *timerport; struct timerequest *TimerIO; timerport = ( struct MsgPort * ) CreatePort ( 0, 0 ); if ( timerport == NULL ) return ( NULL ); TimerIO = ( struct timerequest * ) CreateExtIO ( timerport, sizeof ( struct timerequest ) ); if ( TimerIO == NULL ) { DeletePort ( timerport ); /* Delete message port */ return ( NULL ); } error = OpenDevice ( TIMERNAME, unit, ( struct IORequest * ) TimerIO, 0L ); if ( error != 0 ) { delete_timer ( TimerIO ); return ( NULL ); } return ( TimerIO ); }
int cw_device_close(void) { unsigned int i; /* mute all sids */ memset(sidbuf, 0, sizeof(sidbuf)); for (i = 0; i < sizeof(sidbuf); i++) { write_sid(i, 0, i / 0x20); } for (i = 0; i < 2; i++) { if (gCatweaselReq[i]) { CloseDevice((struct IORequest *)gCatweaselReq[i]); if (gCatweaselReq[i] != NULL) { DeleteExtIO((struct IORequest *)gCatweaselReq[i]); } if (gDiskPort[i] != NULL) { DeletePort(gDiskPort[i]); } gCatweaselReq[i] = NULL; gDiskPort[i] = NULL; } } log_message(LOG_DEFAULT, "CatWeasel Device: closed"); return 0; }
void stop_noise(void) { AbortIO(&(audioreq->ioa_Request)); FreeMem(chipnoisedata, sizeof(noisedata) ); CloseDevice(&(audioreq->ioa_Request)); DeleteExtIO(&(audioreq->ioa_Request), sizeof(*audioreq)*2); DeletePort(nport); }
/** Close The AREXX port and library pointer **/ exit_t closeRexxLibPort() { if (port != NULL) { DeletePort(port); } CloseLibrary(RexxSysBase); return EXIT_SUCCESS; }
static void gettimeofday_shutdown(void) { if (TimerIO) { CloseDevice(TimerIO); DeleteExtIO(TimerIO); } if (TimerMP) { DeletePort(TimerMP); } TimerBase = NULL; }
void delete_timer(struct timerequest *tr) { struct MsgPort *tp; if (tr != 0) { tp = tr->tr_node.io_Message.mn_ReplyPort; if (tp != 0) { DeletePort(tp); } CloseDevice((struct IORequest *) tr); DeleteExtIO((struct IORequest *) tr); } }
void cleanup(int exitCode,char *errorMsg) { if(rexxport) { RegisterARexxFunctionHost(FALSE); DeletePort(rexxport); } if(NiKomBase) { InitServermem(NULL); /* Stänger av nikom.library */ } if(Servermem) { if(exitCode == OK) { writeinfo(); } freegroupmem(); freefilemem(); FreeCommandMem(); freemotmem(); freeshortusermem(); if(Servermem->confTexts.texts != NULL) { FreeMem(Servermem->confTexts.texts, Servermem->confTexts.arraySize * sizeof(short)); } FreeMem(Servermem,sizeof(struct System)); } if(NiKWindow) CloseWindow(NiKWindow); if(nodereplyport) DeleteMsgPort(nodereplyport); if(permitport) DeletePort(permitport); if(NiKomBase) CloseLibrary(NiKomBase); if(UtilityBase) CloseLibrary(UtilityBase); if(RexxSysBase) CloseLibrary((struct Library *)RexxSysBase); if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase); if(NiKPort) DeletePort(NiKPort); if(exitCode != OK) { printf("\n\nShutting down NiKServer with error code %d: %s\n", exitCode, errorMsg); } exit(exitCode); }
void closetimer() { if (TimerIO) { /* Delete any pending timer requests */ if (!(CheckIO((struct IORequest *)TimerIO))) AbortIO((struct IORequest *)TimerIO); CloseDevice((struct IORequest *) TimerIO); DeleteExtIO((struct IORequest *) TimerIO); } if (TimerMP) { DeletePort(TimerMP); } }
int cw_device_open(void) { static int atexitinitialized = 0; unsigned int i; if (atexitinitialized) { cw_device_close(); } gSIDs = 0; gSwapSIDs = FALSE; for (i = 0; i < 2; i++) { if ((gDiskPort[i] = CreatePort(NULL, 0)) != NULL) { if (gCatweaselReq[i] = (struct IOExtTD *)CreateExtIO(gDiskPort[i], sizeof(struct IOExtTD))) { if (OpenDevice("catweaselsid.device", i, (struct IORequest *)gCatweaselReq[i], 0)) { DeleteExtIO((struct IORequest *)gCatweaselReq[i]); DeletePort(gDiskPort[i]); gCatweaselReq[i] = NULL; gDiskPort[i] = NULL; } else { gSIDs++; } } } } if (gSIDs == 0) { return -1; } if (gCatweaselReq[1] && gCatweaselReq[0] == NULL) { gSwapSIDs = TRUE; } /* install exit handler, so device is closed on exit */ if (!atexitinitialized) { atexitinitialized = 1; atexit((voidfunc_t)cw_device_close); } sidfh = 1; /* ok */ return 1; }
void _glfwPlatformCloseWindow( void ) { // Restore mouse pointer (if hidden) _glfwPlatformShowMouseCursor(); // Destroy OpenGL context if( _glfwWin.Context ) { #ifdef _GLFW_STORMMESA AmigaMesaDestroyContext( _glfwWin.Context ); #endif _glfwWin.Context = NULL; } // Close window if( _glfwWin.Window ) { CloseWindow( _glfwWin.Window ); _glfwWin.Window = NULL; } // Close screen if( _glfwWin.Fullscreen && _glfwWin.Screen ) { CloseScreen( _glfwWin.Screen ); } _glfwWin.Screen = NULL; // Close input device I/O request if( _glfwWin.InputIO ) { CloseDevice( (struct IORequest *) _glfwWin.InputIO ); DeleteExtIO( (struct IORequest *) _glfwWin.InputIO ); _glfwWin.InputIO = NULL; } // Close input device message port if( _glfwWin.InputMP ) { DeletePort( _glfwWin.InputMP ); _glfwWin.InputMP = NULL; } }
/* * checks if a device exists */ static int device_exists (const char *device_name, int device_unit) { struct IOStdReq *ioreq = NULL; struct MsgPort *port = NULL; int ret = 0; port = CreatePort(0, 0); if(port) { ioreq = CreateStdIO(port); if(ioreq) { if(!OpenDevice(device_name,device_unit,(void*)ioreq,0)) { CloseDevice((void*)ioreq); ret = 1; } DeleteStdIO(ioreq); } DeletePort(port); } return ret; }
void msgio_shutdown(void) { msgio_ready--; /* not last one? */ if(msgio_ready > 0) { return; } /* free message */ if(msg) { FreeMem(msg, sizeof(msg_t)); msg = NULL; } /* free reply port */ if(reply_port) { DeletePort(reply_port); reply_port = NULL; } }
int main(void) { struct IOStdReq *ior; struct MsgPort *mp; char buff[10]; Printf("main\n"); if (mp = (struct MsgPort *)CreatePort(0,0)) { Printf("got port\n"); if (ior = (struct IOStdReq *) CreateExtIO(mp, sizeof(struct IOStdReq))) { Printf("got extio\n"); if (OpenDevice("example.device",0,(struct IORequest*)ior,0) == 0) { Printf("opened device\n"); ior->io_Data = buff; ior->io_Command = CMD_READ; ior->io_Length = 1; DoIO((struct IORequest *)ior); Printf("done read\n"); ior->io_Data = buff; ior->io_Command = CMD_WRITE; ior->io_Length = 1; DoIO((struct IORequest *)ior); Printf("done write\n"); CloseDevice((struct IORequest *)ior); } DeleteExtIO((struct IORequest *)ior); } DeletePort(mp); } Printf("done\n"); return 0; }
/* * This function closes down the ARexx context that was opened * with InitARexx... */ void FreeARexx(AREXXCONTEXT RexxContext) { register struct RexxMsg *rmsg; if (RexxContext) { /* * Clear port name so it can't be found... */ RexxContext->PortName[0]='\0'; /* * Clean out any outstanding messages we had sent out... */ while (RexxContext->Outstanding) { WaitPort(RexxContext->ARexxPort); while (rmsg=GetARexxMsg(RexxContext)) { if (rmsg!=REXX_RETURN_ERROR) { /* * Any messages that come now are blown * away... */ SetARexxLastError(RexxContext,rmsg, "99: Port Closed!"); ReplyARexxMsg(RexxContext,rmsg, NULL,100); } } } /* * Clean up the port and delete it... */ if (RexxContext->ARexxPort) { while (rmsg=GetARexxMsg(RexxContext)) { /* * Any messages that still are coming in are * "dead" We just set the LASTERROR and * reply an error of 100... */ SetARexxLastError(RexxContext,rmsg, "99: Port Closed!"); ReplyARexxMsg(RexxContext,rmsg,NULL,100); } DeletePort(RexxContext->ARexxPort); } /* * Make sure we close the library... */ if (RexxContext->arc_RexxSysBase) { CloseLibrary(RexxContext->arc_RexxSysBase); } /* * Free the memory of the RexxContext */ FreeMem(RexxContext,sizeof(struct ARexxContext)); } }
int main(int argc, char **argv) { struct MsgPort *myport; char *PortName; dll_tMessage *msg; int expunge = FALSE; int opencount = 0; /* * If an argument was passed, use it as the port name, * otherwise use the program name */ if (argc > 1) { PortName = argv[1]; } else { PortName = argv[0]; } /* * Process symbol import table */ if (!dllImportSymbols()) { D(bug("[DLL] %s: dllImportSymbols failed\n", PortName)); //exit(0); return 0; } /* * Call DLL specific constructor */ if (!DLL_Init()) { D(bug("[DLL] %s: DLL_Init failed\n", PortName)); //exit(0); return 0; } /* * Create a (public) message port */ if (!(myport = CreatePort(PortName, 0))) { D(bug("[DLL] %s: can't create message port\n", PortName)); //exit(0); return 0; } /* ** Loop until DLL expunges (that is if a CloseMessage leads to opencount==0) ** and no pending Messages are left */ while ((msg = (dll_tMessage *)GetMsg(myport)) || (!expunge)) { if (msg) { switch (msg->dllMessageType) { case DLLMTYPE_Open: D(bug("[DLL] %s: received DLLMTYPE_Open\n", PortName)); if (msg->dllMessageData.dllOpen.StackType != DLLSTACK_DEFAULT) { msg->dllMessageData.dllOpen.ErrorCode = DLLERR_StackNotSupported; if (opencount <= 0) { D(bug("[DLL] %s: unsupported stack type %d, expunging\n", PortName, msg->dllMessageData.dllOpen.StackType)); expunge = TRUE; } break; } opencount++; D(bug("[DLL] %s: increased open count to %d\n", PortName, opencount)); if (opencount > 0) { expunge = FALSE; } msg->dllMessageData.dllOpen.ErrorCode = DLLERR_NoError; break; case DLLMTYPE_Close: D(bug("[DLL] %s: received DLLMTYPE_Close\n", PortName)); opencount--; D(bug("[DLL] %s: descreased open count to %d\n", PortName, opencount)); if (opencount <= 0) { D(bug("[DLL] %s: open count is 0, expunging\n", PortName)); expunge = TRUE; } break; case DLLMTYPE_SymbolQuery: D(bug("[DLL] %s: received DLLMTYPE_SymbolQuery\n", PortName)); dllExportSymbol(&msg->dllMessageData.dllSymbolQuery); D(bug("[DLL] %s: result of symbol query for '%s': %p\n", PortName, msg->dllMessageData.dllSymbolQuery.SymbolName, *msg->dllMessageData.dllSymbolQuery.SymbolPointer)); break; case DLLMTYPE_Kill: D(bug("[DLL] %s: received DLLMTYPE_Kill\n", PortName)); expunge = TRUE; break; } /* * Send the message back */ D(bug("[DLL] %s: replying message\n", PortName)); ReplyMsg((struct Message *)msg); } /* * Wait for messages to pop up * Note that if the DLL is expunged it doesn't wait anymore, * but it still processes all pending messages (including open messages * which can disable the expunge flag). * FIXME: Is this multithread safe ?? */ if (!expunge) { D(bug("[DLL] %s: Waiting for message...\n", PortName)); WaitPort(myport); } } /* * Delete public port */ DeletePort(myport); /* * Call DLL specific destructor */ DLL_DeInit(); return 0; }
/* * copy a device to a FILE*. */ static int raw_copy(char *dev_name, int dev_unit, FILE *dst) { struct MsgPort *port = NULL; struct IOStdReq *ioreq = NULL; int tracklen = 512*11; int retstatus = 1; int inhibited = 0; char *buffer = NULL; static char name[] = {'D','F','0','\0'}; if(!strcmp(dev_name, "trackdisk.device")) { inhibited = 1; name[2] = '0'+dev_unit; } /* allocate system stuff */ if((port = CreatePort(0, 0))) { if((ioreq = CreateStdIO(port))) { if((buffer = AllocMem(tracklen, MEMF_CHIP))) { /* gain access to the device */ if(!OpenDevice(dev_name, dev_unit, (struct IORequest*)ioreq, 0)) { /* check if a disk is present */ myDoIO(ioreq, TD_CHANGESTATE, 0, -1, -1, -1); if(!ioreq->io_Error && ioreq->io_Actual) { fprintf(stderr,"No disk in %s unit %d !\n", dev_name, dev_unit); retstatus = 0; } else { int tr = 0; int write_protected = 0; /* check if disk is write-protected: myDoIO(ioreq, TD_PROTSTATUS, 0, -1, -1, -1); if(!ioreq->io_Error && ioreq->io_Actual) write_protected = 1; */ /* inhibit device */ if(inhibited) inhibited = dev_inhibit(name,1); /* read tracks */ for(tr = 0; tr < 160; ++tr) { printf("Reading track %2d side %d of %s unit %d \r", tr/2, tr%2, dev_name, dev_unit); fflush(stdout); myDoIO(ioreq, CMD_READ, -1, tracklen*tr, tracklen, (LONG)buffer); if(ioreq->io_Error) printf("Err. on\n"); if(fwrite(buffer, 1, tracklen, dst) != (unsigned int)tracklen) { retstatus = 0; break; } } /* ok everything done! */ printf(" \r"); fflush(stdout); /* stop motor */ myDoIO(ioreq, TD_MOTOR, 0, -1, 0, -1); /* uninhibit */ if(inhibited) dev_inhibit(name,0); } CloseDevice((struct IORequest*)ioreq); } else retstatus = 0; FreeMem(buffer,tracklen); } else retstatus = 0; DeleteStdIO(ioreq); } else retstatus = 0; DeletePort(port); } else retstatus = 0; return retstatus; }
int main (int argc, char **argv) { struct timerequest *timereq = 0; struct MsgPort *timeport; struct timeval *tz_offset; struct Device *TimerBase; int quit = 0; int result = calltrap (0, 0); if (result == 1) fputs ("timehack already running.\n", stderr); else if (result == 2) fputs ("timehack not supported with this version of UAE.\n", stderr); if (result != 0) exit (5); timeport = (struct MsgPort *) CreatePort (0, 0); if (timeport) timereq = (struct timerequest *) CreateStdIO(timeport); if (timereq == 0) goto fail; if (OpenDevice ("timer.device", UNIT_VBLANK, (struct IORequest *) timereq, 0) != 0) goto fail; TimerBase = timereq->tr_node.io_Device; SetTaskPri (FindTask (NULL), 20); /* same as input.device */ tz_offset = get_tz_offset(); while (!quit) { struct timeval cur_sys_time; timereq->tr_node.io_Command = TR_GETSYSTIME; DoIO ((struct IORequest *)timereq); cur_sys_time = timereq->tr_time; calltrap (1, &timereq->tr_time); if (timereq->tr_time.tv_secs != cur_sys_time.tv_secs || (timereq->tr_time.tv_secs == cur_sys_time.tv_secs && ABS(timereq->tr_time.tv_micro - cur_sys_time.tv_micro) > 1000)) { AddTime (&timereq->tr_time, tz_offset); timereq->tr_node.io_Command = TR_SETSYSTIME; DoIO ((struct IORequest *)timereq); } timereq->tr_time.tv_secs = 1; timereq->tr_time.tv_micro = 0; timereq->tr_node.io_Command = TR_ADDREQUEST; DoIO ((struct IORequest *)timereq); if (SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) quit = TRUE; } /* Exit and error handling badly needs tidying up - Rich */ CloseDevice ((struct IORequest *)timereq); DeleteStdIO ((struct IOStdReq *)timereq); DeletePort (timeport); exit (0); fail: fputs ("Couldn't start timehack (that's bad!)\n", stderr); exit (5); }
int32_t main(int32_t argc, char **argv) { char *filename, *openMode="rb"; FILE *ADFFile; int32_t write=0; struct IOStdReq *ioreq; struct MsgPort *port; UBYTE *buffer; char devicebuf[256]; char *devicename = "trackdisk.device"; char devicenum = 0; int32_t i; int32_t starttr = 0, endtr = 79; int32_t sectors = 11; for (i = 1; i < argc;) { if (argv[i][0] != '-' || argv[i][2] != 0) { usage(); exit(1); } switch (argv[i][1]) { case 'h': sectors = 22; i++; break; case 'd': if (i+2 >= argc) { usage(); exit(1); } devicenum = atoi(argv[i+2]); sprintf(devicebuf, "%s.device", argv[i+1]); devicename = devicebuf; i += 3; break; case 's': if (i+1 >= argc) { usage(); exit(1); } starttr = atoi(argv[i+1]); i += 2; break; case 'e': if (i+1 >= argc) { usage(); exit(1); } endtr = atoi(argv[i+1]); i += 2; break; case 'w': if (i+1 >= argc) { usage(); exit(1); } filename=argv[i+1]; write=1; i += 2; break; default: usage(); exit(1); } } fprintf(stderr,"Using %s unit %d\n", devicename, devicenum); fprintf(stderr,"Tracks are %d sectors\n", sectors); fprintf(stderr,"First track %d, last track %d\n", starttr, endtr); buffer = AllocMem(512, MEMF_CHIP); if (write) { ADFFile = fopen(filename,openMode); if (!ADFFile) { fprintf(stderr,"Error while opening input file\n"); exit (1); } } port = CreatePort(0, 0); if (port) { ioreq = CreateStdIO(port); if (ioreq) { if (OpenDevice(devicename, devicenum, (struct IORequest *) ioreq, 0) == 0) { int32_t tr, sec; ioreq->io_Command = write ? CMD_WRITE : CMD_READ; ioreq->io_Length = 512; ioreq->io_Data = buffer; for (tr = starttr*2; tr < (endtr+1)*2; tr++) { fprintf(stderr,"Track: %d\r",tr/2); for (sec = 0; sec < sectors; sec++) { fflush(stderr); if (write) if (fread(buffer, sizeof(UBYTE), 512, ADFFile) < 512) { fprintf(stderr, "Error: ADF file to short?\n"); exit(1); } ioreq->io_Offset = 512 * (tr * sectors + sec); DoIO( (struct IORequest *) ioreq); if (!write) fwrite(buffer, sizeof(UBYTE), 512, stdout); } } if (write) { /* Make sure the last track is written to disk */ ioreq->io_Command = CMD_UPDATE; DoIO( (struct IORequest *) ioreq); } ioreq->io_Command = TD_MOTOR; /* Turn Disk-motor off */ ioreq->io_Length = 0; DoIO( (struct IORequest *) ioreq); CloseDevice( (struct IORequest *) ioreq); } else fprintf(stderr,"Unable to open %s unit %d\n", devicename, devicenum); DeleteStdIO(ioreq); } DeletePort(port); } fprintf(stderr,"\n"); FreeMem(buffer, 512); if (write) fclose (ADFFile); return 0; }
void main(int argc,char *argv[]) { int unit; char *devicename; /* ML */ if (argc!=2 && argc!=3) exit(0); unit = argv[1][0]-'0'; if (unit!=0 && unit!=1) exit(0); port = (struct MsgPort *)CreatePort(0,0); if (!port) exit(10); req = (struct IOStdReq *)CreateExtIO(port, sizeof(struct IOExtTD)); if (!req) exit(11); devicename="ide.device"; /* ML */ if (argc==3) devicename=argv[2]; /* ML */ if (OpenDevice (devicename,unit,(struct IORequest *)req,0)) exit(12); mu = (struct MyUnit *)req->io_Unit; if (argc==2) { printf("Device %d:\n",mu->mdu_UnitNum); if (mu->mdu_drv_type==ATAPI_DRV) { printf(" ATAPI device\n"); printf(" Motor is : "); if (mu->mdu_motor==0) printf("OFF\n"); else printf("ON\n"); printf(" Disk change count : %d\n",mu->mdu_change_cnt); printf(" Disk inserted : "); if (mu->mdu_no_disk==0) printf("YES\n"); else printf("NO\n"); } else if (mu->mdu_drv_type==ATA_DRV) { printf(" ATA device\n"); if (mu->mdu_lba) { printf(" LBA"); if (mu->mdu_numlba) printf(" - %d user addressable sectors\n",mu->mdu_numlba); else printf("\n"); } else printf(" no LBA\n"); printf(" Sectors per track : %d\n",mu->mdu_sectors_per_track); printf(" Heads : %d\n",mu->mdu_heads); printf(" Cylinders : %d\n",mu->mdu_cylinders); printf(" Size : %d MB\n",mu->mdu_sectors_per_track*mu->mdu_heads*mu->mdu_cylinders/2048); printf(" Motor is : "); if (mu->mdu_motor==0) printf("OFF\n"); else printf("ON\n"); } else printf(" not present\n",unit); if (mu->mdu_drv_type!=UNKNOWN_DRV && mu->mdu_auto) { printf(" Serial number : %s\n",mu->mdu_ser_num); printf(" Firmware revision : %s\n",mu->mdu_firm_rev); printf(" Model number : %s\n",mu->mdu_model_num); } } else { sprintf(hlp,"Ram:Drive%d",unit); if ((fd = fopen(hlp,"w"))!=NULL) { if (mu->mdu_drv_type==ATAPI_DRV) { fprintf(fd,"ATAPI\n"); } else if (mu->mdu_drv_type==ATA_DRV) { fprintf(fd,"ATA\n"); if (mu->mdu_lba) { fprintf(fd,"LBA %d\n",mu->mdu_numlba); } else fprintf(fd,"noLBA 0\n"); fprintf(fd,"%d\n",mu->mdu_sectors_per_track); fprintf(fd,"%d\n",mu->mdu_heads); fprintf(fd,"%d\n",mu->mdu_cylinders); fprintf(fd,"%d\n",mu->mdu_sectors_per_track*mu->mdu_heads*mu->mdu_cylinders/2048); } else fprintf(fd,"NONE\n"); if (mu->mdu_drv_type!=UNKNOWN_DRV) { if (mu->mdu_auto) { fprintf(fd,"[%s]\n",mu->mdu_ser_num); fprintf(fd,"[%s]\n",mu->mdu_firm_rev); fprintf(fd,"[%s]\n",mu->mdu_model_num); } else fprintf(fd,"X\nX\nX\n"); } } fclose(fd); } CloseDevice((struct IORequest *)req); DeleteExtIO((struct IORequest *)req); DeletePort(port); exit(0); }
int main(int argc, char **argv) { struct MsgPort *myport; char PortName[255]; dll_tMessage *msg; int expunge=0L; int opencount=0L; bug("[DynFile] %s('%s')\n", __PRETTY_FUNCTION__, argv[0]); /* * If an argument was passed, use it as the port name, * otherwise use the program name */ if (argc>1) { char *argPort = argv[1]; if (argPort[0] == '"') strncpy(PortName, &argPort[1], strlen(argPort) - 2); else strcpy(PortName, argPort); } else { strcpy(PortName, argv[0]); } bug("[DynFile] %s: Portname '%s'\n", __PRETTY_FUNCTION__, PortName); /* * Process symbol import table */ if(!dllImportSymbols()) exit(0L); bug("[DynFile] %s: symbols imported\n", __PRETTY_FUNCTION__); /* * Call DLL specific constructor */ if(!DLL_Init()) exit(0L); bug("[DynFile] %s: initialised\n", __PRETTY_FUNCTION__); /* * Create a (public) message port */ myport = CreatePort(PortName,0); if (!myport) exit(0l); bug("[DynFile] %s: port @ 0x%p\n", __PRETTY_FUNCTION__, myport); /* ** Loop until DLL expunges (that is if a CloseMessage leads to opencount==0) ** and no pending Messages are left */ while((msg=(dll_tMessage *)GetMsg(myport))||(!expunge)) { if (msg) { switch(msg->dllMessageType) { case DLLMTYPE_Open: bug("[DynFile] %s: DLLMTYPE_Open\n", __PRETTY_FUNCTION__); /* * Stack type checking should go here. Might be ommited for strictly * private DLLs, or when stack frame compatibility can be 100% assured. * FIXME: Not handled for now */ opencount++; if(opencount>0) expunge=0L; msg->dllMessageData.dllOpen.ErrorCode=DLLERR_NoError; break; case DLLMTYPE_Close: bug("[DynFile] %s: DLLMTYPE_Close\n", __PRETTY_FUNCTION__); opencount--; if(opencount<=0L) // <0 ???? expunge=1L; break; case DLLMTYPE_SymbolQuery: bug("[DynFile] %s: DLLMTYPE_SymbolQuery\n", __PRETTY_FUNCTION__); dllExportSymbol(&msg->dllMessageData.dllSymbolQuery); //printf("Symbol Query for %s : %p\n",msg->dllMessageData.dllSymbolQuery.SymbolName, // *msg->dllMessageData.dllSymbolQuery.SymbolPointer); break; case DLLMTYPE_Kill: bug("[DynFile] %s: DLLMTYPE_Kill\n", __PRETTY_FUNCTION__); expunge=1L; break; } /* * Send the message back */ ReplyMsg((struct Message *)msg); } /* * Wait for messages to pop up * Note that if the DLL is expunged it doesn't wait anymore, * but it still processes all pending messages (including open messages * which can disable the expunge flag). * FIXME: Is this multithread safe ?? */ if(!expunge) WaitPort(myport); } /* * Delete public port */ DeletePort(myport); /* * Call DLL specific destructor */ DLL_DeInit(); return 0L; }