示例#1
0
static void mainproc(void *arg)
{
    Dynamic    *dynamicp;
    Gfx        *glistp;
    Control    cont;

    init_dma();
    init_task();
    init_framebuffer();

    read_rom( _staticSegmentStart,
              _staticSegmentRomStart, _staticSegmentRomEnd  );
    read_rom( _dkSegmentStart, _dkSegmentRomStart, _dkSegmentRomEnd  );
    read_rom( _dk7SegmentStart, _dk7SegmentRomStart, _dk7SegmentRomEnd  );
    read_rom( _roadSegmentStart, _roadSegmentRomStart,
              _roadSegmentRomEnd  );
    read_rom( _l2_tvSegmentStart, _l2_tvSegmentRomStart,
              _l2_tvSegmentRomEnd  );

    init_controlers( &cont );

    game_init();

    while (1)
    {
        read_controler( &cont );

        dynamicp = &dynamic;

        guOrtho( &dynamicp->projection,
                 -(float) SCREEN_WD / 2.0F, (float) SCREEN_WD / 2.0F,
                 -(float) SCREEN_HT / 2.0F, (float) SCREEN_HT / 2.0F,
                 1.0F, 10.0F, 1.0F );
        guRotate( &dynamicp->modeling, 0.0F, 0.0F, 0.0F, 1.0F );

        glistp = dynamicp->glist;

        /* rcp rdp & color frame buffer initialize */
        glistp = init_rcprdp( glistp, (char *)_staticSegmentStart, draw_buffer );
        glistp = clear_cfb( glistp );

        /* game main */
        glistp = game_main( glistp, &cont );

        gDPFullSync(glistp++);
        gSPEndDisplayList(glistp++);

        assert((glistp - dynamicp->glist) < GLIST_LEN);

        start_task( glistp, dynamicp );

        swap_framebuffer( draw_buffer );
        draw_buffer ^= 1;
    }
}
示例#2
0
struct zfile *read_rom_name_guess (const TCHAR *filename)
{
	int i, j;
	struct zfile *f;
	const TCHAR *name;

	for (i = _tcslen (filename) - 1; i >= 0; i--) {
		if (filename[i] == '/' || filename[i] == '\\')
			break;
	}
	if (i < 0)
		return NULL;
	name = &filename[i];

	for (i = 0; i < romlist_cnt; i++) {
		TCHAR *n = rl[i].path;
		for (j = _tcslen (n) - 1; j >= 0; j--) {
			if (n[j] == '/' || n[j] == '\\')
				break;
		}
		if (j < 0)
			continue;
		if (!_tcsicmp (name, n + j)) {
			struct romdata *rd = rl[i].rd;
			f = read_rom (&rd);
			if (f) {
				write_log (L"ROM %s not found, using %s\n", filename, rl[i].path);
				return f;
			}
		}
	}
	return NULL;
}
示例#3
0
uint8_t ds2431_read(void)
{
	uint8_t i, rt = 0;
	
	for (i = 0; i < 10; i ++)
	{
		ow_rst();
		udelay(9000);
		
		rt = read_rom();
		
		if (rt == 1)
		{
			//ROM读取成功,则读取MEM
			rt = read_mem();
			
			if (rt == 1)
			{
				//都读取成功,则退出
				return 1;
			}
		}
	}
	
	//读取失败
	return 0;
}
static int scan_rom(char *path, char *file)
{
	struct dirent **namelist;
	char *name, *path2;
	int i, n, r, rc = 0, result = 0;
	struct stat buf;

	n = scandir(path, &namelist, 0, alphasort);
	if (n < 0) {
		perror("scandir");
		return -1;
	}

	for (i = 0; i < n; i++) {
		name = namelist[i]->d_name;

		if (fnmatch(".", name, 0) == 0)
			goto skip;
		if (fnmatch("..", name, 0) == 0)
			goto skip;

		path2 = malloc(strlen(path) + strlen(name) + 3);
		strcpy(path2, path);
		strcat(path2, "/");
		strcat(path2, name);

		if (fnmatch(file, name, 0) == 0) {
			rc = read_rom(path2);

			/*
			 * It's OK if the ROM is unreadable.  Maybe there
			 * is no ROM, or some other error ocurred.  The
			 * important thing is that no MCA happened.
			 */
			if (rc > 0)
				fprintf(stderr, "PASS: %s read %d bytes\n", path2, rc);
			else {
				fprintf(stderr, "PASS: %s not readable\n", path2);
				return rc;
			}
		} else {
			r = lstat(path2, &buf);
			if (r == 0 && S_ISDIR(buf.st_mode)) {
				rc = scan_rom(path2, file);
				if (rc < 0)
					return rc;
			}
		}

		result |= rc;
		free(path2);

skip:
		free(namelist[i]);
	}
	free(namelist);
	return result;
}
示例#5
0
int main(int argc, char** argv) {

        if (argc > 1) {
                uint8_t rom[ROM_SIZE];
                int size = read_rom(argv[1], rom, ROM_SIZE);
                if (size != -1) {
                        chip8emu_init();
                        chip8emu_load_rom(rom, size);
                        chip8emu_begin_emulate();
                }
        }
        return 0;
}
示例#6
0
struct zfile *read_rom_name (const TCHAR *filename)
{
	int i;
	struct zfile *f;

