Esempio n. 1
0
//------------------------------------------------------------------------
// getchar for apps
//------------------------------------------------------------------------
char sh_getchar()
{
	FIFO f = OS_GetParam();
	int val;
	while(!OS_Read(f, &val)) 
		OS_Yield();
	return (char)val;
}
Esempio n. 2
0
/*
	Load a binary image, return # bytes read.
*/
int  
data_load_binary(const char *type, const char *path, const char *filename,
				 u8 * loadat, int swap, int fileoffs, int imagesize, 
				 int maxsize)
{
	OSRef       ref;
	OSSize      size;
	OSError     err;
	OSSpec      spec;

	size = data_find_binary(path, filename, &spec);

	if (!size) {
		if (*filename) {
			command_logger(_L |LOG_USER|LOG_ERROR, 
						   _("Cannot find '%s' in path:\n'%s'\n"), 
						   filename, path);
		}
		return 0;
	}
	logger(_L|L_0, _("Loading %s image %s... "), type, OS_SpecToString1(&spec));

	if (imagesize)
		size = imagesize;
	else if (size - fileoffs > maxsize) {
		command_logger(_L | LOG_WARN | LOG_USER, _("%s too long, only %d bytes of %d read... "),
			 OS_SpecToString1(&spec), maxsize, size);
		size = maxsize - fileoffs;
	}

	if ((err = OS_Open(&spec, OSReadOnly, &ref)) != OS_NOERR) {
		OSerror(err, "\n");
		return 0;
	}

	if ((err = OS_Seek(ref, OSSeekAbs, fileoffs)) != OS_NOERR ||
		(err = OS_Read(ref, loadat, &size)) != OS_NOERR) {
		OSerror(err, _("could not read\n"));
		return 0;
	}

	if (swap) {
		logger(_L, _("swapping bytes... "));
		swab((const void *) loadat, (void *) loadat, size);
	}

	logger(_L| L_0, _("done\n"));

	OS_Close(ref);
	return size;
}
Esempio n. 3
0
void PrintFIFO (void) {
	FIFO f = (FIFO)OS_GetParam(); 
	char *s = "               "; 
	int i; 
	int fi; 
	
	i = 0; 
	while(i < 6) {
		if(OS_Read(f,&fi)) {
			s[i++] = (char)fi; 
		} 
		else {
			OS_Yield(); 
		}
	}
	OS_Wait(S_LCD); 
	OS_Create(PrintString, (int)s, PERIODIC, 50); 
}
Esempio n. 4
0
/*
 *----------------------------------------------------------------------
 *
 * FillBuffProc --
 *
 *      Reads bytes from the ipcFd, supplies bytes to a stream client.
 *
 *----------------------------------------------------------------------
 */
