Example #1
0
void WriteA (void) {
	FIFO f = (FIFO)OS_GetParam();

	OS_Write(f,(int)'J'); 
	OS_Yield(); 
	OS_Write(f,(int)'o'); 
	OS_Yield(); 
	OS_Write(f,(int)'e'); 
	OS_Signal(S_LOGO); 
}
Example #2
0
void Write1 (void) {
	FIFO f = (FIFO)OS_GetParam(); 
	
	OS_Wait(S_LOGO); 
	OS_Write(f,(int)'l'); 
	OS_Yield();
	OS_Write(f,(int)'O'); 
	OS_Yield();
	OS_Write(f,(int)'S'); 
	OS_Signal(S_LOGO);
}
Example #3
0
/*
 *	Send a byte to the PIO 
 */
static void PIOSendByte(u16 crubase, u8 val)
{
	OSError err;
	if (!pio.handle)
	{
		if (strchr(emupiofilename, '%'))
		{
			char outname[OS_NAMESIZE];
			int cnt = 1000;
			while (cnt>0) {
				snprintf(outname, sizeof(outname), emupiofilename, pio.page);
				if (!data_find_file(datapath, outname, &pio.filespec))
					break;
				pio.page++;
				cnt--;
			}
			if (cnt == 0) {
				module_logger(&emuPIODSR, _L|LOG_ERROR|LOG_USER, _("could not find a spare page file for '%s' (page=%d)"),
							  emupiofilename, pio.page);
				return;
			}
			if (!data_create_file(datapath, outname, &pio.filespec, &OS_TEXTTYPE)) {
				module_logger(&emuPIODSR, _L|LOG_ERROR|LOG_USER, _("could not create page file '%s'"),
							  outname);
				return;
			}
		}
		else
		{
			if (!data_create_file(datapath, emupiofilename, &pio.filespec, &OS_TEXTTYPE)) {
				module_logger(&emuPIODSR, _L|LOG_ERROR|LOG_USER, _("could not create page file '%s'"),
							  emupiofilename);
				return;
			}
		}

		if ((err = OS_Open(&pio.filespec, OSReadWrite, &pio.handle)) != OS_NOERR)
		{
			module_logger(&emuPIODSR, _L|LOG_ERROR|LOG_USER, _("could not write file '%s' (%s)"),
						  OS_SpecToString1(&pio.filespec),
						  OS_GetErrText(err));
			return;	
		}
	}

	if (pio.handle)
	{
		OSSize size = 1;
		if ((err = OS_Write(pio.handle, (void *)&val, &size)) != OS_NOERR
			&& size != 1)
		{
			module_logger(&emuPIODSR, _L|LOG_ERROR, _("error writing to PIO (%s) (%s)"),
						  OS_SpecToString1(&pio.filespec),
						  OS_GetErrText(err));
		}
	}
	//module_logger(&emuPIODSR, _L | LOG_USER, "%c", val);
}
Example #4
0
void ReadLightSensors(void) {
	FIFO f = (FIFO)OS_GetParam(); 
	int l, r;
	
	while (1) {
		l = 0; 
		r = 0; 
		OS_Wait(S_PORTE); 
		/* Activate A/D Converter...makes pins on Port E analog. */ 
		Ports[M6811_OPTION] SET_BIT(BIT7); 
		/* Delay at least 100 microseconds */ 
		OS_Yield(); 
		
		/* Start converting the right photocell */ 
		Ports[M6811_ADCTL] = 0; 
		/* Wait for conversion to complete. */ 
		while (!(Ports[M6811_ADCTL] & BIT7)) {
			OS_Yield(); 
		}
		r = Ports[M6811_ADR1]; 
		
		/* Start converting the left photocell */ 
		Ports[M6811_ADCTL] = 1; 
		/* Wait for conversion to complete. */ 
		while (!(Ports[M6811_ADCTL] & BIT7)) {
			OS_Yield(); 
		}
		l = Ports[M6811_ADR1];	
		OS_Signal(S_PORTE); 
		
		if (l > 100) {
			OS_Wait(S_BUZZ_FIFO);
			OS_Write(f,'l'); 
		}
		
		if (r > 100) {
			OS_Wait(S_BUZZ_FIFO);
			OS_Write(f,'r'); 
		}
		
		
		OS_Yield();
	}
}
Example #5
0
static int write_it_all(int fd, char *buf, int len)
{
	int wrote;

	while (len) {
		wrote = OS_Write(fd, buf, len);
		if (wrote < 0)
			return wrote;
		len -= wrote;
		buf += wrote;
	}
	return len;
}
Example #6
0
void ReadMicrophone(void) {
	FIFO f = (FIFO)OS_GetParam(); 
	int s;
	
	while (1) {
		s = 0; 
		
		OS_Wait(S_PORTE); 
		/* Activate A/D Converter...makes pins on Port E analog. */ 
		Ports[M6811_OPTION] SET_BIT(BIT7); 
		/* Delay at least 100 microseconds */ 
		OS_Yield(); 
		/* Don't listen while buzzing. */ 
		OS_Wait(S_BUZZ_OUTPUT);
		/* Start converting the microphone. */ 
		Ports[M6811_ADCTL] = 2; 
		OS_Signal(S_BUZZ_OUTPUT);
		/* Wait for conversion to complete. */ 
		while (!(Ports[M6811_ADCTL] & BIT7)) {
			OS_Yield(); 
		}
		s = Ports[M6811_ADR1]; 
		OS_Signal(S_PORTE); 
		
		/* Rectify the sound sample around 128. */ 
		if (s >= 128) { s -= 128; }
		else          { s = 128 - s; }
		
		if (s > 35) {
			OS_Wait(S_BUZZ_FIFO);
			OS_Write(f,'s'); 
		}
		
		
		OS_Yield();
	}
}
Example #7
0
/*
 *	Save data to an image found somewhere in 'path'
 *	(if not existing, placed in first writeable entry of 'path').
 *	Existing file is not overwritten.
 *
 *	path:			search
 *	type:			string emitted in error, i.e., "RAM image"
 *	filename:		name of image
 *	fileoffs:		offset into file to write
 *	saveat:			start of memory to write 
 *	swap:			if true, byteswap word data to TI format
 *	memsize:		size of memory to write
 */
