Пример #1
0
int load_normal(u8* dest, load_ptr *src, int actualsize, int expectedsize)
{
	if (actualsize<=expectedsize)
	{
		read_mem_block(dest,*src,actualsize);
		return actualsize;
	}
	else //(actualsize>expectedsize)
	{
		read_mem_block(dest,*src,expectedsize);
		seek_ahead(*src,actualsize-expectedsize);
		return expectedsize;
	}
}
Пример #2
0
void load_old_savestate(load_ptr *src)
{
	read_mem_block(&emuflags,*src,8); //emuflags, scaling settings, bg mirror
	read_mem_block(NES_RAM,*src,0x800);
	read_mem_block(NES_SRAM,*src,0x2000);
	if (has_vram)	{
		read_mem_block(NES_VRAM,*src,0x2000);
	} else {
		seek_ahead(*src,0x2000);
	}
	read_mem_block(NES_VRAM2,*src,0x800);
	if (fourscreen) {
		read_mem_block(NES_VRAM4,*src,0x800);
	} else {
		seek_ahead(*src,0x800);
	}
	seek_ahead(*src,64); //AGB palette
	read_mem_block(nes_palette,*src,32);
	
	
	//convert vram_map to nes_chr_map
	seek_ahead(*src,64);  //vram_map is unreadable
	seek_ahead(*src,16); //agb_nt_map, no longer used
	read_mem_block(mapperstate,*src,32);
	read_mem_block(nes_chr_map,*src,8);
	seek_ahead(*src,8); //skip duplicate of nes_chr_map
	read_mem_block(rommap,*src,16);
	{
		int i;
		for (i=0;i<4;i++)
		{
			bank8[i]=((int)rommap[i]+0x8000+8192*i)/8192;
		}
	}
	{
		u32 old_readmem;
		old_readmem = cpustate[1];
		read_mem_block(cpustate,*src,32);
		cpustate[1]=old_readmem;
	}
	read_mem_block(&lastbank,*src,4);
	seek_ahead(*src,8);
	m6502_s=(u8*) ((u32)m6502_s&0x3FF);
	m6502_pc=(u8*)((u32)m6502_pc-(u32)lastbank);
	lastbank=NULL;
	read_mem_block(ppustate,*src,32);
	nextx=scrollX;
}
Пример #3
0
int load_none(u8* dest, load_ptr *src, int actualsize, int expectedsize)
{
	seek_ahead(*src,actualsize);
	return -1;
}
Пример #4
0
bool loadstate(const char* filename)
#endif
{
	//save old values of Crash detector and sound volume
	//crash detector will become enabled, and sound will be muted later
	int old_crash_disabled = _crash_disabled;
	int soundvol;

	#if !MOVIEPLAYER
	u8* limit=src+statesize;
	load_ptr file=src;
	#else
	File file;
	#endif

	bool do_load=true;
	
	u32 tag;
	int size;
	
	//enable crash detector - if loading doesn't complete within 5 seconds, it crashed
	_crash_disabled = 0;
	
	//Set that no block has loaded yet, this is changed later when loadblock is called for each tag
	blocks_loaded = 0;

	#if MOVIEPLAYER
	file=FAT_fopen(filename,"r");
	if (file==NO_FILE)
	{
		do_load=false;
	}
	#endif

	if (do_load)
	{
		//Read old sound volume, and stop sound on GB channels
		soundvol=REG_SOUNDCNT_L;
		REG_SOUNDCNT_L=0;

		do
		{
			int tagid;
			//verify presence of VERS tag as first thing in file
			if (!read_u32(file,tag)) break;
			//look up tag
			tagid=tag_search(tag,tags,NUM_TAGS);
			if (tagid!=VERSION_TAG)
			{
				seek_ahead(file,-4);
				#if !MOVIEPLAYER
				//reboot game, but don't clear some stuff
				do_not_decompress=1;
				do_not_reset_all=1;
				loadcart(romnumber,emuflags,0);
				//Restore previous sound volume (fixme, we get audio playing while we re-decompress the game)
				REG_SOUNDCNT_L=soundvol;
				//Messes up variables so that the emulator won't run anymore (later we un-mess them)
				prepare_variables_for_savestate();
				do_not_decompress=0;
				do_not_reset_all=0;
				#endif
				load_old_savestate(&file);
				break;
			}
			else
			{
				if (!read_u32(file,size)) break;
				//discard version block
				loadblock(&file,tag,size);
				
				#if !MOVIEPLAYER
					//reboot game to a blank slate
					do_not_decompress=1;
					loadcart(romnumber,emuflags,0);
					//Restore sound volume
					REG_SOUNDCNT_L=soundvol;
					do_not_decompress=0;
				#endif
				
				//Messes up variables so that the emulator won't run anymore (later we un-mess them)
				prepare_variables_for_savestate();
				//load all other tags
				while (1)
				{
					if (!read_u32(file,tag)) break;
					if (!read_u32(file,size)) break;
					loadblock(&file,tag,size);
				}
			}
		} while (0);
		#if MOVIEPLAYER
		FAT_fclose(file);
		#endif
		//Now we restore the variables so the emulator runs again
		restore_variables_for_loadstate();
		restore_more_variables_for_loadstate();
	}
	//restore previous state of crash detector
	_crash_disabled = old_crash_disabled;

	#if MOVIEPLAYER
	return do_load;
	#endif
}
Пример #5
0
static Token* cmdline_parse(Cmdline *cmdline, Token *word, UT_array *parent)
{
  char ch;
  bool seek;
  Cmdstr cmd = {.ed = 0};
  if (word)
    cmd.st = word->start;

  QUEUE *stack = &cmd.stack;
  QUEUE_INIT(stack);

  cmd.args = list_new(cmdline);
  stack_push(stack, cmd.args);
  Token *headref = stack_head(stack);
  utarray_new(cmd.chlds, &chld_icd);

  check_flags(cmdline, &cmd);

  int idx = 0;
  while ((word = (Token*)utarray_next(cmdline->tokens, word))) {
    char *str = token_val(word, VAR_STRING);

    if (word->quoted) {
      push(*word, stack, word->start);
      pop(stack, cmdline, &idx);
      continue;
    }

    switch(ch = str[0]) {
      case '(':
        cmdline->lvl++;
        word = cmdline_parse(cmdline, word, cmd.chlds);
        ((Cmdstr*)utarray_back(cmd.chlds))->idx = idx - 1;
        if (!word)
          goto breakout;
        break;
      case ')':
        if (cmdline->lvl < 1)
          break;
        cmdline->lvl--;
        cmd.ed = word->start;
        goto breakout;
      case '[':
        push(list_new(cmdline), stack, word->start);
        stack_head(stack)->start = word->start;
        break;
      case ']':
        if (!valid_arry(cmdline, stack, headref))
          break;
        stack_head(stack)->end = word->end;
        push_arry_container(cmdline, headref, word);
        pop(stack, cmdline, &idx);
        break;
      case '|':
        if (cmdline->lvl < 1) {
          cmd.bar = true;
          cmd.ed = word->start;
          goto breakout;
        }
      /*FALLTHROUGH*/
      case '.':
      case ':':
      case ',':
        break;
      case '%':
      case '$':
        word = valid_var(cmdline, word, ch);
      case '!':
        if (valid_exec(cmdline, &cmd, word))
          break;
      /*FALLTHROUGH*/
      default:
        seek = seek_ahead(cmdline, stack, word);
        push(*word, stack, word->start);
        if (!seek)
          pop(stack, cmdline, &idx);
    }
  }
breakout:
  while (!QUEUE_EMPTY(stack))
    stack_pop(stack);

  utarray_push_back(parent, &cmd);
  return word;
}

void cmdline_build_tokens(Cmdline *cmdline, char *line)
{
  log_msg("CMDSTR", "cmdline_build_tokens");
  SWAP_ALLOC_PTR(cmdline->line, strdup(line));
  Token *word = NULL;
  while ((word = (Token*)utarray_next(cmdline->tokens, word)))
    free(word->var.vval.v_string);
  utarray_clear(cmdline->tokens);
  cmdline_tokenize(cmdline);
}