Exemple #1
0
/*===========================================================================*
 *				dsp_dma_setup
 *===========================================================================*/
PRIVATE void dsp_dma_setup(phys_bytes address, int count)
{
	pvb_pair_t pvb[9];


	dprint("Setting up %d bit DMA\n", DspBits);

	if(DspBits == 8) {   /* 8 bit sound */
		count--;     

		pv_set(pvb[0], DMA8_MASK, SB_DMA_8 | 0x04);      /* Disable DMA channel */
		pv_set(pvb[1], DMA8_CLEAR, 0x00);		       /* Clear flip flop */

		/* set DMA mode */
		pv_set(pvb[2], DMA8_MODE, (DmaMode == DEV_WRITE_S ? DMA8_AUTO_PLAY : DMA8_AUTO_REC)); 

		pv_set(pvb[3], DMA8_ADDR, (address >>  0) & 0xff);        /* Low_byte of address */
		pv_set(pvb[4], DMA8_ADDR, (address >>  8) & 0xff);        /* High byte of address */
		pv_set(pvb[5], DMA8_PAGE, (address >> 16) & 0xff);        /* 64K page number */
		pv_set(pvb[6], DMA8_COUNT, (count >> 0) & 0xff);          /* Low byte of count */
		pv_set(pvb[7], DMA8_COUNT, (count >> 8) & 0xff);          /* High byte of count */
		pv_set(pvb[8], DMA8_MASK, SB_DMA_8);	       /* Enable DMA channel */

		sys_voutb(pvb, 9);
	} else {  /* 16 bit sound */
Exemple #2
0
/*===========================================================================*
 *				printer_intr				     *
 *===========================================================================*/
static void printer_intr(unsigned int UNUSED(mask))
{
/* This function does the actual output to the printer. This is called on an
 * interrupt message sent from the generic interrupt handler that 'forwards'
 * interrupts to this driver. The generic handler did not reenable the printer
 * IRQ yet! 
 */

  u32_t status;
  pvb_pair_t char_out[3];

  if (oleft == 0) {
	/* Nothing more to print.  Turn off printer interrupts in case they
	 * are level-sensitive as on the PS/2.  This should be safe even
	 * when the printer is busy with a previous character, because the
	 * interrupt status does not affect the printer.
	 */
	if(sys_outb(port_base + 2, PR_SELECT) != OK) {
		printf("printer: sys_outb of %x failed\n", port_base+2);
		panic("sys_outb failed");
	}
	if(sys_irqenable(&irq_hook_id) != OK) {
		panic("sys_irqenable failed");
	}
	return;
  }

  do {
	/* Loop to handle fast (buffered) printers.  It is important that
	 * processor interrupts are not disabled here, just printer interrupts.
	 */
	if(sys_inb(port_base + 1, &status) != OK) {
		printf("printer: sys_inb of %x failed\n", port_base+1);
		panic("sys_inb failed");
	}
	if ((status & STATUS_MASK) == BUSY_STATUS) {
		/* Still busy with last output.  This normally happens
		 * immediately after doing output to an unbuffered or slow
		 * printer.  It may happen after a call from prepare_output or
		 * pr_restart, since they are not synchronized with printer
		 * interrupts.  It may happen after a spurious interrupt.
		 */
		if(sys_irqenable(&irq_hook_id) != OK) {
			panic("sys_irqenable failed");
		}
		return;
	}
	if ((status & STATUS_MASK) == NORMAL_STATUS) {
		/* Everything is all right.  Output another character. */
		pv_set(char_out[0], port_base, *optr);	
		optr++;
		pv_set(char_out[1], port_base+2, ASSERT_STROBE);
		pv_set(char_out[2], port_base+2, NEGATE_STROBE);
		if(sys_voutb(char_out, 3) != OK) {
			/* request series of port outb */
			panic("sys_voutb failed");
		}

		user_vir_d++;
		user_left--;
	} else {
		/* Error.  This would be better ignored (treat as busy). */
		done_status = status;
		output_done();
		if(sys_irqenable(&irq_hook_id) != OK) {
			panic("sys_irqenable failed");
		}
		return;
	}
  }
  while (--oleft != 0);

  /* Finished printing chunk OK. */
  done_status = OK;
  output_done();
  if(sys_irqenable(&irq_hook_id) != OK) {
	panic("sys_irqenable failed");
  }
}
Exemple #3
0
/*--------------------------------------------------------------------------
 Process a network message generated by this module on another computer.

 Note: player deletion should be noticed by some other handler, and
 should cause a call to pv_deletePlayer().

 Large variables will be handled as follows:
 The buffer is broken into pieces.
 The first piece is sent with tag pv_PLAYERDATA_INITIAL_PACKET_ID
 and has a header structure describing the length, owner, and key of the
 incoming variables.
 Subsequent pieces are sent with tag pv_PLAYERDATA_BODY_PACKET_ID,
 and lack headers.

 When a first piece comes in, it goes into a holding area for that source;
 When middle or last pieces come in, they are appended to the holding area;
 When a last piece comes in, the holding area is copied to the real variable
 area, and the user code is informed.

 On success,
	if not the final packet,
		Returns dp_RES_EMPTY.
	else,
		Returns dp_RES_OK, and places a tagged dp_user_playerData_packet_t
		in buffer.
--------------------------------------------------------------------------*/
dp_result_t pv_handlePacket(pv_t *pv, size_t len, void *buf)
{
	dp_packetType_t *tag = (dp_packetType_t *)buf;
	pv_peer_t *peer;
	pv_var_t *pvar;
	dp_result_t err;
	dpid_t id;

#ifdef DPRINTBUFS
	DPRINT(("pv_handlePacket(pv, %d, ", len));
	dprint_buf(buf, len);
#endif
	if (!pv)
		return dp_RES_BUG;

	if (*tag == pv_PLAYERDATA_INITIAL_PACKET_ID) {
		pv_playerData_initial_packet_t *body = (pv_playerData_initial_packet_t *)((char *)buf + sizeof(dp_packetType_t));
		void *payload = ((char *)body) + sizeof(pv_playerData_initial_packet_t);
		size_t datalen = len - sizeof(dp_packetType_t) - sizeof(pv_playerData_initial_packet_t);

		if (datalen < 1 || datalen > pv_PLAYERDATA_INITIAL_MAXLEN)
			return dp_RES_BUG;
		/* call dpSwapPvUpdateInitial to byte swap body */
		dpSwapPvUpdateInitial(body);
		id = body->id;

		/* Locate the sender's holding area and check for sanity. */
		peer = (pv_peer_t *)assoctab_subscript(pv->peers, id);
		if (!peer) {
			/* No peer yet.  Create one.  Hope we can trust id. */
			peer = pv_addPlayer(pv, id);
			if (!peer) {
				DPRINT(("pv_handlePacket: pv_addPlayer returns NULL\n"));
				return dp_RES_NOMEM;
			}
		}
		pvar = &peer->incoming;
		if (peer->allocated < body->len) {
			void *p = dp_REALLOC(pvar->buf, body->len);
			if (!p) return dp_RES_NOMEM;
			pvar->buf = p;
			peer->allocated = body->len;
		}
		/* Clear the holding area & copy this in. */
		pvar->key = body->key;
		pvar->flags = body->flags;
		pvar->len = body->len;
		pvar->crc = body->crc;
		memcpy(pvar->type, body->type, sizeof(pvar->type));
		memcpy(pvar->buf, payload, datalen);
		pvar->offset = datalen;
		DPRINT(("pv_handlePacket: after 1st packet, offset is %d, len is %d\n", pvar->offset, pvar->len));

	} else if (*tag == pv_PLAYERDATA_BODY_PACKET_ID) {
		pv_playerData_body_packet_t *body = (pv_playerData_body_packet_t *)((char *)buf + sizeof(dp_packetType_t));
		void *payload = ((char *)body) + sizeof(pv_playerData_body_packet_t);
		size_t datalen = len - sizeof(dp_packetType_t) - sizeof(pv_playerData_body_packet_t);

		if (datalen < 1 || datalen > pv_PLAYERDATA_BODY_MAXLEN) {
			DPRINT(("pv_handlePacket: datalen\n"));
			return dp_RES_BUG;
		}
		/* call dpSwapPvUpdate to byte swap body */
		dpSwapPvUpdate(body);
		id = body->id;
		/* Locate the sender's holding area and check for sanity. */
		peer = (pv_peer_t *)assoctab_subscript(pv->peers, id);
		if (!peer) {
			DPRINT(("pv_handlePacket: no variables for player %d\n", id));
			return dp_RES_BAD;
		}
		pvar = &peer->incoming;
		if (peer->allocated < pvar->offset + datalen) {
			DPRINT(("pv_handlePacket: allocated %d need %d + %d\n", peer->allocated, pvar->offset, datalen));
			return dp_RES_BUG;
		}

		/* Append to holding area. */
		memcpy((char *)pvar->buf + pvar->offset, payload, datalen);
		pvar->offset += datalen;
		DPRINT(("pv_handlePacket: after: id %d, key %d, offset %d, len %d\n", id, pvar->key, pvar->offset, pvar->len));

	} else
		return dp_RES_EMPTY;	/* no error - but no pv packet recognized */

	if (pvar->offset == pvar->len) {
		/* The variable has arrived! Obey the value change it carries.
		 * Don't echo to other machines!
		 */
		long newcrc = dp_crc32((unsigned char *)pvar->buf, pvar->len);
		DPRINT(("pv_handlePacket: got crc %x\n", newcrc));
		if (newcrc != pvar->crc) {
			DPRINT(("pv_handlePacket: bad crc %x, expected %x!\n", newcrc, pvar->crc));
			return dp_RES_BAD;
		}

		err = pv_set(pv, id, pvar->key, pvar->len, pvar->buf, dp_PLAYERDATA_FLAG_NOFLOOD);
		DPRINT(("pv_handlePacket: called pv_set; returning err %d\n", err));
		if (err == dp_RES_OK) {
			dp_user_playerData_packet_t *body = (dp_user_playerData_packet_t *)((char *)buf + sizeof(dp_packetType_t));
			/* Notify local players - overwrite buffer with user packet. */
			*tag = dp_USER_PLAYERDATA_PACKET_ID;
			body->len = pvar->len;
			body->id = id;
			body->key = pvar->key;
			body->data = pvar->buf;
			return dp_RES_OK;
		}
		return err;
	}
	return dp_RES_EMPTY;
}