int  
data_save_binary(const char *type, const char *path, const char *filename, 
				 int fileoffs, u8 * saveat, int swap, int memsize)
{
	OSRef       ref;
	OSSize      size;
	OSError     err;
	OSSpec      spec;

#if 0
	if ((size = data_find_binary(path, syspath, filename, &spec)) == 0) {
		if ((err = OS_CreateFileInPath(filename, 
									   *path ? path : syspath, 
									   &spec, 
									   &osBinaryType)) != OS_NOERR) {
			OSerror(err, _("Couldn't create %s image %s anywhere in path: %s\n"),
					type, filename, path);
			return 0;
		}
	}
#endif

	if ((size = data_find_binary(path, filename, &spec)) == 0) {
		if (!data_create_file(path, filename, &spec, &osBinaryType)) {
			logger(_L|LOG_USER|LOG_ERROR, _("Couldn't create %s image '%s' anywhere in path:\n'%s'\n"),
					type, filename, path);
			return 0;
		}
		size = memsize;
	}

	logger(_L |L_0, _("Writing %s image %s... "), type, OS_SpecToString1(&spec));

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

	//saveat += offset;

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

	err = OS_Seek(ref, OSSeekAbs, fileoffs);

	size = memsize;
	err = OS_Write(ref, saveat, &size);

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

	if (err != OS_NOERR) {
		OSerror(err, _("could not write\n"));
		return 0;
	}

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

	OS_Close(ref);
	return size;
}