static void FillBuffProc(FCGX_Stream * stream)
{
	FCGX_Stream_Data *data = (FCGX_Stream_Data *) stream->data;
	FCGI_Header header;
	int headerLen = 0;
	int status, count;

	for (;;) {
		/*
		 * If data->buff is empty, do a read.
		 */
		if (stream->rdNext == data->buffStop) {
			count = OS_Read(data->reqDataPtr->ipcFd,
				(char *)data->buff, data->bufflen);
			if (count <= 0) {
				SetError(stream,
					(count ==
						0 ? FCGX_PROTOCOL_ERROR :
						OS_Errno));
				return;
			}
			stream->rdNext = data->buff;
			data->buffStop = data->buff + count;
		}
		/*
		 * Now data->buff is not empty.  If the current record contains
		 * more content bytes, deliver all that are present in data->buff.
		 */
		if (data->contentLen > 0) {
			count = min(data->contentLen,
				data->buffStop - stream->rdNext);
			data->contentLen -= count;
			if (!data->skip) {
				stream->wrNext = stream->stop =
					stream->rdNext + count;
				return;
			} else {
				stream->rdNext += count;
				if (data->contentLen > 0) {
					continue;
				} else {
					data->skip = FALSE;
				}
			}
		}
		/*
		 * If the current record (whose content has been fully consumed by
		 * the client) was padded, skip over the padding bytes.
		 */
		if (data->paddingLen > 0) {
			count = min(data->paddingLen,
				data->buffStop - stream->rdNext);
			data->paddingLen -= count;
			stream->rdNext += count;
			if (data->paddingLen > 0) {
				continue;
			}
		}
		/*
		 * All done with the current record, including the padding.
		 * If we're in a recursive call from ProcessHeader, deliver EOF.
		 */
		if (data->eorStop) {
			stream->stop = stream->rdNext;
			stream->isClosed = TRUE;
			return;
		}
		/*
		 * Fill header with bytes from the input buffer.
		 */
		count = min((int)sizeof(header) - headerLen,
			data->buffStop - stream->rdNext);
		memcpy(((char *)(&header)) + headerLen, stream->rdNext, count);
		headerLen += count;
		stream->rdNext += count;
		if (headerLen < sizeof(header)) {
			continue;
		};
		headerLen = 0;
		/*
		 * Interpret header.  eorStop prevents ProcessHeader from reading
		 * past the end-of-record when using stream to read content.
		 */
		data->eorStop = TRUE;
		stream->stop = stream->rdNext;
		status = ProcessHeader(header, stream);
		data->eorStop = FALSE;
		stream->isClosed = FALSE;
		switch (status) {
		case STREAM_RECORD:
			/*
			 * If this stream record header marked the end of stream
			 * data deliver EOF to the stream client, otherwise loop
			 * and deliver data.
			 *
			 * XXX: If this is final stream and
			 * stream->rdNext != data->buffStop, buffered
			 * data is next request (server pipelining)?
			 */
			if (data->contentLen == 0) {
				stream->wrNext = stream->stop = stream->rdNext;
				stream->isClosed = TRUE;
				return;
			}
			break;
		case SKIP:
			data->skip = TRUE;
			break;
		case BEGIN_RECORD:
			/*
			 * If this header marked the beginning of a new
			 * request, return role information to caller.
			 */
			return;
			break;
		case MGMT_RECORD:
			break;
		default:
			SetError(stream, status);
			return;
			break;
		}
	}
}
Esempio n. 5
0
/*
 *	Search paths for a file matching 'filename'.
 *	If found, and it is a valid GRAM-Kracker file,
 *	set 'spec' to point to it, and return its header info in 'header'
 *	
 */
