Example #1
0
int get_save_state_size(void){
    int ssize = 0;
    
    //davex: header is not saved in a memory state
    
    ssize = sizeof(vdp_t); // VDP context
    ssize += sizeof(sms_t); //SMS context (1/3)
    //SMS context (2/3)
    ssize += 1; //fputc(cart.fcr[0], fd); 
    ssize += 1; //fputc(cart.fcr[1], fd);
    ssize += 1; //fputc(cart.fcr[2], fd);
    ssize += 1; //fputc(cart.fcr[3], fd);
    //SMS context (3/3)
    ssize += 0x8000;
    
    //Z80 context
    ssize += sizeof(Z80_Regs);
    ssize += sizeof(int);
    
    //YM2413 context
    ssize += FM_GetContextSize();
    
    //SN76489 context
    ssize += SN76489_GetContextSize();
    
    return ssize;
}
Example #2
0
void system_save_state(void *fd)
{
    char *id = STATE_HEADER;
    uint16 version = STATE_VERSION;

    /* Write header */
    fwrite(id, sizeof(id), 1, fd);
    fwrite(&version, sizeof(version), 1, fd);

    /* Save VDP context */
    fwrite(&vdp, sizeof(vdp_t), 1, fd);

    /* Save SMS context */
    fwrite(&sms, sizeof(sms_t), 1, fd);

    fputc(cart.fcr[0], fd);
    fputc(cart.fcr[1], fd);
    fputc(cart.fcr[2], fd);
    fputc(cart.fcr[3], fd);
    fwrite(cart.sram, 0x8000, 1, fd);

    /* Save Z80 context */
    fwrite(Z80_Context, sizeof(Z80_Regs), 1, fd);
    fwrite(&after_EI, sizeof(int), 1, fd);

    /* Save YM2413 context */
    fwrite(FM_GetContextPtr(), FM_GetContextSize(), 1, fd);

    /* Save SN76489 context */
    fwrite(SN76489_GetContextPtr(0), SN76489_GetContextSize(), 1, fd);
}
Example #3
0
int sound_context_save(uint8 *state)
{
    int bufferptr = 0;

    if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
    {
        bufferptr = YM2612SaveContext(state);
    }
    else
    {
        save_param(YM2413GetContextPtr(),YM2413GetContextSize());
    }

    save_param(SN76489_GetContextPtr(),SN76489_GetContextSize());

    save_param(&fm_cycles_start,sizeof(fm_cycles_start));

    return bufferptr;
}
Example #4
0
int save_state_to_mem(void *stor){
	
	
    //davex: header is not saved in a memory state
    
    memcpy(stor, &vdp, sizeof(vdp_t)); //VDP context
    stor += sizeof(vdp_t);
    
    //SMS context (1/3)
    memcpy(stor, &sms, sizeof(sms_t) );
    stor += sizeof(sms_t); 
    
    //SMS context (2/3)
    memcpy(stor, &cart.fcr[0], 1 );
    stor += 1; 
    memcpy(stor, &cart.fcr[1], 1 );
    stor += 1; 
    memcpy(stor, &cart.fcr[2], 1 );
    stor += 1; 
    memcpy(stor, &cart.fcr[3], 1 );
    stor += 1; 
        
    //SMS context (3/3)
    memcpy(stor, &cart.sram, 0x8000);
    stor += 0x8000;
    

    // Z80 context 
    memcpy( stor, Z80_Context, sizeof(Z80_Regs) );
    stor += sizeof(Z80_Regs);
    memcpy( stor, &after_EI, sizeof(int) );
    stor += sizeof(int);
    
    
    // YM2413 context
    memcpy( stor, FM_GetContextPtr(), FM_GetContextSize() );
    stor += FM_GetContextSize();
    
    // SN76489 context
    memcpy(stor, SN76489_GetContextPtr(0),  SN76489_GetContextSize() );
    //stor += SN76489_GetContextSize();
    return 1;
}
Example #5
0
int sound_context_load(uint8 *state)
{
    int bufferptr = 0;

    if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
    {
        bufferptr = YM2612LoadContext(state);
        YM2612Config(config.dac_bits);
    }
    else
    {
        load_param(YM2413GetContextPtr(),YM2413GetContextSize());
    }

    load_param(SN76489_GetContextPtr(),SN76489_GetContextSize());

    load_param(&fm_cycles_start,sizeof(fm_cycles_start));
    fm_cycles_count = fm_cycles_start;

    return bufferptr;
}
Example #6
0
int state_load(unsigned char *buffer)
{
  /* buffer size */
  int bufferptr = 0;

  /* uncompress savestate */
  unsigned long inbytes, outbytes;
  memcpy(&inbytes, buffer, 4);
  outbytes = STATE_SIZE;
  uncompress ((Bytef *)state, &outbytes, (Bytef *)(buffer + 4), inbytes);

  /* version check */
  char version[16];
  load_param(version,16);
  if (strncmp(version,STATE_VERSION,16))
  {
    return 0;
  }

  /* reset system */
  system_reset();
  m68k_memory_map[0].base = default_rom;

  // GENESIS
  load_param(work_ram, sizeof(work_ram));
  load_param(zram, sizeof(zram));
  load_param(&zbusreq, sizeof(zbusreq));
  load_param(&zreset, sizeof(zreset));
  load_param(&zbank, sizeof(zbank));
  zbusack = 1 ^(zbusreq & zreset);

  // IO
  load_param(io_reg, sizeof(io_reg));

  // VDP
  uint8 temp_reg[0x20];
  load_param(sat, sizeof(sat));
  load_param(vram, sizeof(vram));
  load_param(cram, sizeof(cram));
  load_param(vsram, sizeof(vsram));
  load_param(temp_reg, sizeof(temp_reg));
  load_param(&addr, sizeof(addr));
  load_param(&addr_latch, sizeof(addr_latch));
  load_param(&code, sizeof(code));
  load_param(&pending, sizeof(pending));
  load_param(&status, sizeof(status));
  load_param(&dmafill, sizeof(dmafill));
  load_param(&hint_pending, sizeof(hint_pending));
  load_param(&vint_pending, sizeof(vint_pending));
  load_param(&irq_status, sizeof(irq_status));
  vdp_restore(temp_reg);

  // FM 
  YM2612Restore(&state[bufferptr]);
  bufferptr+= YM2612GetContextSize();

  // PSG
  load_param(SN76489_GetContextPtr(),SN76489_GetContextSize());

  // 68000 
  uint16 tmp16;
  uint32 tmp32;
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_D0, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_D1, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_D2, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_D3, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_D4, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_D5, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_D6, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_D7, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_A0, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_A1, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_A2, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_A3, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_A4, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_A5, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_A6, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_A7, tmp32);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_PC, tmp32);  
  load_param(&tmp16, 2); m68k_set_reg(M68K_REG_SR, tmp16);
  load_param(&tmp32, 4); m68k_set_reg(M68K_REG_USP,tmp32);

  // Z80 
  load_param(&Z80, sizeof(Z80_Regs));

  return 1;
}
Example #7
0
int state_save(unsigned char *buffer)
{
  /* buffer size */
  int bufferptr = 0;

  /* version string */
  char version[16];
  strncpy(version,STATE_VERSION,16);
  save_param(version, 16);

  // GENESIS
  save_param(work_ram, sizeof(work_ram));
  save_param(zram, sizeof(zram));
  save_param(&zbusreq, sizeof(zbusreq));
  save_param(&zreset, sizeof(zreset));
  save_param(&zbank, sizeof(zbank));

  // IO
  save_param(io_reg, sizeof(io_reg));

  // VDP
  save_param(sat, sizeof(sat));
  save_param(vram, sizeof(vram));
  save_param(cram, sizeof(cram));
  save_param(vsram, sizeof(vsram));
  save_param(reg, sizeof(reg));
  save_param(&addr, sizeof(addr));
  save_param(&addr_latch, sizeof(addr_latch));
  save_param(&code, sizeof(code));
  save_param(&pending, sizeof(pending));
  save_param(&status, sizeof(status));
  save_param(&dmafill, sizeof(dmafill));
  save_param(&hint_pending, sizeof(hint_pending));
  save_param(&vint_pending, sizeof(vint_pending));
  save_param(&irq_status, sizeof(irq_status));

  // FM 
  save_param(YM2612GetContextPtr(),YM2612GetContextSize());

  // PSG 
  save_param(SN76489_GetContextPtr(),SN76489_GetContextSize());

  // 68000 
  uint16 tmp16;
  uint32 tmp32;
  tmp32 = m68k_get_reg(NULL, M68K_REG_D0);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_D1);   save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_D2);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_D3);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_D4);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_D5);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_D6);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_D7);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_A0);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_A1);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_A2);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_A3);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_A4);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_A5);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_A6);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_A7);  save_param(&tmp32, 4);
  tmp32 = m68k_get_reg(NULL, M68K_REG_PC);  save_param(&tmp32, 4);
  tmp16 = m68k_get_reg(NULL, M68K_REG_SR);  save_param(&tmp16, 2); 
  tmp32 = m68k_get_reg(NULL, M68K_REG_USP);  save_param(&tmp32, 4);

  // Z80 
  save_param(&Z80, sizeof(Z80_Regs));

  /* compress state file */
  unsigned long inbytes   = bufferptr;
  unsigned long outbytes  = STATE_SIZE;
  compress2 ((Bytef *)(buffer + 4), &outbytes, (Bytef *)state, inbytes, 9);
  memcpy(buffer, &outbytes, 4);

  /* return total size */
  return (outbytes + 4);
}
Example #8
0
void system_load_state(void *fd)
{
    int i;
    uint8 *buf;
    char id[4];
    uint16 version;

    /* Initialize everything */
    z80_reset(0);
    z80_set_irq_callback(sms_irq_callback);
    system_reset();
    if(snd.enabled)
        sound_reset();

    /* Read header */
    fread(id, 4, 1, fd);
    fread(&version, 2, 1, fd);

    /* Load VDP context */
    fread(&vdp, sizeof(vdp_t), 1, fd);

    /* Load SMS context */
    fread(&sms, sizeof(sms_t), 1, fd);

    cart.fcr[0] = fgetc(fd);
    cart.fcr[1] = fgetc(fd);
    cart.fcr[2] = fgetc(fd);
    cart.fcr[3] = fgetc(fd);
    fread(cart.sram, 0x8000, 1, fd);

    /* Load Z80 context */
    fread(Z80_Context, sizeof(Z80_Regs), 1, fd);
    fread(&after_EI, sizeof(int), 1, fd);

    /* Load YM2413 context */
    buf = malloc(FM_GetContextSize());
    fread(buf, FM_GetContextSize(), 1, fd);
    FM_SetContext(buf);
    free(buf);

    /* Load SN76489 context */
    buf = malloc(SN76489_GetContextSize());
    fread(buf, SN76489_GetContextSize(), 1, fd);
    SN76489_SetContext(0, buf);
    free(buf);

    /* Restore callbacks */
    z80_set_irq_callback(sms_irq_callback);

    for(i = 0x00; i <= 0x2F; i++)
    {
        cpu_readmap[i]  = &cart.rom[(i & 0x1F) << 10];
        cpu_writemap[i] = dummy_write;
    }

    for(i = 0x30; i <= 0x3F; i++)
    {
        cpu_readmap[i] = &sms.wram[(i & 0x07) << 10];
        cpu_writemap[i] = &sms.wram[(i & 0x07) << 10];
    }

    sms_mapper_w(3, cart.fcr[3]);
    sms_mapper_w(2, cart.fcr[2]);
    sms_mapper_w(1, cart.fcr[1]);
    sms_mapper_w(0, cart.fcr[0]);

    /* Force full pattern cache update */
    bg_list_index = 0x200;
    for(i = 0; i < 0x200; i++)
    {
        bg_name_list[i] = i;
        bg_name_dirty[i] = -1;
    }

    /* Restore palette */
    for(i = 0; i < PALETTE_SIZE; i++)
        palette_sync(i, 1);

    viewport_check();
}