Exemplo n.º 1
0
byte cheat_write(word adr, byte dat)
{
	cheat_dat *tmp=&cheats[cheat_map_n[adr]];

	switch(tmp->code){
	case 0x01:
		tmp->dat_old = dat;
		return tmp->dat;
	case 0x90:
	case 0x91:
	case 0x92:
	case 0x93:
	case 0x94:
	case 0x95:
	case 0x96:
	case 0x97:
		if ((adr>=0xD000)&&(adr<0xE000)){
			if(((cpu_get_ram_bank()-cpu_get_ram())/0x1000)==(tmp->code-0x90)){
				tmp->dat_old = dat;
				return tmp->dat;
			}
		}
		else{
			tmp->dat_old = dat;
			return tmp->dat;
		}
	}

	return dat;
}
Exemplo n.º 2
0
Arquivo: gb.c Projeto: BelmonduS/rin
void gb_restore_state(FILE * fd, const byte *buf)
{
	const int tbl_ram[]={1,1,1,4,16,8}; // 0と1は保険
	const int has_bat[]={0,0,0,1,0,0,1,0,0,1,0,0,1,1,0,1,1,0,0,1,0,0,0,0,0,0,0,1,0,1,1,0}; // 0x20以下
	int gb_type,dmy;
	
	read_state(fd, &gb_type, sizeof(int));
	
	rom_get_info()->gb_type=gb_type;
	
	if (gb_type<=2){
		read_state(fd, cpu_get_ram(),0x2000); // ram
		read_state(fd, cpu_get_vram(),0x2000); // vram
		read_state(fd, get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000); // sram
		read_state(fd, cpu_get_oam(),0xA0);
		read_state(fd, cpu_get_stack(),0x80);

		int page,ram_page;
		read_state(fd, &page, sizeof(int)); // rom_page
		read_state(fd, &ram_page, sizeof(int)); // ram_page
		mbc_set_page(page,ram_page);

		read_state(fd, cpu_get_c_regs(),sizeof(struct cpu_regs)); // cpu_reg
		cpu_set_c_regs();
		read_state(fd, (void *)&g_regs,sizeof(struct gb_regs)); // sys_reg
		int halt;
		read_state(fd, &halt,sizeof(int));
		*cpu_get_halt()=((halt)?true:false);
		read_state(fd, &dmy,sizeof(int));

		int mbc_dat;
		read_state(fd, &mbc_dat,sizeof(int)); // MBC
		mbc_set_state(mbc_dat);
		int ext_is;
		read_state(fd, &ext_is,sizeof(int));
		mbc_set_ext_is(ext_is?true:false);

		// ver 1.1 追加
		byte tmp[256],tester[100];
//		read_state(fd, tmp, 100); // とりあえず調べてみる
//		_memset(tester,0,100);
//		if (_memcmp(tmp,tester,100)!=0){
			// apu 部分
//			sceIoLseek(fd, -100, 1);
			read_state(fd, apu_get_stat_cpu(),sizeof(struct apu_stat));
			read_state(fd, apu_get_mem(),0x30);
			read_state(fd, apu_get_stat_gen(),sizeof(struct apu_stat));
//		}

		byte resurved[256];
		read_state(fd, resurved, 256);//将来のために確保
		
		// RIN拡張
		if(gb_type==2 && sgb_mode){
			int dmy;
			read_state(fd, &dmy, sizeof(int));

			read_state(fd, &bit_received, sizeof(int));
			read_state(fd, &bits_received, sizeof(int));
			read_state(fd, &packets_received, sizeof(int));
			read_state(fd, &sgb_state, sizeof(int));
			read_state(fd, &sgb_index, sizeof(int));
			read_state(fd, &sgb_multiplayer, sizeof(int));
			read_state(fd, &sgb_fourplayers, sizeof(int));
			read_state(fd, &sgb_nextcontrol, sizeof(int));
			read_state(fd, &sgb_readingcontrol, sizeof(int));
			read_state(fd, &sgb_mask, sizeof(int));
			
			read_state(fd, sgb_palette, sizeof(unsigned short)*8*16);
			read_state(fd, sgb_palette_memory, sizeof(unsigned short)*512*4);
			read_state(fd, sgb_buffer, 7*16);
			read_state(fd, sgb_ATF, 18*20);
			read_state(fd, sgb_ATF_list, 45*20*18);
			/*
			read_state(fd, sgb_border, 2048);
			read_state(fd, sgb_borderchar, 32*256);
			read_state(fd, border_tmp, sizeof(border_tmp));
			int i, j, n=0;
			for (i=0; i<224; i++){
				for (j=0; j<256; j++){
					if (i>=40 && i<=183 && j==48) j=208;
					sgb_border_buffer[i*256+j] = border_tmp[n++];
				}
			}
			*/
		}
	}
	else if (gb_type>=3){ // GB Colour / GBA
		read_state(fd, cpu_get_ram(),0x2000*4); // ram
		read_state(fd, cpu_get_vram(),0x2000*2); // vram
		read_state(fd, get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000); // sram
		read_state(fd, cpu_get_oam(),0xA0);
		read_state(fd, cpu_get_stack(),0x80);

		int cpu_dat[16];

		int page,ram_page;
		read_state(fd, &page, sizeof(int)); // rom_page
		read_state(fd, &ram_page, sizeof(int)); // ram_page
		mbc_set_page(page,ram_page);
		page=(mbc_get_rom()-get_rom())/0x4000;
		ram_page=(mbc_get_sram()-get_sram())/0x2000;

		read_state(fd, cpu_dat+0,sizeof(int));//int_page
		read_state(fd, cpu_dat+1,sizeof(int));//vram_page

		int dmy;
		read_state(fd, cpu_get_c_regs(),sizeof(struct cpu_regs)); // cpu_reg
		cpu_set_c_regs();
		read_state(fd, &g_regs,sizeof(struct gb_regs));//sys_reg
		read_state(fd, &cg_regs,sizeof(struct gbc_regs));//col_reg
		read_state(fd, lcd_get_pal_addr(),sizeof(word)*(8*4*2));//palette
		int halt;
		read_state(fd, &halt,sizeof(int));
		*cpu_get_halt()=(halt?true:false);
		read_state(fd, &dmy,sizeof(int)); // 元の版ではシリアル通信通信満了までのクロック数

		int mbc_dat;
		read_state(fd, &mbc_dat,sizeof(int)); // MBC
		mbc_set_state(mbc_dat);
		int ext_is;
		read_state(fd, &ext_is,sizeof(int));
		mbc_set_ext_is(ext_is?true:false);

		//その他諸々
		read_state(fd, cpu_dat+2,sizeof(int));
		read_state(fd, cpu_dat+3,sizeof(int));
		read_state(fd, cpu_dat+4,sizeof(int));
		read_state(fd, cpu_dat+5,sizeof(int));
		read_state(fd, cpu_dat+6,sizeof(int));
		read_state(fd, cpu_dat+7,sizeof(int));
		cpu_restore_state(cpu_dat);

		// ver 1.1 追加
		byte tmp[256],tester[100];

			read_state(fd, apu_get_stat_cpu(),sizeof(struct apu_stat));
			read_state(fd, apu_get_mem(),0x30);
			read_state(fd, apu_get_stat_gen(),sizeof(struct apu_stat));

			read_state(fd, tmp,1);
//		}
		byte resurved[256];
		read_state(fd, resurved,256);//将来のために確保
	}

	cheat_create_cheat_map();
}
Exemplo n.º 3
0
Arquivo: gb.c Projeto: BelmonduS/rin
size_t gb_save_state(byte *out)
{
	const int tbl_ram[]={1,1,1,4,16,8}; // 0と1は保険
	const int has_bat[]={0,0,0,1,0,0,1,0,0,1,0,0,1,1,0,1,1,0,0,1,0,0,0,0,0,0,0,1,0,1,1,0}; // 0x20以下
	byte *outbak = out;

	if (outbak)
		cheat_decreate_cheat_map();

	write_state(&rom_get_info()->gb_type,sizeof(int),out,outbak);

	if (rom_get_info()->gb_type<=2){ // normal gb & sgb
		write_state(cpu_get_ram(),0x2000,out,outbak); // ram
		write_state(cpu_get_vram(),0x2000,out,outbak); // vram
		write_state(get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000,out,outbak); // sram
		write_state(cpu_get_oam(),0xA0,out,outbak);
		write_state(cpu_get_stack(),0x80,out,outbak);

		int page,ram_page;
		page=(mbc_get_rom()-get_rom())/0x4000;
		ram_page=(mbc_get_sram()-get_sram())/0x2000;

		write_state(&page,sizeof(int),out,outbak); // rom_page
		write_state(&ram_page,sizeof(int),out,outbak); // ram_page

		int dmy=0;

		write_state(cpu_get_c_regs(),sizeof(struct cpu_regs),out,outbak); // cpu_reg
		write_state(&g_regs,sizeof(struct gb_regs),out,outbak);//sys_reg
		int halt=((*cpu_get_halt())?1:0);
		write_state(&halt,sizeof(int),out,outbak);
		write_state(&dmy,sizeof(int),out,outbak); // 元の版ではシリアル通信通信満了までのクロック数
		                                               // (通信の仕様が大幅に変わったためダミーで埋めている)
		int mbc_dat=mbc_get_state();
		write_state(&mbc_dat,sizeof(int),out,outbak);//MBC

		int ext_is=mbc_is_ext_ram()?1:0;
		write_state(&ext_is,sizeof(int),out,outbak);

		// ver 1.1 追加
		write_state(apu_get_stat_cpu(),sizeof(struct apu_stat),out,outbak);
		write_state(apu_get_mem(),0x30,out,outbak);
		write_state(apu_get_stat_gen(),sizeof(struct apu_stat),out,outbak);

		byte resurved[256];
		memset(resurved,0,256);
		write_state(resurved,256,out,outbak);//将来のために確保
		
		// RIN拡張
		if(now_gb_mode==2){
			write_state(&sgb_mode, sizeof(int),out,outbak);
			write_state(&bit_received, sizeof(int),out,outbak);
			write_state(&bits_received, sizeof(int),out,outbak);
			write_state(&packets_received, sizeof(int),out,outbak);
			write_state(&sgb_state, sizeof(int),out,outbak);
			write_state(&sgb_index, sizeof(int),out,outbak);
			write_state(&sgb_multiplayer, sizeof(int),out,outbak);
			write_state(&sgb_fourplayers, sizeof(int),out,outbak);
			write_state(&sgb_nextcontrol, sizeof(int),out,outbak);
			write_state(&sgb_readingcontrol, sizeof(int),out,outbak);
			write_state(&sgb_mask, sizeof(int),out,outbak);
			
			write_state(sgb_palette, sizeof(unsigned short)*8*16,out,outbak);
			write_state(sgb_palette_memory, sizeof(unsigned short)*512*4,out,outbak);
			write_state(sgb_buffer, 7*16,out,outbak);
			write_state(sgb_ATF, 18*20,out,outbak);
			write_state(sgb_ATF_list, 45*20*18,out,outbak);
		}
	}
	else if (rom_get_info()->gb_type>=3){ // GB Colour / GBA
		write_state(cpu_get_ram(),0x2000*4,out,outbak); // ram
		write_state(cpu_get_vram(),0x2000*2,out,outbak); // vram
		write_state(get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000,out,outbak); // sram
		write_state(cpu_get_oam(),0xA0,out,outbak);
		write_state(cpu_get_stack(),0x80,out,outbak);

		int cpu_dat[16];
		cpu_save_state(cpu_dat);

		int page,ram_page;
		page=(mbc_get_rom()-get_rom())/0x4000;
		ram_page=(mbc_get_sram()-get_sram())/0x2000;

		write_state(&page,sizeof(int),out,outbak); // rom_page
		write_state(&ram_page,sizeof(int),out,outbak); // ram_page
		write_state(cpu_dat+0,sizeof(int),out,outbak);//int_page	//color
		write_state(cpu_dat+1,sizeof(int),out,outbak);//vram_page	//color

		int dmy=0;

		write_state(cpu_get_c_regs(),sizeof(struct cpu_regs),out,outbak); // cpu_reg
		write_state(&g_regs,sizeof(struct gb_regs),out,outbak);//sys_reg
		write_state(&cg_regs,sizeof(struct gbc_regs),out,outbak);//col_reg		//color
		
		//save the gbc palette
		write_state(lcd_get_pal_addr(),sizeof(word)*(8*4*2),out,outbak);//palette	//color
		
		int halt=((*cpu_get_halt())?1:0);
		write_state(&halt,sizeof(int),out,outbak);
		write_state(&dmy,sizeof(int),out,outbak); // 元の版ではシリアル通信通信満了までのクロック数

		int mbc_dat=mbc_get_state();
		write_state(&mbc_dat,sizeof(int),out,outbak);//MBC

		int ext_is=mbc_is_ext_ram()?1:0;
		write_state(&ext_is,sizeof(int),out,outbak);

		//その他諸々
		write_state(cpu_dat+2,sizeof(int),out,outbak);	//color
		write_state(cpu_dat+3,sizeof(int),out,outbak);	//color
		write_state(cpu_dat+4,sizeof(int),out,outbak);	//color
		write_state(cpu_dat+5,sizeof(int),out,outbak);	//color
		write_state(cpu_dat+6,sizeof(int),out,outbak);	//color
		write_state(cpu_dat+7,sizeof(int),out,outbak);	//color

		// ver 1.1 追加
		write_state(apu_get_stat_cpu(),sizeof(struct apu_stat),out,outbak);
		write_state(apu_get_mem(),0x30,out,outbak);
		write_state(apu_get_stat_gen(),sizeof(struct apu_stat),out,outbak);

		byte resurved[256],reload=1;
		memset(resurved,0,256);
//		resurved[0]=1;
		write_state(&reload,1,out,outbak);
		write_state(resurved,256,out,outbak);//将来のために確保
	}

	if(outbak)
		cheat_create_cheat_map();

	return out-outbak;
}
Exemplo n.º 4
0
void gb_save_state(VIRTUAL_FILE *fd, byte *buf)
{
	const int tbl_ram[]={1,1,1,4,16,8}; // 0と1は保険

#ifdef CHEAT_SUPPORT
	if (buf || fd)
		cheat_decreate_cheat_map();
#endif

	write_state(fd, &rom_get_info()->gb_type,sizeof(int));

	if (rom_get_info()->gb_type<=2){ // normal gb & sgb
		write_state(fd, cpu_get_ram(),0x2000); // ram
		write_state(fd, cpu_get_vram(),0x2000); // vram
		write_state(fd, get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000); // sram
		write_state(fd, cpu_get_oam(),0xA0);
		write_state(fd, cpu_get_stack(),0x80);

		int page,ram_page;
		page=(mbc_get_rom()-get_rom())/0x4000;
		ram_page=(mbc_get_sram()-get_sram())/0x2000;

		write_state(fd, &page,sizeof(int)); // rom_page
		write_state(fd, &ram_page,sizeof(int)); // ram_page

		int dmy=0;

		write_state(fd, cpu_get_c_regs(),sizeof(struct cpu_regs)); // cpu_reg
		write_state(fd, &g_regs,sizeof(struct gb_regs));//sys_reg
		int halt=((*cpu_get_halt())?1:0);
		write_state(fd, &halt,sizeof(int));
		write_state(fd, &dmy,sizeof(int)); // 元の版ではシリアル通信通信満了までのクロック数
		                                               // (通信の仕様が大幅に変わったためダミーで埋めている)
		int mbc_dat=mbc_get_state();
		write_state(fd, &mbc_dat,sizeof(int));//MBC

		int ext_is=mbc_is_ext_ram()?1:0;
		write_state(fd, &ext_is,sizeof(int));

		// ver 1.1 追加
		write_state(fd, apu_get_stat_cpu(),sizeof(struct apu_stat));
		write_state(fd, apu_get_mem(),0x30);
		write_state(fd, apu_get_stat_gen(),sizeof(struct apu_stat));

		byte resurved[256];
		memset(resurved,0,256);
		write_state(fd, resurved,256);//将来のために確保
		
		// RIN拡張
		if(now_gb_mode==2){
			write_state(fd, &sgb_mode, sizeof(int));
			write_state(fd, &bit_received, sizeof(int));
			write_state(fd, &bits_received, sizeof(int));
			write_state(fd, &packets_received, sizeof(int));
			write_state(fd, &sgb_state, sizeof(int));
			write_state(fd, &sgb_index, sizeof(int));
			write_state(fd, &sgb_multiplayer, sizeof(int));
			write_state(fd, &sgb_fourplayers, sizeof(int));
			write_state(fd, &sgb_nextcontrol, sizeof(int));
			write_state(fd, &sgb_readingcontrol, sizeof(int));
			write_state(fd, &sgb_mask, sizeof(int));
			
			write_state(fd, sgb_palette, sizeof(unsigned short)*8*16);
			write_state(fd, sgb_palette_memory, sizeof(unsigned short)*512*4);
			write_state(fd, sgb_buffer, 7*16);
			write_state(fd, sgb_ATF, 18*20);
			write_state(fd, sgb_ATF_list, 45*20*18);
			/*
			sceIoWrite(fd, sgb_border, 2048);
			sceIoWrite(fd, sgb_borderchar, 32*256);
			
			int i, j, n=0;
			for (i=0; i<224; i++){
				for (j=0; j<256; j++){
					if (i>=40 && i<=183 && j==48) j=208;
					border_tmp[n++] = sgb_border_buffer[i*256+j];
				}
			}
			sceIoWrite(fd, border_tmp, sizeof(border_tmp));
			*/
		}
	}
	else if (rom_get_info()->gb_type>=3){ // GB Colour / GBA
		write_state(fd, cpu_get_ram(),0x2000*4); // ram
		write_state(fd, cpu_get_vram(),0x2000*2); // vram
		write_state(fd, get_sram(),tbl_ram[rom_get_info()->ram_size]*0x2000); // sram
		write_state(fd, cpu_get_oam(),0xA0);
		write_state(fd, cpu_get_stack(),0x80);

		int cpu_dat[16];
		cpu_save_state(cpu_dat);

		int page,ram_page;
		page=(mbc_get_rom()-get_rom())/0x4000;
		ram_page=(mbc_get_sram()-get_sram())/0x2000;

		write_state(fd, &page,sizeof(int)); // rom_page
		write_state(fd, &ram_page,sizeof(int)); // ram_page
		write_state(fd, cpu_dat+0,sizeof(int));//int_page	//color
		write_state(fd, cpu_dat+1,sizeof(int));//vram_page	//color

		int dmy=0;

		write_state(fd, cpu_get_c_regs(),sizeof(struct cpu_regs)); // cpu_reg
		write_state(fd, &g_regs,sizeof(struct gb_regs));//sys_reg
		write_state(fd, &cg_regs,sizeof(struct gbc_regs));//col_reg		//color
		write_state(fd, lcd_get_pal(0),sizeof(word)*(8*4*2));//palette	//color
		int halt=((*cpu_get_halt())?1:0);
		write_state(fd, &halt,sizeof(int));
		write_state(fd, &dmy,sizeof(int)); // 元の版ではシリアル通信通信満了までのクロック数

		int mbc_dat=mbc_get_state();
		write_state(fd, &mbc_dat,sizeof(int));//MBC

		int ext_is=mbc_is_ext_ram()?1:0;
		write_state(fd, &ext_is,sizeof(int));

		//その他諸々
		write_state(fd, cpu_dat+2,sizeof(int));	//color
		write_state(fd, cpu_dat+3,sizeof(int));	//color
		write_state(fd, cpu_dat+4,sizeof(int));	//color
		write_state(fd, cpu_dat+5,sizeof(int));	//color
		write_state(fd, cpu_dat+6,sizeof(int));	//color
		write_state(fd, cpu_dat+7,sizeof(int));	//color

		// ver 1.1 追加
		write_state(fd, apu_get_stat_cpu(),sizeof(struct apu_stat));
		write_state(fd, apu_get_mem(),0x30);
		write_state(fd, apu_get_stat_gen(),sizeof(struct apu_stat));

		byte resurved[256],reload=1;
		memset(resurved,0,256);
//		resurved[0]=1;
		write_state(fd, &reload,1);
		write_state(fd, resurved,256);//将来のために確保
	}

#ifdef CHEAT_SUPPORT
	if (buf || fd)
		cheat_create_cheat_map();
#endif

	return;
}