main.c 3.43 KB

#include	<ultra64.h>
#include	"thread.h"
#include        "textlib.h"

extern u16      *bitmap_buf;
extern u16      bitmap_buf1[];
extern u16      bitmap_buf2[];

OSPfs pfs0;

#define NUM_MESSAGE 1

OSMesgQueue  pifMesgQueue;
OSMesg       dummyMessage, pifMesgBuf[NUM_MESSAGE];
static OSContStatus     sdata[MAXCONTROLLERS];

extern OSMesgQueue retraceMessageQ;

void	
mainproc(void *arg)
{	
	int error = 0;
	s32 ret = 0;
	u8 p;
	int i;
	u8 test_buffer[EEPROM_BLOCK_SIZE];
	u8 long_buffer[EEPROM_MAXBLOCKS * EEPROM_BLOCK_SIZE];
	static OSContPad        rdata[MAXCONTROLLERS];

	osCreateMesgQueue(&pifMesgQueue, pifMesgBuf, NUM_MESSAGE);
	osSetEventMesg(OS_EVENT_SI, &pifMesgQueue, dummyMessage);
	osContInit(&pifMesgQueue, &p, &sdata[0]);

	init_draw();
	draw_char('n');
	while (1) {
		u8 no;

		ret = osEepromProbe(&pifMesgQueue);
		if (p)
			osContStartReadData(&pifMesgQueue);
		setcolor(0xa0,0xf0,0x80);
		if (ret) {
			draw_puts("\f\n\n\n\n\t");
			draw_puts(" probe success\n");
#ifdef jean
			for(no = 0 ; no < EEPROM_MAXBLOCKS ; no++) {
				for (i = 0 ; i < EEPROM_BLOCK_SIZE; i++)
					test_buffer[i] = no;
				ret = osEepromWrite(&pifMesgQueue, no, 
						test_buffer);
				if (ret == 0) {
					setcolor(0xa0,0x20,0x80);
					draw_puts("\t\t\twrite success: ");
					draw_ushort(no);
					draw_char('\n');
				} else {
					setcolor(0xa0,0x20,0x80);
					draw_puts("\t\t\twrite fail: ");
					draw_ushort(no);
					draw_char('\n');
				}
			}
			for(no = 0 ; no < 10 ; no++) {
				int error = 0;

				ret = 0;
				ret = osEepromRead(&pifMesgQueue, no, 
						test_buffer);
				if (ret == 0) {
					error = 0;
					for (i = 0 ; i < EEPROM_BLOCK_SIZE; i++){
						if (test_buffer[i] != no) {
							error++;
						}
					}
					setcolor(0xa0,0x20,0x80);
					if (error == 0) {
						draw_puts("\t\t\t\t\t\tread success: ");
						draw_ushort(no);
						draw_char('\n');
					} else {
						draw_puts("\t\t\t\t\t\tread error: ");
						draw_ushort(no);
						draw_char('\n');
					}
				} else {
					setcolor(0xa0,0x20,0x80);
					draw_puts("\t\t\t\t\t\t\read fail: ");
					draw_ushort(no);
					draw_char('\n');
				}
			}
#endif
			for (i  = 0; i < EEPROM_BLOCK_SIZE * EEPROM_MAXBLOCKS; i++) {
				long_buffer[i] = i & 0xff;
			}
			ret = osEepromLongWrite(&pifMesgQueue, 0, long_buffer, EEPROM_BLOCK_SIZE * EEPROM_MAXBLOCKS);
			if (ret == 0) {
				setcolor(0xa0,0x20,0x80);
				draw_puts("\t long write success \n");
			} else {
				setcolor(0xa0,0x20,0x80);
				draw_puts("\t long write fail: \n");
			}
			ret = osEepromLongRead(&pifMesgQueue, 0, long_buffer,EEPROM_BLOCK_SIZE * EEPROM_MAXBLOCKS);
			if (ret == 0) {
				error = 0;
				for (i = 0; i < EEPROM_BLOCK_SIZE * EEPROM_MAXBLOCKS; i++) {
					if (long_buffer[i] != (i & 0xff)) {
						error++;
					}
				}
				setcolor(0xa0,0x20,0x80);
				if (error == 0)
					draw_puts("\t long read success \n");
				else
					draw_puts("\t long read error \n");
					
			} else {
				setcolor(0xa0,0x20,0x80);
				draw_puts("\t long read fail: \n");
			}
		} else{
			draw_puts("\f\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t");
			draw_puts(" probe fail\n");
			v_sync_double_buffer(&retraceMessageQ);
			draw_puts("\f\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t");
			draw_puts(" probe fail\n");

		}
	    
		if (p) {
			osRecvMesg(&pifMesgQueue, NULL, OS_MESG_BLOCK);
			osContGetReadData(&rdata[0]);
			draw_puts("\f\n\tbutton: ");
			draw_ushort(rdata[0].button);
		}

		v_sync_double_buffer(&retraceMessageQ);
		clear_draw();
	}

	  for (;;);
}