예제 #1
0
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);
}
예제 #2
0
파일: console.c 프로젝트: ryo/netbsd-src
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;
}
예제 #3
0
파일: timer.c 프로젝트: jens-maus/anfs
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
}
예제 #4
0
int lib_exec_f_AbortIO_2(emumsg_syscall_t *msg)
{
	/* Make real syscall */
	AbortIO((struct IORequest *)msg->arg[0]._aptr);

	return HOOK_DONE;
}
예제 #5
0
파일: signal.c 프로젝트: DailyR/mudos
__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;
}
예제 #6
0
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);
}
예제 #7
0
void CloseTimer(struct timerequest *treq) {
	if(!(CheckIO((struct IORequest *)timerreq))) {
		AbortIO((struct IORequest *)timerreq);
		WaitIO((struct IORequest *)timerreq);
	}
	CloseDevice((struct IORequest *)treq);
}
예제 #8
0
파일: waitto.c 프로젝트: michalsc/AROS
/* 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;
}
예제 #9
0
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
}
예제 #10
0
파일: noise.c 프로젝트: axelmuhr/Helios-NG
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);
}
예제 #11
0
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);
}
예제 #12
0
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);
    }
}
예제 #13
0
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);
}
예제 #14
0
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);
	}
}
예제 #15
0
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);
}
예제 #16
0
파일: signal.c 프로젝트: DailyR/mudos
__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;
}
예제 #17
0
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));
}
예제 #18
0
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);
	}
}
예제 #19
0
struct SysNetData *Sys_Net_Init()
{
	struct SysNetData *netdata;

	netdata = AllocVec(sizeof(*netdata), MEMF_ANY);
	if (netdata)
	{
		SocketBase = OpenLibrary("bsdsocket.library", 0);
		if (SocketBase)
		{
			netdata->timerport = CreateMsgPort();
			if (netdata->timerport)
			{
				netdata->timerrequest = (struct timerequest *)CreateIORequest(netdata->timerport, sizeof(*netdata->timerrequest));
				if (netdata->timerrequest)
				{
					if (OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)netdata->timerrequest, 0) == 0)
					{
						netdata->timerrequest->tr_node.io_Command = TR_ADDREQUEST;
						netdata->timerrequest->tr_time.tv_secs = 1;
						netdata->timerrequest->tr_time.tv_micro = 0;
						SendIO((struct IORequest *)netdata->timerrequest);
						AbortIO((struct IORequest *)netdata->timerrequest);

						return netdata;
					}

					DeleteIORequest((struct IORequest *)netdata->timerrequest);
				}

				DeleteMsgPort(netdata->timerport);
			}

			CloseLibrary(SocketBase);
		}

		FreeVec(netdata);
	}

	return 0;
}
예제 #20
0
파일: timer.c 프로젝트: michalsc/AROS
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;
}
예제 #21
0
int sendbinfile(void) {
    struct TransferFiles *tf;
    int xprreturkod,cnt=0;
    if(!(XProtocolBase=(struct Library *)OpenLibrary("xprzmodem.library",0L)))
    {
        puttekn("\r\n\nKunde inte öppna xprzmodem.library!\r\n",-1);
        return(2);
    }
    if(!(xio=(struct XPR_IO *)AllocMem(sizeof(struct XPR_IO),MEMF_PUBLIC | MEMF_CLEAR))) {
        puttekn("\r\n\nKunde inte allokera en io-struktur\r\n",-1);
        CloseLibrary(XProtocolBase);
        return(2);
    }
    puttekn("\r\nDu kan börja ta emot med Zmodem.\r\n",-1);
    puttekn("Tryck Ctrl-X några gånger för att avbryta.\r\n",-1);
    AbortIO((struct IORequest *)serreadreq);
    WaitIO((struct IORequest *)serreadreq);
    if(!CheckIO((struct IORequest *)inactivereq)) {
        AbortIO((struct IORequest *)inactivereq);
        WaitIO((struct IORequest *)inactivereq);
    }

    xpr_setup(xio);
    xio->xpr_filename=zinitstring;
    XProtocolSetup(xio);
    xio->xpr_filename="Hejhopp";
    xprreturkod=XProtocolSend(xio);
    Delay(30);
    XProtocolCleanup(xio);
    CloseLibrary(XProtocolBase);
    if(!CheckIO((struct IORequest *)serreadreq)) {
        AbortIO((struct IORequest *)serreadreq);
        WaitIO((struct IORequest *)serreadreq);
        printf("Serreadreq avbruten!!\n");
    }
    if(!CheckIO((struct IORequest *)timerreq)) {
        AbortIO((struct IORequest *)timerreq);
        WaitIO((struct IORequest *)timerreq);
        printf("Timerreq avbruten!!\n");
    }
    FreeMem(xio,sizeof(struct XPR_IO));
    Delay(100);
    serchangereq->IOSer.io_Command=CMD_CLEAR;
    DoIO((struct IORequest *)serchangereq);
    serchangereq->IOSer.io_Command=CMD_FLUSH;
    DoIO((struct IORequest *)serchangereq);
    serreqtkn();
    updateinactive();
    if(Servermem->cfg.logmask & LOG_SENDFILE) {
        for(tf=(struct TransferFiles *)tf_list.mlh_Head; tf->node.mln_Succ; tf=(struct TransferFiles *)tf->node.mln_Succ)
            if(tf->sucess) {
                LogEvent(USAGE_LOG, INFO, "Skickar filen %s till %s",
                         tf->path, getusername(inloggad));
            }
    }
    for(tf=(struct TransferFiles *)tf_list.mlh_Head; tf->node.mln_Succ; tf=(struct TransferFiles *)tf->node.mln_Succ)
        if(tf->sucess) cnt++;
    if(cnt==1) strcpy(outbuffer,"\n\n\rFörde över 1 fil.\n\n\r");
    else sprintf(outbuffer,"\n\n\rFörde över %d filer.\n\n\r",cnt);
    puttekn(outbuffer,-1);
    return(0);
}
예제 #22
0
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
}
예제 #23
0
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);
}
예제 #24
0
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;
}
예제 #25
0
static void AHI_CloseAudio(_THIS)
{
	D(bug("Closing audio...\n"));

	playing=0;

	if(audio_req[0])
	{
		if(audio_req[1])
		{
			D(bug("Break req[1]...\n"));

			AbortIO((struct IORequest *)audio_req[1]);
			WaitIO((struct IORequest *)audio_req[1]);
		}

		D(bug("Break req[0]...\n"));

		AbortIO((struct IORequest *)audio_req[0]);
		WaitIO((struct IORequest *)audio_req[0]);

		if(audio_req[1])
		{
			D(bug("Break AGAIN req[1]...\n"));
			AbortIO((struct IORequest *)audio_req[1]);
			WaitIO((struct IORequest *)audio_req[1]);
		}
// Double abort to be sure to break the dbuffering process.

		SDL_Delay(200);

		D(bug("Reqs breaked, closing device...\n"));
		CloseDevice((struct IORequest *)audio_req[0]);
		D(bug("Device closed, freeing memory...\n"));
		myfree(audio_req[1]);
		D(bug("Memory freed, deleting IOReq...\n")); 
		DeleteIORequest((struct IORequest *)audio_req[0]);
		audio_req[0]=audio_req[1]=NULL;
	}

	D(bug("Freeing mixbuf[0]...\n"));
	if ( mixbuf[0] != NULL ) {
		myfree(mixbuf[0]);
//		SDL_FreeAudioMem(mixbuf[0]);
		mixbuf[0] = NULL;
	}

	D(bug("Freeing mixbuf[1]...\n"));
	if ( mixbuf[1] != NULL ) {
		myfree(mixbuf[1]);
//		SDL_FreeAudioMem(mixbuf[1]);
		mixbuf[1] = NULL;
	}

	D(bug("Freeing audio_port...\n"));

	if ( audio_port != NULL ) {
		DeleteMsgPort(audio_port);
		audio_port = NULL;
	}
	D(bug("...done!\n"));
}
예제 #26
0
static __saveds void net_func(void)
{
	const char *str;
	BYTE od_error;
	struct MsgPort *write_port = NULL, *control_port = NULL;
	struct IOSana2Req *write_io = NULL, *control_io = NULL;
	bool opened = false;
	ULONG read_mask = 0, write_mask = 0, proc_port_mask = 0;
	struct Sana2DeviceQuery query_data = {sizeof(Sana2DeviceQuery)};
	ULONG buffer_tags[] = {
		S2_CopyToBuff, (uint32)copy_to_buff,
		S2_CopyFromBuff, (uint32)copy_from_buff,
		TAG_END
	};

	// Default: error occured
	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 device I/O
	read_port = CreateMsgPort();
	if (read_port == NULL)
		goto quit;
	read_mask = 1 << read_port->mp_SigBit;
	write_port = CreateMsgPort();
	if (write_port == NULL)
		goto quit;
	write_mask = 1 << write_port->mp_SigBit;
	control_port = CreateMsgPort();
	if (control_port == NULL)
		goto quit;

	// Create control IORequest
	control_io = (struct IOSana2Req *)CreateIORequest(control_port, sizeof(struct IOSana2Req));
	if (control_io == NULL)
		goto quit;
	control_io->ios2_Req.io_Message.mn_Node.ln_Type = 0;	// Avoid CheckIO() bug

	// Parse device name
	char dev_name[256];
	ULONG dev_unit;

	str = PrefsFindString("ether");
	if (str) {
		const char *FirstSlash = strchr(str, '/');
		const char *LastSlash = strrchr(str, '/');

		if (FirstSlash && FirstSlash && FirstSlash != LastSlash) {

			// Device name contains path, i.e. "Networks/xyzzy.device"
			const char *lp = str;
			char *dp = dev_name;

			while (lp != LastSlash)
				*dp++ = *lp++;
			*dp = '\0';

			if (strlen(dev_name) < 1)
				goto quit;

			if (sscanf(LastSlash, "/%ld", &dev_unit) != 1)
				goto quit;
		} else {
			if (sscanf(str, "%[^/]/%ld", dev_name, &dev_unit) != 2)
				goto quit;
		}
	} else
		goto quit;

	// Open device
	control_io->ios2_BufferManagement = buffer_tags;
	od_error = OpenDevice((UBYTE *) dev_name, dev_unit, (struct IORequest *)control_io, 0);
	if (od_error != 0 || control_io->ios2_Req.io_Device == 0) {
		printf("WARNING: OpenDevice(<%s>, unit=%d) returned error %d)\n", (UBYTE *)dev_name, dev_unit, od_error);
		goto quit;
	}
	opened = true;

	// Is it Ethernet?
	control_io->ios2_Req.io_Command = S2_DEVICEQUERY;
	control_io->ios2_StatData = (void *)&query_data;
	DoIO((struct IORequest *)control_io);
	if (control_io->ios2_Req.io_Error)
		goto quit;
	if (query_data.HardwareType != S2WireType_Ethernet) {
		WarningAlert(GetString(STR_NOT_ETHERNET_WARN));
		goto quit;
	}

	// Yes, create IORequest for writing
	write_io = (struct IOSana2Req *)CreateIORequest(write_port, sizeof(struct IOSana2Req));
	if (write_io == NULL)
		goto quit;
	memcpy(write_io, control_io, sizeof(struct IOSana2Req));
	write_io->ios2_Req.io_Message.mn_Node.ln_Type = 0;	// Avoid CheckIO() bug
	write_io->ios2_Req.io_Message.mn_ReplyPort = write_port;

	// Configure Ethernet
	control_io->ios2_Req.io_Command = S2_GETSTATIONADDRESS;
	DoIO((struct IORequest *)control_io);
	memcpy(ether_addr, control_io->ios2_DstAddr, 6);
	memcpy(control_io->ios2_SrcAddr, control_io->ios2_DstAddr, 6);
	control_io->ios2_Req.io_Command = S2_CONFIGINTERFACE;
	DoIO((struct IORequest *)control_io);
	D(bug("Ethernet address %08lx %08lx\n", *(uint32 *)ether_addr, *(uint16 *)(ether_addr + 4)));

	// Initialization went well, inform main task
	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 | read_mask | write_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 NetMessage *msg;
			while (msg = (NetMessage *)GetMsg(proc_port)) {
				D(bug("net_proc received %08lx\n", msg->what));
				switch (msg->what) {
					case MSG_CLEANUP:
						remove_all_protocols();
						break;

					case MSG_ADD_MULTI:
						control_io->ios2_Req.io_Command = S2_ADDMULTICASTADDRESS;
						Mac2Host_memcpy(control_io->ios2_SrcAddr, msg->pointer + eMultiAddr, 6);
						DoIO((struct IORequest *)control_io);
						if (control_io->ios2_Req.io_Error == S2ERR_NOT_SUPPORTED) {
							WarningAlert(GetString(STR_NO_MULTICAST_WARN));
							msg->result = noErr;
						} else if (control_io->ios2_Req.io_Error)
							msg->result = eMultiErr;
						else
							msg->result = noErr;
						break;

					case MSG_DEL_MULTI:
						control_io->ios2_Req.io_Command = S2_DELMULTICASTADDRESS;
						Mac2Host_memcpy(control_io->ios2_SrcAddr, msg->pointer + eMultiAddr, 6);
						DoIO((struct IORequest *)control_io);
						if (control_io->ios2_Req.io_Error)
							msg->result = eMultiErr;
						else
							msg->result = noErr;
						break;

					case MSG_ATTACH_PH: {
						uint16 type = msg->type;
						uint32 handler = msg->pointer;

						// Protocol of that type already installed?
						NetProtocol *p = (NetProtocol *)prot_list.lh_Head, *next;
						while ((next = (NetProtocol *)p->ln_Succ) != NULL) {
							if (p->type == type) {
								msg->result = lapProtErr;
								goto reply;
							}
							p = next;
						}

						// Allocate NetProtocol, set type and handler
						p = (NetProtocol *)AllocMem(sizeof(NetProtocol), MEMF_PUBLIC);
						if (p == NULL) {
							msg->result = lapProtErr;
							goto reply;
						}
						p->type = type;
						p->handler = handler;

						// Set up and submit read requests
						for (int i=0; i<NUM_READ_REQUESTS; i++) {
							memcpy(p->read_io + i, control_io, sizeof(struct IOSana2Req));
							p->read_io[i].ios2_Req.io_Message.mn_Node.ln_Name = (char *)p;	// Hide pointer to NetProtocol in node name
							p->read_io[i].ios2_Req.io_Message.mn_Node.ln_Type = 0;			// Avoid CheckIO() bug
							p->read_io[i].ios2_Req.io_Message.mn_ReplyPort = read_port;
							p->read_io[i].ios2_Req.io_Command = CMD_READ;
							p->read_io[i].ios2_PacketType = type;
							p->read_io[i].ios2_Data = p->read_buf[i];
							p->read_io[i].ios2_Req.io_Flags = SANA2IOF_RAW;
							BeginIO((struct IORequest *)(p->read_io + i));
						}

						// Add protocol to list
						AddTail(&prot_list, p);

						// Everything OK
						msg->result = noErr;
						break;
					}

					case MSG_DETACH_PH: {
						uint16 type = msg->type;
						msg->result = lapProtErr;
						NetProtocol *p = (NetProtocol *)prot_list.lh_Head, *next;
						while ((next = (NetProtocol *)p->ln_Succ) != NULL) {
							if (p->type == type) {
								remove_protocol(p);
								msg->result = noErr;
								break;
							}
							p = next;
						}
						break;
					}

					case MSG_WRITE: {
						// Get pointer to Write Data Structure
						uint32 wds = msg->pointer;
						write_io->ios2_Data = (void *)wds;

						// Calculate total packet length
						long len = 0;
						uint32 tmp = wds;
						for (;;) {
							int16 w = ReadMacInt16(tmp);
							if (w == 0)
								break;
							len += w;
							tmp += 6;
						}
						write_io->ios2_DataLength = len;

						// Get destination address
						uint32 hdr = ReadMacInt32(wds + 2);
						Mac2Host_memcpy(write_io->ios2_DstAddr, hdr, 6);

						// Get packet type
						uint32 type = ReadMacInt16(hdr + 12);
						if (type <= 1500)
							type = 0;		// 802.3 packet
						write_io->ios2_PacketType = type;

						// Multicast/broadcard packet?
						if (write_io->ios2_DstAddr[0] & 1) {
							if (*(uint32 *)(write_io->ios2_DstAddr) == 0xffffffff && *(uint16 *)(write_io->ios2_DstAddr + 4) == 0xffff)
								write_io->ios2_Req.io_Command = S2_BROADCAST;
							else
								write_io->ios2_Req.io_Command = S2_MULTICAST;
						} else
							write_io->ios2_Req.io_Command = CMD_WRITE;

						// Send packet
						write_done = false;
						write_io->ios2_Req.io_Flags = SANA2IOF_RAW;
						BeginIO((IORequest *)write_io);
						break;
					}
				}
reply:			D(bug(" net_proc replying\n"));
				ReplyMsg(msg);
			}
		}

		// Packet received
		if (sig & read_mask) {
			D(bug(" packet received, triggering Ethernet interrupt\n"));
			SetInterruptFlag(INTFLAG_ETHER);
			TriggerInterrupt();
		}

		// Packet write completed
		if (sig & write_mask) {
			GetMsg(write_port);
			WriteMacInt32(ether_data + ed_Result, write_io->ios2_Req.io_Error ? excessCollsns : 0);
			write_done = true;
			D(bug(" packet write done, triggering Ethernet interrupt\n"));
			SetInterruptFlag(INTFLAG_ETHER);
			TriggerInterrupt();
		}
	}
quit:

	// Close everything
	remove_all_protocols();
	if (opened) {
		if (CheckIO((struct IORequest *)write_io) == 0) {
			AbortIO((struct IORequest *)write_io);
			WaitIO((struct IORequest *)write_io);
		}
		CloseDevice((struct IORequest *)control_io);
	}
	if (write_io)
		DeleteIORequest(write_io);
	if (control_io)
		DeleteIORequest(control_io);
	if (control_port)
		DeleteMsgPort(control_port);
	if (write_port)
		DeleteMsgPort(write_port);
	if (read_port)
		DeleteMsgPort(read_port);

	// Send signal to main task to confirm termination
	Forbid();
	Signal(MainTask, SIGF_SINGLE);
}
예제 #27
0
int recbinfile(char *dir) {
	int xprreturkod,bytesfree;
	char zmodeminit[100];
	struct InfoData *id;
	BPTR lock;

	ulfiles = 0;
	if(access(dir,0)) {
		puttekn("\r\nDirectoryt finns inte!\r\n",-1);
		return(2);
	}
	if(!(id=AllocMem(sizeof(struct InfoData),MEMF_CLEAR))) {
		puttekn("\r\nKunde inte allokera en InfoData-struktur!\r\n",-1);
		return(2);
	}
	if(!(lock=Lock(dir,ACCESS_READ))) {
		puttekn("\r\nKunde inte få ett Lock för directoryt!\r\n",-1);
		FreeMem(id,sizeof(struct InfoData));
		return(2);
	}
	if(!Info(lock,id)) {
		puttekn("\r\nKunde inte få info om devicet!\r\n",-1);
		UnLock(lock);
		FreeMem(id,sizeof(struct InfoData));
		return(2);
	}
	bytesfree=(id->id_NumBlocks - id->id_NumBlocksUsed)*id->id_BytesPerBlock;
	UnLock(lock);
	FreeMem(id,sizeof(struct InfoData));
	if(bytesfree < Servermem->cfg.diskfree) {
		puttekn("\r\nTyvärr, gränsen för hur full disken får bli har överskridits!\r\n",-1);
		return(2);
	}
	if(Servermem->cfg.ar.preup2) sendrexx(Servermem->cfg.ar.preup2);
	sprintf(zmodeminit,"%s%s",zinitstring,dir);
	if(!(XProtocolBase=(struct Library *)OpenLibrary("xprzmodem.library",0L))) {
		puttekn("\r\n\nKunde inte öppna xprzmodem.library!\r\n",-1);
		return(2);
	}
	if(!(xio=(struct XPR_IO *)AllocMem(sizeof(struct XPR_IO),MEMF_PUBLIC | MEMF_CLEAR))) {
		puttekn("\r\n\nKunde inte allokera en io-struktur\r\n",-1);
		CloseLibrary(XProtocolBase);
		return(2);
	}
	NewList((struct List *)&tf_list);

	puttekn("\r\nDu kan börja sända med Zmodem. Du kan nu skicka fler filer!",-1);
	puttekn("\r\nTryck Ctrl-X några gånger för att avbryta.\r\n",-1);
	AbortIO((struct IORequest *)serreadreq);
	WaitIO((struct IORequest *)serreadreq);
	if(!CheckIO((struct IORequest *)inactivereq)) {
		AbortIO((struct IORequest *)inactivereq);
		WaitIO((struct IORequest *)inactivereq);
	}
	xpr_setup(xio);
	xio->xpr_filename=zmodeminit;
	XProtocolSetup(xio);
	xprreturkod=XProtocolReceive(xio);
	Delay(30);
	XProtocolCleanup(xio);
	CloseLibrary(XProtocolBase);
	if(!CheckIO((struct IORequest *)serreadreq)) {
		AbortIO((struct IORequest *)serreadreq);
		WaitIO((struct IORequest *)serreadreq);
		printf("Serreadreq avbruten!!\n");
	}
	if(!CheckIO((struct IORequest *)timerreq)) {
		AbortIO((struct IORequest *)timerreq);
		WaitIO((struct IORequest *)timerreq);
		printf("Timerreq avbruten!!\n");
	}
	FreeMem(xio,sizeof(struct XPR_IO));
	Delay(100);
	serchangereq->IOSer.io_Command=CMD_CLEAR;
	DoIO((struct IORequest *)serchangereq);
	serchangereq->IOSer.io_Command=CMD_FLUSH;
	DoIO((struct IORequest *)serchangereq);
	serreqtkn();
	updateinactive();
	if(Servermem->cfg.ar.postup2) sendrexx(Servermem->cfg.ar.postup2);
/*	if(Servermem->cfg.logmask & LOG_RECFILE) {
		sprintf(outbuffer,"Tar emot filen %s från %s",xprfilnamn,getusername(inloggad));
		logevent(outbuffer);
	}
	if(xprreturkod) {
		puttekn("\r\n\nÖverföringen lyckades.\r\n",-1);
		sprintf(outbuffer,"Hastighet: %d cps\n\r",cps);
		puttekn(outbuffer,-1);
		return(0);
	} else {
		puttekn("\r\n\nÖverföringen misslyckades.\r\n",-1);
		return(2);
	} Removed by Tomas Kärki 22/1 1996 */

	if(ulfiles > 0) {
		puttekn("\r\n\nÖverföringen lyckades.\r\n",-1);
		return(0);
	}
	else {
		puttekn("\r\n\nÖverföringen misslyckades.\r\n",-1);
		return(2);
	}
}
예제 #28
0
int recbinfile(char *dir) {
    int xprreturkod;
    char zmodeminit[100];

    ulfiles = 0;
    if(access(dir,0)) {
        puttekn("\r\nDirectoryt finns inte!\r\n",-1);
        return 2;
    }

    if(Servermem->cfg.diskfree != 0
            && !HasPartitionEnoughFreeSpace(dir, Servermem->cfg.diskfree)) {
        puttekn("\r\nTyvärr, gränsen för hur full disken får bli har överskridits!\r\n",-1);
        return 2;
    }

    if(Servermem->cfg.ar.preup2) {
        sendautorexx(Servermem->cfg.ar.preup2);
    }
    sprintf(zmodeminit,"%s%s",zinitstring,dir);
    if(!(XProtocolBase = (struct Library *) OpenLibrary("xprzmodem.library", 0L))) {
        puttekn("\r\n\nKunde inte öppna xprzmodem.library!\r\n",-1);
        return 2;
    }
    if(!(xio = (struct XPR_IO *)
               AllocMem(sizeof(struct XPR_IO), MEMF_PUBLIC | MEMF_CLEAR))) {
        puttekn("\r\n\nKunde inte allokera en io-struktur\r\n",-1);
        CloseLibrary(XProtocolBase);
        return 2;
    }
    NewList((struct List *)&tf_list);

    puttekn("\r\nDu kan börja sända med Zmodem. Du kan nu skicka fler filer!",-1);
    puttekn("\r\nTryck Ctrl-X några gånger för att avbryta.\r\n",-1);
    AbortIO((struct IORequest *)serreadreq);
    WaitIO((struct IORequest *)serreadreq);
    if(!CheckIO((struct IORequest *)inactivereq)) {
        AbortIO((struct IORequest *)inactivereq);
        WaitIO((struct IORequest *)inactivereq);
    }
    xpr_setup(xio);
    xio->xpr_filename = zmodeminit;
    XProtocolSetup(xio);
    xprreturkod = XProtocolReceive(xio);
    Delay(30);
    XProtocolCleanup(xio);
    CloseLibrary(XProtocolBase);
    if(!CheckIO((struct IORequest *)serreadreq)) {
        AbortIO((struct IORequest *)serreadreq);
        WaitIO((struct IORequest *)serreadreq);
        printf("Serreadreq avbruten!!\n");
    }
    if(!CheckIO((struct IORequest *)timerreq)) {
        AbortIO((struct IORequest *)timerreq);
        WaitIO((struct IORequest *)timerreq);
        printf("Timerreq avbruten!!\n");
    }
    FreeMem(xio,sizeof(struct XPR_IO));
    Delay(100);
    serchangereq->IOSer.io_Command=CMD_CLEAR;
    DoIO((struct IORequest *)serchangereq);
    serchangereq->IOSer.io_Command=CMD_FLUSH;
    DoIO((struct IORequest *)serchangereq);
    serreqtkn();
    updateinactive();
    if(Servermem->cfg.ar.postup2) {
        sendautorexx(Servermem->cfg.ar.postup2);
    }

    if(ulfiles > 0) {
        puttekn("\r\n\nÖverföringen lyckades.\r\n",-1);
        return 0;
    }
    else {
        puttekn("\r\n\nÖverföringen misslyckades.\r\n",-1);
        return 2;
    }
}
예제 #29
0
__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);
}
예제 #30
0
static void
Slave( struct ExecBase* SysBase )
{
  struct AHIAudioCtrlDrv* AudioCtrl;
  struct DriverBase*      AHIsubBase;
  struct DeviceBase* DeviceBase;
  BOOL                    running;
  ULONG                   signals;

  AudioCtrl  = (struct AHIAudioCtrlDrv*) FindTask( NULL )->tc_UserData;
  AHIsubBase = (struct DriverBase*) dd->ahisubbase;
  DeviceBase = (struct DeviceBase*) AHIsubBase;

  dd->slavesignal = AllocSignal( -1 );

  if( dd->slavesignal != -1 )
  {
    struct MsgPort*    ahi_mp           = NULL;
    struct AHIRequest* ahi_iorequest    = NULL;
    APTR               ahi_iocopy       = NULL;
    BYTE               ahi_device       = -1;

    struct AHIRequest* ahi_io[ 2 ]      = { NULL,  NULL };
    BOOL               ahi_io_used[ 2 ] = { FALSE, FALSE };

    ULONG              frame_length     = 0;

    ahi_mp = CreateMsgPort();

    if( ahi_mp != NULL )
    {
      ahi_iorequest = CreateIORequest( ahi_mp, sizeof( struct AHIRequest ) );

      if( ahi_iorequest != NULL )
      {
	ahi_iorequest->ahir_Version = 4;

	ahi_device = OpenDevice( AHINAME, dd->unit,
				 (struct IORequest*) ahi_iorequest, 0 );

	if( ahi_device == 0 )
	{
	  struct Library* AHIBase = (struct Library*) ahi_iorequest->ahir_Std.io_Device;

	  ahi_iocopy = AllocVec( sizeof( *ahi_iorequest ), MEMF_ANY );

	  if( ahi_iocopy != NULL )
	  {
	    bcopy( ahi_iorequest, ahi_iocopy, sizeof( *ahi_iorequest ) );

	    ahi_io[ 0 ] = ahi_iorequest;
	    ahi_io[ 1 ] = ahi_iocopy;
    
	    // Everything set up. Tell Master we're alive and healthy.

	    Signal( (struct Task*) dd->mastertask,
		    1L << dd->mastersignal );

	    running = TRUE;

	    // The main playback loop follow

	    while( running )
	    {
	      int skip_mix;
	      APTR tmp_buff;
	      struct AHIRequest* tmp_io;
	      
	      if( ahi_io_used[ 0 ] )
	      {
		LONG  err;
		ULONG mask = ( SIGBREAKF_CTRL_C |
			       (1L << dd->slavesignal) |
			       (1L << ahi_mp->mp_SigBit) );
	      
		signals = Wait( mask );

		if( signals & ( SIGBREAKF_CTRL_C |
				(1L << dd->slavesignal) ) ) 
		{
		  running = FALSE;
		  break;
		}

		err = WaitIO( (struct IORequest*) ahi_io[ 0 ] );

		if( err != 0 )
		{
		  KPrintF( DRIVER ": AHI device error %ld\n", err );
//		  running = FALSE;
		  break;
		}
	      }

	      skip_mix = CallHookPkt( AudioCtrl->ahiac_PreTimerFunc,
				      (Object*) AudioCtrl, 0 );

	      CallHookPkt( AudioCtrl->ahiac_PlayerFunc, AudioCtrl, NULL );
		
	      if( ! skip_mix )
	      {
		CallHookPkt( AudioCtrl->ahiac_MixerFunc, AudioCtrl,
			     dd->mixbuffers[ 0 ] );
	      }
		
	      CallHookPkt( AudioCtrl->ahiac_PostTimerFunc, (Object*) AudioCtrl, 0 );

	      if( frame_length == 0 )
	      {
		frame_length = AHI_SampleFrameSize( AudioCtrl->ahiac_BuffType );
	      }
	      
	      ahi_io[ 0 ]->ahir_Std.io_Command = CMD_WRITE;
	      ahi_io[ 0 ]->ahir_Std.io_Data    = dd->mixbuffers[ 0 ];
	      ahi_io[ 0 ]->ahir_Std.io_Length  = ( AudioCtrl->ahiac_BuffSamples *
						   frame_length );
	      ahi_io[ 0 ]->ahir_Std.io_Offset  = 0;
	      ahi_io[ 0 ]->ahir_Frequency      = AudioCtrl->ahiac_MixFreq;
	      ahi_io[ 0 ]->ahir_Type           = AudioCtrl->ahiac_BuffType;
	      ahi_io[ 0 ]->ahir_Volume         = 0x10000;
	      ahi_io[ 0 ]->ahir_Position       = 0x08000;
	      ahi_io[ 0 ]->ahir_Link           = ( ahi_io_used[ 1 ] ?
						   ahi_io[ 1 ] : NULL );

	      SendIO( (struct IORequest*) ahi_io[ 0 ] );
    
	      tmp_io = ahi_io[ 0 ];
	      ahi_io[ 0 ] = ahi_io[ 1 ];
	      ahi_io[ 1 ] = tmp_io;

	      tmp_buff = dd->mixbuffers[ 0 ];
	      dd->mixbuffers[ 0 ] = dd->mixbuffers[ 1 ];
	      dd->mixbuffers[ 1 ] = tmp_buff;
	      
	      ahi_io_used[ 0 ] = ahi_io_used[ 1 ];
	      ahi_io_used[ 1 ] = TRUE;
	    }

	    
	    if( ahi_io_used[ 0 ] )
	    {
	      AbortIO( (struct IORequest*) ahi_io[ 0 ] );
	      WaitIO( (struct IORequest*) ahi_io[ 0 ] );
	    }

	    if( ahi_io_used[ 1 ] )
	    {
	      AbortIO( (struct IORequest*) ahi_io[ 1 ] );
	      WaitIO( (struct IORequest*) ahi_io[ 1 ] );
	    }
	    
	    FreeVec( ahi_iocopy );
	  }

	  CloseDevice( (struct IORequest*) ahi_iorequest );
	}

	DeleteIORequest( (struct IORequest*) ahi_iorequest );
      }

      DeleteMsgPort( ahi_mp );
    }
  }

  FreeSignal( dd->slavesignal );
  dd->slavesignal = -1;

  Forbid();

  // Tell the Master we're dying

  Signal( (struct Task*) dd->mastertask,
          1L << dd->mastersignal );

  dd->slavetask = NULL;

  // Multitaking will resume when we are dead.
}