	for (i = 0; i < romlist_cnt; i++) {
		if (!_tcsicmp (filename, rl[i].path)) {
			struct romdata *rd = rl[i].rd;
			f = read_rom (&rd);
			if (f)
				return f;
		}
	}
	f = rom_fopen (filename, L"rb", ZFD_NORMAL);
	if (f) {
		uae_u8 tmp[11];
		zfile_fread (tmp, sizeof tmp, 1, f);
		if (!memcmp (tmp, "AMIROMTYPE1", sizeof tmp)) {
			struct zfile *df;
			int size;
			uae_u8 *buf;
			addkeydir (filename);
			zfile_fseek (f, 0, SEEK_END);
			size = zfile_ftell (f) - sizeof tmp;
			zfile_fseek (f, sizeof tmp, SEEK_SET);
			buf = xmalloc (uae_u8, size);
			zfile_fread (buf, size, 1, f);
			df = zfile_fopen_empty (f, L"tmp.rom", size);
			decode_cloanto_rom_do (buf, size, size);
			zfile_fwrite (buf, size, 1, df);
			zfile_fclose (f);
			xfree (buf);
			zfile_fseek (df, 0, SEEK_SET);
			f = df;
		} else {
			zfile_fseek (f, -((int)sizeof tmp), SEEK_CUR);
		}
	}
	return f;
}
示例#7
0
int load_rom_from_file(int num, room **rom_ptr )
{
    int fd;
    char file[256];

	get_room_filename(num, file );

	fd = open(file, O_RDWR | O_BINARY );
	if(fd < 0)
		return(-1);
	*rom_ptr = (room *)malloc(sizeof(room));
	if(!*rom_ptr)
		merror("load_rom", FATAL);
	if(read_rom(fd, *rom_ptr) < 0) {
		close(fd);
		return(-1);
	}
	close(fd);

	(*rom_ptr)->rom_num = num;

    return(0);
}
示例#8
0
void chip8disasm(const char* rom_file, const char* output) {
        uint8_t rom_data[4096];
        int rom_size = read_rom(rom_file, &(rom_data[0]), 4096);

        if (rom_size != -1) {
                printf("%d bytes read.\n", rom_size);

                FILE *output_file = fopen(output, "w");
                if (output_file == NULL) {
                        printf("Could not open output file %s.\n", output);
                        return;
                }

                size_t i;
                for (i = 0; i < rom_size; i += 2) {
                        fprintf(output_file, "%x: ", i);

                        uint16_t opcode = rom_data[i];
                        opcode <<= 8;
                        opcode |= rom_data[i + 1];

                        /*  
                         * Pieces of interest.  The vast majority of the 
                         *  instructions will use one of these.  
                        
                         *  x and y represent one of the 16 registers.
                         *  n is a nibble representing a constant.
                         *  kk is a byte constant.
                         *  addr is a 12-bit address vaue.
                         */
                        uint8_t x = nibble(opcode, 2);
                        uint8_t y = nibble(opcode, 1);
                        uint8_t n = nibble(opcode, 0);
                        uint8_t kk = low_byte(opcode);
                        uint16_t addr = get_addr(opcode);

                        switch (identify_ins(opcode)) {
                        case SYS_addr:
                                fprintf(output_file, "SYS %x", 
                                                        get_addr(opcode));
                                break;
                        case CLS:
                                fprintf(output_file, "CLS");
                                break;
                        case RET:
                                fprintf(output_file, "RET");
                                break;
                        case JP_addr:
                                fprintf(output_file, "JP %x", 
                                                        get_addr(opcode));
                                break;
                        case CALL_addr:
                                fprintf(output_file, "CALL %x", 
                                                        get_addr(opcode));
                                break;
                        case SE_Vx_byte:
                                fprintf(output_file, "SE V%x, %x", x, kk);
                                break;
                        case SNE_Vx_byte:
                                fprintf(output_file, "SNE, V%x, %x", x, kk);
                                break;
                        case SE_Vx_Vy:
                                fprintf(output_file, "SE V%x, V%x", x, y);
                                break;
                        case LD_Vx_byte:
                                fprintf(output_file, "LD V%x, %x", x, kk);
                                break;
                        case ADD_Vx_byte:
                                fprintf(output_file, "ADD V%x, %x", x, kk);
                                break;
                        case LD_Vx_Vy:
                                fprintf(output_file, "LD V%x, V%x", x, y);
                                break;
                        case OR_Vx_Vy:
                                fprintf(output_file, "OR V%x, V%x", x, y);
                                break;
                        case AND_Vx_Vy:
                                fprintf(output_file, "AND V%x, V%x", x, y);
                                break;
                        case XOR_Vx_Vy:
                                fprintf(output_file, "XOR V%x, V%x", x, y);
                                break;
                        case ADD_Vx_Vy:
                                fprintf(output_file, "ADD V%x, V%x", x, y);
                                break;
                        case SUB_Vx_Vy:
                                fprintf(output_file, "SUB V%x, V%x", x, y);
                                break;
                        case SHR_Vx:
                                fprintf(output_file, "SHR V%x", x);
                                break;
                        case SUBN_Vx_Vy:
                                fprintf(output_file, "SUBN V%x, V%x", x, y);
                                break;
                        case SHL_Vx:
                                fprintf(output_file, "SHL V%x", x);
                                break;
                        case SNE_Vx_Vy:
                                fprintf(output_file, "SNE V%x, V%x", x, y);
                                break;
                        case LD_I_addr:
                                fprintf(output_file, "LD I, %x", addr);
                                break;
                        case JP_V0_addr:
                                fprintf(output_file, "JP V0, %x", addr);
                                break;
                        case RND_Vx_byte:
                                fprintf(output_file, "RND V%x, %x", x, kk);
                                break;
                        case DRW_Vx_Vy_nibble:
                                fprintf(output_file, "DRW V%x, V%x, %x", x, y,
                                                                        n);
                                break;
                        case SKP_Vx:
                                fprintf(output_file, "SKP V%x", x);
                                break;
                        case SKNP_Vx:
                                fprintf(output_file, "SKNP V%x", x);
                                break;
                        case LD_Vx_DT:
                                fprintf(output_file, "LD V%x, DT", x);
                                break;
                        case LD_Vx_K:
                                fprintf(output_file, "LD V%x, K", x);
                                break;
                        case LD_DT_Vx:
                                fprintf(output_file, "LD DT, V%x", x);
                                break;
                        case LD_ST_Vx:
                                fprintf(output_file, "LD ST, V%x", x);
                                break;
                        case ADD_I_Vx:
                                fprintf(output_file, "ADD I, V%x", x);
                                break;
                        case LD_F_Vx:
                                fprintf(output_file, "LD F, V%x", x);
                                break;
                        case LD_B_Vx:
                                fprintf(output_file, "LD B, V%x", x);
                                break;
                        case LD_memI_Vx:
                                fprintf(output_file, "LD [I], V%x", x);
                                break;
                        case LD_Vx_memI:
                                fprintf(output_file, "LD V%x, [I]", x);
                                break;
                        default:
                                fprintf(output_file, "UNKNOWN");
                        }
                        fprintf(output_file, "\n");
                }
                fclose(output_file);
        } else {
                printf("Could not read rom file.\n");
        }
}