int data_find_gram_kracker(const char *path, const char *filename, 
						   OSSpec *spec, gram_kracker_header *header)
{
	int size;
	fiad_logger_func old;
	int old_unknownfileistext;
	fiad_tifile tf;
	OSError err;
	OSRef ref;
	bool is_v9t9_file;

	memset(header, 0, sizeof(gram_kracker_header));

	/* Can we find the file? */
	size = data_find_binary(path, filename, spec);
	if (!size)
		return 0;

	/* See if it's a V9t9/TIFILES file or perhaps a plain binary */
	old = fiad_set_logger(0L);
	old_unknownfileistext = unknownfileistext;
	unknownfileistext = 0;

	if (fiad_tifile_setup_spec_with_spec(&tf, spec) != OS_NOERR) {
		goto error_exit;
	}

	/* Is it a V9t9 file? */
	if (fiad_tifile_get_info(&tf)) {
		if (!(tf.fdr.flags & ff_program)) {
			command_logger(_L|LOG_ERROR|LOG_USER, _("GRAM Kracker segment '%s' is not a PROGRAM file (it's %s)\n"),
				   OS_SpecToString1(spec), fiad_catalog_get_file_type_string(&tf.fdr));
			goto error_exit;
		}
		// allow enough space for the data, header, and extra sector
		if (FDR_FILESIZE(&tf.fdr) > 8198+256) {
			command_logger(_L|LOG_ERROR|LOG_USER, _("GRAM Kracker segment '%s' is too long\n"
				   "to be a segment (%d bytes > 8192+6 bytes)\n"),
				   OS_SpecToString1(spec), FDR_FILESIZE(&tf.fdr));
			goto error_exit;
		}
		is_v9t9_file = true;
	} else {
		is_v9t9_file = false;
	}

	/* Read header from first sector */
	if (is_v9t9_file) {
		u16 headersize = 6;
		if (fiad_tifile_open_file(&tf, newfileformat, 
								   false /*create*/,
								   false /*always*/,
								   true /*readonly*/) != OS_NOERR 
			||
			fiad_tifile_read_binary_image(&tf,
										  (u8 *)header,
										  headersize,
										  &headersize) != 0
			||
			headersize < 6)
		{
			command_logger(_L|LOG_ERROR|LOG_USER, _("Could not read signature for GRAM Kracker segment in V9t9 file '%s' (%s)\n"),
				   OS_SpecToString1(spec), OS_GetErrText(tf.error));
			goto error_exit;
		}
		header->absolute_image_file_offset = sizeof(v9t9_fdr) + 6;
	} else {
		OSSize headersize = 6;

		if ((err = OS_Open(spec, OSReadOnly, &ref)) != OS_NOERR ||
			(err = OS_Read(ref, (void *)header, &headersize)) != OS_NOERR ||
			(err = OS_Close(ref)) != OS_NOERR)
		{
			command_logger(_L|LOG_ERROR|LOG_USER, _("Could not read signature for GRAM Kracker segment in binary file '%s' (%s)\n"),
				   OS_SpecToString1(spec), OS_GetErrText(err));
			goto error_exit;
		}
		header->absolute_image_file_offset = 6;
	}

	/* Make header suitable for v9t9 */
	header->address = TI2HOST(header->address);
	header->length = TI2HOST(header->length);

	if (header->more_to_load == 0x80)
	{
		command_logger(_L|LOG_ERROR|LOG_USER, _("GRAM Kracker segment '%s' is a 'UTIL' segment (not supported)\n"),
			   OS_SpecToString1(spec));
		goto error_exit;
	}

	if (header->gk_type == 0x00 ||
		header->gk_type == 0xff ||
		header->gk_type > GK_TYPE_ROM_2)
	{
		command_logger(_L|LOG_ERROR|LOG_USER, _("GRAM Kracker segment '%s' is not a ROM file (got >%02X)\n"),
			   OS_SpecToString1(spec), header->gk_type);
		goto error_exit;
	}

	fiad_set_logger(old);
	return size;

error_exit:
	fiad_set_logger(old);
	unknownfileistext = old_unknownfileistext;
	return 0;
}
Esempio n. 6
0
/* Device: > 500ms */ 
void FIFOBuzz(void) {
	FIFO f;
	int fi; 
	unsigned int i; 

	f = (FIFO)OS_GetParam(); 
	
	while (1) {
		if(OS_Read(f,&fi)) {
			/* Fifo for charactar output */
			OS_Wait(S_BUZZ_OUTPUT); 
			switch((char)fi) {
				case 'a': dot(); dash(); break; 
				case 'b': dash(); dot(); dot(); dot(); break; 
				case 'c': dash(); dot(); dash(); dot(); break; 
				case 'd': dash(); dot(); dot(); break;
				case 'e': dot(); break; 
				case 'f': dot(); dot(); dash(); dot(); break; 
				case 'g': dash(); dash(); dot(); break; 
				case 'h': dot(); dot(); dot(); dot(); break; 
				case 'i': dot(); dot(); break; 
				case 'j': dot(); dash(); dash(); dash(); break; 
				case 'k': dash(); dot(); dash(); break; 
				case 'l': dot(); dash(); dot(); dot(); break; 
				case 'm': dash(); dash(); break; 
				case 'n': dash(); dot(); break; 
				case 'o': dash(); dash(); dash(); break; 
				case 'p': dot(); dash(); dash(); dot(); break; 
				case 'q': dash(); dash(); dot(); dash(); break; 
				case 'r': dot(); dash(); dot(); break; 
				case 's': dot(); dot(); dot(); break; 
				case 't': dash(); break; 
				case 'u': dot(); dot(); dash(); break; 
				case 'v': dot(); dot(); dot(); dash(); break; 
				case 'w': dot(); dash(); dash(); break; 
				case 'x': dash(); dot(); dot(); dash(); break; 
				case 'y': dash(); dot(); dash(); dash(); break; 
				case 'z': dash(); dash(); dot(); dot(); break; 
				case '1': dot(); dash(); dash(); dash(); dash(); break; 
				case '2': dot(); dot(); dash(); dash(); dash(); break; 
				case '3': dot(); dot(); dot(); dash(); dash(); break; 
				case '4': dot(); dot(); dot(); dot(); dash(); break; 
				case '5': dot(); dot(); dot(); dot(); dot(); break; 
				case '6': dash(); dot(); dot(); dot(); dot(); break; 
				case '7': dash(); dash(); dot(); dot(); dot(); break; 
				case '8': dash(); dash(); dash(); dot(); dot(); break; 
				case '9': dash(); dash(); dash(); dash(); dot(); break; 
				case '0': dash(); dash(); dash(); dash(); dash(); break; 
				default: OS_Yield(); break; 
			}
			OS_Signal(S_BUZZ_FIFO); 
			/* Wait for the speaker to settle...prevents the microphone from hearing it. */ 
			OS_Yield();
			/* When all buzz processes have finished, signal that output is complete. */ 
			OS_Wait(S_BUZZ); 
			OS_Signal(S_BUZZ_OUTPUT); 
			OS_Signal(S_BUZZ); 
		}
		OS_Yield();
	}
}