int sendtocon(char *pekare, int size) { struct IntuiMessage *mymess; struct NiKMess *nikmess; int aborted = FALSE, paused=FALSE; ULONG signals,conwritesig = 1L << conwriteport->mp_SigBit, conreadsig = 1L << conreadport->mp_SigBit,windsig = 1L << NiKwind->UserPort->mp_SigBit, nikomnodesig = 1L << nikomnodeport->mp_SigBit; char console = 1, tecken; conwritereq->io_Command=CMD_WRITE; conwritereq->io_Data=(APTR)pekare; conwritereq->io_Length=size; SendIO((struct IORequest *)conwritereq); while(console) { signals = Wait(conwritesig | conreadsig | windsig | nikomnodesig); if(signals & conwritesig) { console=0; if(WaitIO((struct IORequest *)conwritereq)) printf("Error console\n"); } if(signals & conreadsig) { if((tecken=congettkn()) == 3) { if(console) { AbortIO((struct IORequest *)conwritereq); WaitIO((struct IORequest *)conwritereq); } aborted=TRUE; console=0; putstring("^C\n\r",-1,0); } else if((tecken==' ' && (Servermem->inne[nodnr].flaggor & MELLANSLAG)) || tecken==19) paused=TRUE; else if(tecken && typeaheadbuftkn<50) { typeaheadbuf[typeaheadbuftkn++]=tecken; typeaheadbuf[typeaheadbuftkn]=0; } } if(signals & windsig) { mymess=(struct IntuiMessage *)GetMsg(NiKwind->UserPort); ReplyMsg((struct Message *)mymess); cleanup(OK,""); } if(signals & nikomnodesig) { while(nikmess = (struct NiKMess *) GetMsg(nikomnodeport)) { handleservermess(nikmess); ReplyMsg((struct Message *)nikmess); } if(carrierdropped()) aborted = TRUE; } } if(paused && gettekn()==3) { putstring("^C\n\r",-1,0); return(TRUE); } return(aborted); }
int getchar(void) { struct AmigaIO *ior; char c = '\n'; struct Console *mc = ConsoleBase; unsigned long ticks; #ifdef SERCONSOLE int32_t r; #endif mc->cnior->length = 1; mc->cnior->buf = &c; mc->cnior->cmd = Cmd_Rd; SendIO(mc->cnior); ticks = 10 * timelimit; do { if (timelimit == 0) ticks = 2; mc->tmior->cmd = Cmd_Addtimereq; mc->tmior->secs = 0; mc->tmior->usec = 100000; SendIO((struct AmigaIO *)mc->tmior); ior = WaitPort(mc->cnmp); if (ior == mc->cnior) { AbortIO((struct AmigaIO *)mc->tmior); ticks = 1; } else /* if (ior == mc->tmior) */ { #ifdef SERCONSOLE if (use_serconsole) { r = RawMayGetChar(); if (r != -1) { c = r; ticks = 1; } } #endif if (ticks == 1) AbortIO((struct AmigaIO *)mc->cnior); } WaitIO((struct AmigaIO *)mc->tmior); --ticks; } while (ticks != 0); timelimit = 0; (void)WaitIO(mc->cnior); return c; }
void CloseConsole(void) { if(!(CheckIO((struct IORequest *)conreadreq))) { AbortIO((struct IORequest *)conreadreq); WaitIO((struct IORequest *)conreadreq); } if(!(CheckIO((struct IORequest *)conwritereq))) { AbortIO((struct IORequest *)conwritereq); WaitIO((struct IORequest *)conwritereq); } CloseDevice((struct IORequest *)conwritereq); }
void ti_Cleanup(Global_T *g) { #ifndef DISABLED SyncTimer *st = &g->g_SyncTimer; if(st->st_Pkt) { if(st->st_Req) { if(st->st_Flags & STF_TIMER_USED) { if(!CheckIO(&st->st_Req->Request)) AbortIO(&st->st_Req->Request); WaitIO(&st->st_Req->Request); } if(st->st_Flags & STF_DEVICE_OPEN) CloseDevice(&st->st_Req->Request); } } if(st->st_Pkt) FreeVec(st->st_Pkt); if(st->st_Req) DeleteIORequest(st->st_Req); memset(st, 0, sizeof(*st)); #endif }
void Sys_Net_Wait(struct SysNetData *netdata, struct SysSocket *socket, unsigned int timeout_us) { fd_set rfds; ULONG sigmask; WaitIO((struct IORequest *)netdata->timerrequest); if (SetSignal(0, 0) & (1<<netdata->timerport->mp_SigBit)) Wait(1<<netdata->timerport->mp_SigBit); FD_ZERO(&rfds); FD_SET(socket->s, &rfds); netdata->timerrequest->tr_node.io_Command = TR_ADDREQUEST; netdata->timerrequest->tr_time.tv_secs = timeout_us / 1000000; netdata->timerrequest->tr_time.tv_micro = timeout_us % 1000000; SendIO((struct IORequest *)netdata->timerrequest); sigmask = 1<<netdata->timerport->mp_SigBit; WaitSelect(socket->s + 1, &rfds, 0, 0, 0, &sigmask); AbortIO((struct IORequest *)netdata->timerrequest); }
__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 modifynoise(UWORD period, UWORD volume) { modifyreq->ioa_Period = period; modifyreq->ioa_Volume = volume; BeginIO(&(modifyreq->ioa_Request)); WaitIO(&(modifyreq->ioa_Request)); }
void CSleep(int milliseconds) { #if defined(PSP) sceKernelDelayThread(milliseconds * 1000); #elif defined(__BEOS__) snooze(milliseconds * 1000); #elif defined(__AMIGA__) { ULONG signals; ULONG TimerSigBit = 1 << TimerPort->mp_SigBit; /* send IORequest */ TimerRequest->tr_node.io_Command = TR_ADDREQUEST; TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000; TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000; SendIO((struct IORequest *)TimerRequest); if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) { AbortIO((struct IORequest *)TimerRequest); } WaitIO((struct IORequest *)TimerRequest); } #else usleep(milliseconds * 1000); #endif }
void CloseTimer(struct timerequest *treq) { if(!(CheckIO((struct IORequest *)timerreq))) { AbortIO((struct IORequest *)timerreq); WaitIO((struct IORequest *)timerreq); } CloseDevice((struct IORequest *)treq); }
/* Waits for a signal or a timeout */ ULONG ata_WaitTO(struct IORequest* tmr, ULONG secs, ULONG micro, ULONG sigs) { ULONG sig = 1 << tmr->io_Message.mn_ReplyPort->mp_SigBit; D(struct Node *t = (struct Node *)FindTask(NULL)); D(bug("[ATA ] Timed wait %lds %ldu (task='%s')\n", secs, micro, t->ln_Name)); tmr->io_Command = TR_ADDREQUEST; ((struct timerequest*)tmr)->tr_time.tv_secs = secs; ((struct timerequest*)tmr)->tr_time.tv_micro = micro; SendIO(tmr); D(bug("[ATA ] Preset signals: %lx ('%s')\n", SetSignal(0, 0), t->ln_Name)); D(bug("[ATA ] Signals requested: %lx ('%s')\n", sigs, t->ln_Name)); D(bug("[ATA ] Timer signal: %lx ('%s')\n", sig, t->ln_Name)); sigs = Wait(sigs | sig); D(bug("[ATA ] Signals received: %lx ('%s')\n", sigs, t->ln_Name)); if (0 == (sigs & sig)) { if (!CheckIO(tmr)) AbortIO(tmr); } WaitIO(tmr); SetSignal(0, sig); return sigs & ~sig; }
void static AHI_WaitAudio(_THIS) { if(!CheckIO((struct IORequest *)audio_req[current_buffer])) { WaitIO((struct IORequest *)audio_req[current_buffer]); // AbortIO((struct IORequest *)audio_req[current_buffer]); } }
char congettkn(void) { char temp; WaitIO((struct IORequest *)conreadreq); temp=coninput; conreqtkn(); return((char)temp); }
void Sys_Net_Shutdown(struct SysNetData *netdata) { WaitIO((struct IORequest *)netdata->timerrequest); CloseDevice((struct IORequest *)netdata->timerrequest); DeleteIORequest((struct IORequest *)netdata->timerrequest); DeleteMsgPort(netdata->timerport); CloseLibrary(SocketBase); FreeVec(netdata); }
long __saveds __regargs nik_sread(char *databuffer,long size,long timeout) { ULONG signals,sersig=1L << serreadport->mp_SigBit, timersig=1L << timerport->mp_SigBit; if(timeout) { serreadreq->IOSer.io_Command=CMD_READ; serreadreq->IOSer.io_Length=size; serreadreq->IOSer.io_Data=(APTR)databuffer; SendIO((struct IORequest *)serreadreq); timerreq->tr_node.io_Command=TR_ADDREQUEST; timerreq->tr_time.tv_secs=timeout/1000000; timerreq->tr_time.tv_micro=timeout%1000000; timerreq->tr_node.io_Message.mn_ReplyPort=timerport; SendIO((struct IORequest *)timerreq); for(;;) { signals=Wait(sersig | timersig); if((signals & sersig) && CheckIO((struct IORequest *)serreadreq)) { WaitIO((struct IORequest *)serreadreq); AbortIO((struct IORequest *)timerreq); WaitIO((struct IORequest *)timerreq); if(serreadreq->IOSer.io_Error || carrierdropped()) return(-1L); return((long)serreadreq->IOSer.io_Actual); } if((signals & timersig) && CheckIO((struct IORequest *)timerreq)) { WaitIO((struct IORequest *)timerreq); AbortIO((struct IORequest *)serreadreq); WaitIO((struct IORequest *)serreadreq); /* printf("Timeout! Size=%d Timeout=%d Actual=%d",size,timeout,serreadreq->IOSer.io_Actual); */ return((long)serreadreq->IOSer.io_Actual); } } } else { serreadreq->IOSer.io_Command=SDCMD_QUERY; DoIO((struct IORequest *)serreadreq); serreadreq->IOSer.io_Command=CMD_READ; if(serreadreq->IOSer.io_Actual > size) serreadreq->IOSer.io_Length=size; else serreadreq->IOSer.io_Length=serreadreq->IOSer.io_Actual; serreadreq->IOSer.io_Data=(APTR)databuffer; DoIO((struct IORequest *)serreadreq); return((long)serreadreq->IOSer.io_Actual); } }
void CleanupTimer(void) { D(bug("[fat] Cleaning up timer\n")); if (glob->timer_active) { D(bug("[fat] Terminating active request\n")); AbortIO((struct IORequest *)glob->timereq); WaitIO((struct IORequest *)glob->timereq); } CloseDevice((struct IORequest *)glob->timereq); DeleteIORequest((struct IORequest *)glob->timereq); DeleteMsgPort(glob->timerport); }
void ami_remove_timer_event(struct nscallback *nscb) { if(!nscb) return; if(nscb->treq) { if(CheckIO((struct IORequest *)nscb->treq)==NULL) AbortIO((struct IORequest *)nscb->treq); WaitIO((struct IORequest *)nscb->treq); FreeVec(nscb->treq); } }
void HandleTimer(void) { WaitIO((struct IORequest *)glob->timereq); glob->timer_active = 0; if (glob->restart_timer) { D(bug("Timer restart queued\n")); glob->restart_timer = 0; RestartTimer(); } else { D(bug("Updating disk\n")); UpdateDisk(); } }
int getfifoevent(struct MsgPort *fifoport, char *puthere) { struct IntuiMessage *mymess; struct NiKMess *nikmess; ULONG signals,conreadsig=1L << conreadport->mp_SigBit,windsig=1L << NiKwind->UserPort->mp_SigBit, fifosig=1L << fifoport->mp_SigBit, nikomnodesig = 1L << nikomnodeport->mp_SigBit; int event=0; while(!event) { signals = Wait(conreadsig | windsig | fifosig | nikomnodesig | SIGBREAKF_CTRL_C); if((signals & conreadsig) && CheckIO((struct IORequest *)conreadreq)) { *puthere=congettkn(); event|=FIFOEVENT_FROMUSER; } if(signals & windsig) { mymess=(struct IntuiMessage *)GetMsg(NiKwind->UserPort); ReplyMsg((struct Message *)mymess); AbortIO((struct IORequest *)conreadreq); WaitIO((struct IORequest *)conreadreq); event|=FIFOEVENT_CLOSEW; } if(signals & SIGBREAKF_CTRL_C) { AbortIO((struct IORequest *)conreadreq); WaitIO((struct IORequest *)conreadreq); event|=FIFOEVENT_CLOSEW; } if(signals & fifosig) { event|=FIFOEVENT_FROMFIFO; } if(signals & nikomnodesig) { while(nikmess = (struct NiKMess *) GetMsg(nikomnodeport)) { handleservermess(nikmess); ReplyMsg((struct Message *)nikmess); } if(carrierdropped()) event |= FIFOEVENT_NOCARRIER; } } return(event); }
__stkargs unsigned int alarm(unsigned int seconds) { static struct timeval tv; static first = 1; if (!treq) { printf("No handler installed !\n"); if (seconds > 0) return 0; /* Heartbeat won't work :+( */ } tv.tv_secs = seconds; tv.tv_micro = 0; if (seconds > 0) { /* first call of alarm() : WaitIO on unsent request ..... */ if (!first) { treq->tr_node.io_Message.mn_ReplyPort->mp_Flags = PA_IGNORE; AbortIO((struct IORequest *) treq); WaitIO((struct IORequest *) treq); treq->tr_node.io_Message.mn_ReplyPort->mp_Flags = PA_SIGNAL; } first = 0; start_timer(&tv, treq); } else { /* * if I don't use this code, AbortIO will generate a signal, which * will trigger catch_alarm. catch_alarm will then generate CTRL-E. * This can be resolved by preventing the signal to occur :+) */ treq->tr_node.io_Message.mn_ReplyPort->mp_Flags = PA_IGNORE; AbortIO((struct IORequest *) treq); WaitIO((struct IORequest *) treq); cleanup_timer(&treq); first = 1; } return 0; }
// // perform an I/O command and wait for completion // BYTE DoIO(struct IORequest *io) { if (!io || io->io_Device == NULL) return -1; io->io_Flags = IOF_QUICK; io->io_Message.Node.Type = 0; BeginIO(io); if (!io->io_Flags & IOF_QUICK) WaitIO(io); return io->io_Error; }
// // perform an I/O command and wait for completion // BYTE DoIO(struct IORequest * ioRequest) { if (!ioRequest || ioRequest->io_Device == NULL) return -1; ioRequest->io_Flags = IOF_QUICK; ioRequest->io_Message.mn_Node.ln_Type = 0; //BeginIO(ioRequest); if (!ioRequest->io_Flags & IOF_QUICK) WaitIO(ioRequest); return ioRequest->io_Error; }
static void remove_protocol(NetProtocol *p) { // Remove from list Forbid(); Remove(p); Permit(); // Cancel read requests for (int i=0; i<NUM_READ_REQUESTS; i++) { AbortIO((struct IORequest *)(p->read_io + i)); WaitIO((struct IORequest *)(p->read_io + i)); } // Free protocol struct FreeMem(p, sizeof(NetProtocol)); }
static void finish_resethandler(void) { if (rhdata->rebooting) { if (rhdata->timing) { /* Wait until 3 seconds has passed allowing disk buffers to flush. */ WaitIO(&rhdata->timereq.tr_node); CloseDevice(&rhdata->timereq.tr_node); } /* Tell system it's ok to reboot now. */ rhdata->ioreq->io_Command = KBD_RESETHANDLERDONE; rhdata->ioreq->io_Data = (APTR) &rhdata->is; DoIO((struct IORequest *) rhdata->ioreq); rhdata->rebooting = FALSE; rem_resethandler(); } }
ULONG sdcard_WaitTO(struct IORequest* tmr, ULONG secs, ULONG micro, ULONG sigs) { ULONG sig = 1 << tmr->io_Message.mn_ReplyPort->mp_SigBit; tmr->io_Command = TR_ADDREQUEST; ((struct timerequest*)tmr)->tr_time.tv_secs = secs; ((struct timerequest*)tmr)->tr_time.tv_micro = micro; SendIO(tmr); sigs = Wait(sigs | sig); if (0 == (sigs & sig)) { if (!CheckIO(tmr)) AbortIO(tmr); } WaitIO(tmr); SetSignal(0, sig); return sigs &~ sig; }
static void AHI_PlayAudio(_THIS) { if(playing>1) WaitIO((struct IORequest *)audio_req[current_buffer]); /* Write the audio data out */ audio_req[current_buffer] -> ahir_Std. io_Message.mn_Node.ln_Pri = 60; audio_req[current_buffer] -> ahir_Std. io_Data = mixbuf[current_buffer]; audio_req[current_buffer] -> ahir_Std. io_Length = this->hidden->size; audio_req[current_buffer] -> ahir_Std. io_Offset = 0; audio_req[current_buffer] -> ahir_Std . io_Command = CMD_WRITE; audio_req[current_buffer] -> ahir_Frequency = this->hidden->freq; audio_req[current_buffer] -> ahir_Volume = 0x10000; audio_req[current_buffer] -> ahir_Type = this->hidden->type; audio_req[current_buffer] -> ahir_Position = 0x8000; audio_req[current_buffer] -> ahir_Link = (playing>0 ? audio_req[current_buffer^1] : NULL); SendIO((struct IORequest *)audio_req[current_buffer]); current_buffer^=1; playing++; }
int DoIO (void *ioreq, struct MsgPort *reply_port) { struct StdIOReq *stdreq = ioreq; KASSERT (stdreq != NULL); KASSERT (stdreq->device != NULL); stdreq->msg.state = MSG_STATE_DEQUEUED; stdreq->msg.data = stdreq; if (reply_port == NULL) stdreq->msg.reply_port = ¤t_process->reply_port; else stdreq->msg.reply_port = reply_port; stdreq->flags |= IOF_QUICK; stdreq->device->beginio (ioreq); if ((stdreq->flags & IOF_QUICK) == 0) WaitIO (ioreq); return stdreq->error; }
__saveds void ASERDPort::serial_func(void) { struct ASERDPort *obj = (ASERDPort *)proc_arg; struct MsgPort *proc_port = NULL, *io_port = NULL, *control_port = NULL; struct IOExtSer *read_io = NULL, *write_io = NULL, *control_io = NULL; uint8 orig_params[sizeof(struct IOExtSer)]; bool opened = false; ULONG io_mask = 0, proc_port_mask = 0; // Default: error occured obj->proc_error = true; // Create message port for communication with main task proc_port = CreateMsgPort(); if (proc_port == NULL) goto quit; proc_port_mask = 1 << proc_port->mp_SigBit; // Create message ports for serial.device I/O io_port = CreateMsgPort(); if (io_port == NULL) goto quit; io_mask = 1 << io_port->mp_SigBit; control_port = CreateMsgPort(); if (control_port == NULL) goto quit; // Create IORequests read_io = (struct IOExtSer *)CreateIORequest(io_port, sizeof(struct IOExtSer)); write_io = (struct IOExtSer *)CreateIORequest(io_port, sizeof(struct IOExtSer)); control_io = (struct IOExtSer *)CreateIORequest(control_port, sizeof(struct IOExtSer)); if (read_io == NULL || write_io == NULL || control_io == NULL) goto quit; read_io->IOSer.io_Message.mn_Node.ln_Type = 0; // Avoid CheckIO() bug write_io->IOSer.io_Message.mn_Node.ln_Type = 0; control_io->IOSer.io_Message.mn_Node.ln_Type = 0; // Parse device name char dev_name[256]; ULONG dev_unit; if (sscanf(obj->device_name, "%[^/]/%ld", dev_name, &dev_unit) < 2) goto quit; // Open device if (obj->is_parallel) ((IOExtPar *)read_io)->io_ParFlags = PARF_SHARED; else read_io->io_SerFlags = SERF_SHARED | SERF_7WIRE; if (OpenDevice((UBYTE *) dev_name, dev_unit, (struct IORequest *)read_io, 0) || read_io->IOSer.io_Device == NULL) goto quit; opened = true; // Copy IORequests memcpy(write_io, read_io, sizeof(struct IOExtSer)); memcpy(control_io, read_io, sizeof(struct IOExtSer)); // Attach control_io to control_port and set default values control_io->IOSer.io_Message.mn_ReplyPort = control_port; if (!obj->is_parallel) { control_io->io_CtlChar = SER_DEFAULT_CTLCHAR; control_io->io_RBufLen = 64; control_io->io_ExtFlags = 0; control_io->io_Baud = 9600; control_io->io_BrkTime = 250000; control_io->io_ReadLen = control_io->io_WriteLen = 8; control_io->io_StopBits = 1; control_io->io_SerFlags = SERF_SHARED; control_io->IOSer.io_Command = SDCMD_SETPARAMS; DoIO((struct IORequest *)control_io); memcpy(orig_params, &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar)); } // Initialization went well, inform main task obj->proc_port = proc_port; obj->control_io = control_io; obj->proc_error = false; Signal(MainTask, SIGF_SINGLE); // Main loop for (;;) { // Wait for I/O and messages (CTRL_C is used for quitting the task) ULONG sig = Wait(proc_port_mask | io_mask | SIGBREAKF_CTRL_C); // Main task wants to quit us if (sig & SIGBREAKF_CTRL_C) break; // Main task sent a command to us if (sig & proc_port_mask) { struct SerMessage *msg; while (msg = (SerMessage *)GetMsg(proc_port)) { D(bug("serial_proc received %08lx\n", msg->what)); switch (msg->what) { case MSG_QUERY: control_io->IOSer.io_Command = SDCMD_QUERY; DoIO((struct IORequest *)control_io); D(bug(" query returned %08lx, actual %08lx\n", control_io->IOSer.io_Error, control_io->IOSer.io_Actual)); break; case MSG_SET_PARAMS: // Only send SDCMD_SETPARAMS when configuration has changed if (memcmp(orig_params, &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar))) { memcpy(orig_params, &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar)); memcpy(&(read_io->io_CtlChar), &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar)); memcpy(&(write_io->io_CtlChar), &(control_io->io_CtlChar), (uint8 *)&(control_io->io_Status) - (uint8 *)&(control_io->io_CtlChar)); control_io->IOSer.io_Command = SDCMD_SETPARAMS; D(bug(" params %08lx %08lx %08lx %08lx %08lx %08lx\n", control_io->io_CtlChar, control_io->io_RBufLen, control_io->io_ExtFlags, control_io->io_Baud, control_io->io_BrkTime, *(uint32 *)((uint8 *)control_io + 76))); DoIO((struct IORequest *)control_io); D(bug(" set_parms returned %08lx\n", control_io->IOSer.io_Error)); } break; case MSG_SET_PAR_PARAMS: control_io->IOSer.io_Command = PDCMD_SETPARAMS; DoIO((struct IORequest *)control_io); D(bug(" set_par_parms returned %08lx\n", control_io->IOSer.io_Error)); break; case MSG_BREAK: control_io->IOSer.io_Command = SDCMD_BREAK; DoIO((struct IORequest *)control_io); D(bug(" break returned %08lx\n", control_io->IOSer.io_Error)); break; case MSG_RESET: control_io->IOSer.io_Command = CMD_RESET; DoIO((struct IORequest *)control_io); D(bug(" reset returned %08lx\n", control_io->IOSer.io_Error)); break; case MSG_KILL_IO: AbortIO((struct IORequest *)read_io); AbortIO((struct IORequest *)write_io); WaitIO((struct IORequest *)read_io); WaitIO((struct IORequest *)write_io); obj->read_pending = obj->write_pending = false; obj->read_done = obj->write_done = false; break; case MSG_PRIME_IN: read_io->IOSer.io_Message.mn_Node.ln_Name = (char *)msg->pb; read_io->IOSer.io_Data = Mac2HostAddr(ReadMacInt32(msg->pb + ioBuffer)); read_io->IOSer.io_Length = ReadMacInt32(msg->pb + ioReqCount); read_io->IOSer.io_Actual = 0; read_io->IOSer.io_Command = CMD_READ; D(bug("serial_proc receiving %ld bytes from %08lx\n", read_io->IOSer.io_Length, read_io->IOSer.io_Data)); SendIO((struct IORequest *)read_io); break; case MSG_PRIME_OUT: { write_io->IOSer.io_Message.mn_Node.ln_Name = (char *)msg->pb; write_io->IOSer.io_Data = Mac2HostAddr(ReadMacInt32(msg->pb + ioBuffer)); write_io->IOSer.io_Length = ReadMacInt32(msg->pb + ioReqCount); write_io->IOSer.io_Actual = 0; write_io->IOSer.io_Command = CMD_WRITE; D(bug("serial_proc transmitting %ld bytes from %08lx\n", write_io->IOSer.io_Length, write_io->IOSer.io_Data)); #if MONITOR bug("Sending serial data:\n"); uint8 *adr = Mac2HostAddr(ReadMacInt32(msg->pb + ioBuffer)); for (int i=0; i<len; i++) { bug("%02lx ", adr[i]); } bug("\n"); #endif SendIO((struct IORequest *)write_io); break; } } D(bug(" serial_proc replying\n")); ReplyMsg(msg); } } // I/O operation completed if (sig & io_mask) { struct IOExtSer *io; while (io = (struct IOExtSer *)GetMsg(io_port)) { if (io == read_io) { D(bug("read_io complete, %ld bytes received, error %ld\n", read_io->IOSer.io_Actual, read_io->IOSer.io_Error)); uint32 pb = (uint32)read_io->IOSer.io_Message.mn_Node.ln_Name; #if MONITOR bug("Receiving serial data:\n"); uint8 *adr = Mac2HostAddr(ReadMacInt32(msg->pb + ioBuffer)); for (int i=0; i<read_io->IOSer.io_Actual; i++) { bug("%02lx ", adr[i]); } bug("\n"); #endif WriteMacInt32(pb + ioActCount, read_io->IOSer.io_Actual); obj->conv_error(read_io, obj->input_dt); obj->read_done = true; SetInterruptFlag(INTFLAG_SERIAL); TriggerInterrupt(); } else if (io == write_io) { D(bug("write_io complete, %ld bytes sent, error %ld\n", write_io->IOSer.io_Actual, write_io->IOSer.io_Error)); uint32 pb = (uint32)write_io->IOSer.io_Message.mn_Node.ln_Name; WriteMacInt32(pb + ioActCount, write_io->IOSer.io_Actual); obj->conv_error(write_io, obj->output_dt); obj->write_done = true; SetInterruptFlag(INTFLAG_SERIAL); TriggerInterrupt(); } } } } quit: // Close everything if (opened) { if (CheckIO((struct IORequest *)write_io) == 0) { AbortIO((struct IORequest *)write_io); WaitIO((struct IORequest *)write_io); } if (CheckIO((struct IORequest *)read_io) == 0) { AbortIO((struct IORequest *)read_io); WaitIO((struct IORequest *)read_io); } CloseDevice((struct IORequest *)read_io); } if (control_io) DeleteIORequest(control_io); if (write_io) DeleteIORequest(write_io); if (read_io) DeleteIORequest(read_io); if (control_port) DeleteMsgPort(control_port); if (io_port) DeleteMsgPort(io_port); // Send signal to main task to confirm termination Forbid(); Signal(MainTask, SIGF_SINGLE); }
int main(int argc, char *argv[]) { BYTE *p1=buffer1,*p2=buffer2; void *tmp; ULONG signals,length; struct AHIRequest *link = NULL; LONG priority = 0; BYTE pri; if(argc == 2) { StrToLong(argv[1], &priority); } pri = priority; Printf("Sound priority: %ld\n", pri); if((AHImp=CreateMsgPort()) != NULL) { if((AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest))) != NULL) { AHIio->ahir_Version = 4; AHIDevice=OpenDevice(AHINAME,0,(struct IORequest *)AHIio,0); } } if(AHIDevice) { Printf("Unable to open %s/0 version 4\n",AHINAME); cleanup(RETURN_FAIL); } // Make a copy of the request (for double buffering) AHIiocopy = AllocMem(sizeof(struct AHIRequest), MEMF_ANY); if(! AHIiocopy) { cleanup(RETURN_FAIL); } CopyMem(AHIio, AHIiocopy, sizeof(struct AHIRequest)); AHIios[0]=AHIio; AHIios[1]=AHIiocopy; SetIoErr(0); for(;;) { // Fill buffer length = Read(Input(),p1,BUFFERSIZE); // Play buffer AHIios[0]->ahir_Std.io_Message.mn_Node.ln_Pri = pri; AHIios[0]->ahir_Std.io_Command = CMD_WRITE; AHIios[0]->ahir_Std.io_Data = p1; AHIios[0]->ahir_Std.io_Length = length; AHIios[0]->ahir_Std.io_Offset = 0; AHIios[0]->ahir_Frequency = FREQUENCY; AHIios[0]->ahir_Type = TYPE; AHIios[0]->ahir_Volume = 0x10000; // Full volume AHIios[0]->ahir_Position = 0x8000; // Centered AHIios[0]->ahir_Link = link; SendIO((struct IORequest *) AHIios[0]); if(link) { // Wait until the last buffer is finished (== the new buffer is started) signals=Wait(SIGBREAKF_CTRL_C | (1L << AHImp->mp_SigBit)); // Check for Ctrl-C and abort if pressed if(signals & SIGBREAKF_CTRL_C) { SetIoErr(ERROR_BREAK); break; } // Remove the reply and abort on error if(WaitIO((struct IORequest *) link)) { SetIoErr(ERROR_WRITE_PROTECTED); break; } } // Check for end-of-sound, and wait until it is finished before aborting if(length != BUFFERSIZE) { WaitIO((struct IORequest *) AHIios[0]); break; } link = AHIios[0]; // Swap buffer and request pointers, and restart tmp = p1; p1 = p2; p2 = tmp; tmp = AHIios[0]; AHIios[0] = AHIios[1]; AHIios[1] = tmp; } // Abort any pending iorequests AbortIO((struct IORequest *) AHIios[0]); WaitIO((struct IORequest *) AHIios[0]); if(link) { // Only if the second request was started AbortIO((struct IORequest *) AHIios[1]); WaitIO((struct IORequest *) AHIios[1]); } if(IoErr()) { PrintFault(IoErr(), argv[0] ); cleanup(RETURN_ERROR); } cleanup(RETURN_OK); return RETURN_OK; // Make compiler happy }
void main(int argc, char *argv[]) { BYTE *p1=buffer1,*p2=buffer2,*tmp; ULONG signals; if(AHImp=CreateMsgPort()) { if(AHIio=(struct AHIRequest *)CreateIORequest(AHImp,sizeof(struct AHIRequest))) { AHIio->ahir_Version = 4; AHIDevice=OpenDevice(AHINAME,0,(struct IORequest *)AHIio,NULL); } } if(AHIDevice) { Printf("Unable to open %s/0 version 4\n",AHINAME); cleanup(RETURN_FAIL); } // Initialize the first read AHIio->ahir_Std.io_Command=CMD_READ; AHIio->ahir_Std.io_Data=&buffer1; AHIio->ahir_Std.io_Length=BUFFERSIZE; AHIio->ahir_Std.io_Offset=0; AHIio->ahir_Frequency=FREQUENCY; AHIio->ahir_Type=TYPE; if(!DoIO((struct IORequest *) AHIio)) { // The first buffer is now filled SetIoErr(NULL); for(;;) { ULONG length; length=AHIio->ahir_Std.io_Actual; // Initialize the second read (note that io_Offset is not cleared!) AHIio->ahir_Std.io_Data=p2; AHIio->ahir_Std.io_Length=BUFFERSIZE; AHIio->ahir_Frequency=FREQUENCY; AHIio->ahir_Type=TYPE; SendIO((struct IORequest *) AHIio); // While the second read is in progress, save the first buffer to stdout if(Write(Output(),p1,length) != length) { break; } signals=Wait(SIGBREAKF_CTRL_C | (1L << AHImp->mp_SigBit)); if(signals & SIGBREAKF_CTRL_C) { SetIoErr(ERROR_BREAK); break; } // Remove the reply if(WaitIO((struct IORequest *) AHIio)) { SetIoErr(ERROR_READ_PROTECTED); break; } // Swap buffer pointers and repeat tmp=p1; p1=p2; p2=tmp; } // Abort any pending iorequests AbortIO((struct IORequest *) AHIio); WaitIO((struct IORequest *) AHIio); } if(IoErr()) { PrintFault(IoErr(), argv[0] ); // Oh, common! It's not MY fault that this // routine prints to stdout instead of stderr! cleanup(RETURN_ERROR); } cleanup(RETURN_OK); }
long HandleServerMsg(void) { unsigned long PubScreenModes; BlankMsg *CurMsg; while(CurMsg = (BlankMsg *)GetMsg(ServerPort)) { long Type = CurMsg->bm_Type; long Flags = CurMsg->bm_Flags; if(Flags & BF_REPLY) { if(!(Flags & BF_INTERNAL)) FreeVec(CurMsg); } else { CurMsg->bm_Flags |= BF_REPLY; ReplyMsg((struct Message *)CurMsg); } switch(Type) { case BM_DOBLANK: if(Flags & BF_REPLY) { if(!CheckIO((struct IORequest *)TimeOutIO)) { AbortIO((struct IORequest *)TimeOutIO); WaitIO((struct IORequest *)TimeOutIO); SetSignal(0L, SIG_TIMER); } if(ServerScr) { UnblankMousePointer(Wnd); CloseScreen(ServerScr); ServerScr = 0L; } if(!PingTask) PingTask = CreateTask("GarshnePing", -5, PingFunc, 4096); Blanking = TRUE; } break; case BM_DOTESTBLANK: if(Flags & BF_REPLY) { if(!PingTask) PingTask = CreateTask("GarshnePing", -5, PingFunc, 4096); Blanking = TRUE; } break; case BM_INITMSG: if(BlankAfterInit) { BlankAfterInit = FALSE; MessageModule("GarshneClient", BM_DOBLANK); } break; case BM_FAILED: if(PingTask) { Signal(PingTask, SIGBREAKF_CTRL_C); PingTask = 0L; } InternalBlank(); break; case BM_SENDBLANK: if((Flags & BF_REPLY)|| BlankingDisabled) break; if(ServerScr &&(UsagePercent() > 40)) break; PubScreenModes = SetPubScreenModes(0L); if(Stricmp(Prefs->bp_Blanker, "Random")) { if(!Blanking || ServerScr) MessageModule("GarshneClient", BM_DOBLANK); } else { if(!Blanking || Prefs->bp_Flags & BF_REPLACE) { MessageModule("GarshneClient", BM_DELAYEDQUIT); BlankAfterInit = TRUE; LoadModule(Prefs->bp_Dir, Prefs->bp_Blanker); } else if(ServerScr) MessageModule("GarshneClient", BM_DOBLANK); } SetPubScreenModes(PubScreenModes); break; case BM_SENDTEST: if((Flags & BF_REPLY)|| BlankingDisabled) break; PubScreenModes = SetPubScreenModes(0L); MessageModule("GarshneClient", BM_DOTESTBLANK); SetPubScreenModes(PubScreenModes); break; case BM_SENDUNBLANK: if(Flags & BF_REPLY) break; if(ServerScr) { UnblankMousePointer(Wnd); CloseScreen(ServerScr); ServerScr = 0L; } Blanking = FALSE; MessageModule("GarshneClient", BM_UNBLANK); if(PingTask) { Signal(PingTask, SIGBREAKF_CTRL_C); PingTask = 0L; } break; default: break; } } return OK; }