Full savestating to memory
This commit is contained in:
@ -135,6 +135,13 @@ typedef struct {
|
||||
|
||||
} audio_context;
|
||||
|
||||
typedef struct {
|
||||
audio_context ctx;
|
||||
} audio_state;
|
||||
|
||||
void audio_save_state(audio_state*);
|
||||
void audio_load_state(const audio_state*);
|
||||
|
||||
void audio_init();
|
||||
void audio_tick();
|
||||
void audio_period_tick();
|
||||
|
@ -19,6 +19,46 @@ typedef struct {
|
||||
u16 global_checksum;
|
||||
} rom_header;
|
||||
|
||||
typedef struct {
|
||||
char filename[1024];
|
||||
u32 rom_size;
|
||||
u8 *rom_data;
|
||||
rom_header *header;
|
||||
|
||||
//mbc1 data
|
||||
bool ram_enabled;
|
||||
bool ram_banking;
|
||||
|
||||
u8 *rom_bank_x;
|
||||
u8 *rom_bank_x2;
|
||||
u8 banking_mode;
|
||||
|
||||
u8 rom_bank_value;
|
||||
u8 rom_bank_value_2;
|
||||
u8 ram_bank_value;
|
||||
|
||||
u8 *ram_bank;
|
||||
u8 *ram_banks[16];
|
||||
|
||||
//battery
|
||||
bool battery;
|
||||
bool need_save;
|
||||
} cart_context;
|
||||
|
||||
typedef struct {
|
||||
bool ram_enabled;
|
||||
bool ram_banking;
|
||||
u8 banking_mode;
|
||||
u8 rom_bank_value;
|
||||
u8 rom_bank_value_2;
|
||||
u8 ram_bank_value;
|
||||
u8 ram_banks[16][0x2000];
|
||||
bool need_save;
|
||||
} cart_state;
|
||||
|
||||
void cart_load_state(const cart_state*);
|
||||
void cart_save_state(cart_state*);
|
||||
|
||||
bool cart_load(char *cart);
|
||||
|
||||
rom_header *get_rom_header();
|
||||
|
@ -35,6 +35,13 @@ typedef struct {
|
||||
u8 int_flags;
|
||||
} cpu_context;
|
||||
|
||||
typedef struct {
|
||||
cpu_context ctx;
|
||||
} cpu_state;
|
||||
|
||||
void cpu_save_state(cpu_state*);
|
||||
void cpu_load_state(const cpu_state*);
|
||||
|
||||
void cpu_init();
|
||||
bool cpu_step();
|
||||
|
||||
|
@ -2,6 +2,20 @@
|
||||
|
||||
#include <common.h>
|
||||
|
||||
typedef struct {
|
||||
bool active;
|
||||
u8 byte;
|
||||
u8 value;
|
||||
u8 start_delay;
|
||||
} dma_context;
|
||||
|
||||
typedef struct {
|
||||
dma_context ctx;
|
||||
} dma_state;
|
||||
|
||||
void dma_save_state(dma_state*);
|
||||
void dma_load_state(const dma_state*);
|
||||
|
||||
void dma_start(u8 start);
|
||||
void dma_tick();
|
||||
|
||||
|
@ -14,4 +14,7 @@ typedef struct {
|
||||
int emu_run(int, char**);
|
||||
emu_context *emu_get_context();
|
||||
|
||||
void emu_cycles(int cpu_cycles);
|
||||
void emu_cycles(int cpu_cycles);
|
||||
void emu_reset();
|
||||
void emu_stop();
|
||||
void emu_start();
|
@ -13,6 +13,20 @@ typedef struct {
|
||||
bool right;
|
||||
} gamepad_state;
|
||||
|
||||
typedef struct {
|
||||
bool button_sel;
|
||||
bool dir_sel;
|
||||
gamepad_state controller;
|
||||
gamepad_state prev;
|
||||
} gamepad_context;
|
||||
|
||||
typedef struct {
|
||||
gamepad_context ctx;
|
||||
} ctlr_state;
|
||||
|
||||
void gamepad_save_state(ctlr_state*);
|
||||
void gamepad_load_state(const ctlr_state*);
|
||||
|
||||
void gamepad_init();
|
||||
bool gamepad_button_sel();
|
||||
bool gamepad_dir_sel();
|
||||
|
@ -29,6 +29,13 @@ typedef enum {
|
||||
MODE_XFER
|
||||
} lcd_mode;
|
||||
|
||||
typedef struct {
|
||||
lcd_context ctx;
|
||||
} lcd_state;
|
||||
|
||||
void lcd_save_state(lcd_state*);
|
||||
void lcd_load_state(const lcd_state*);
|
||||
|
||||
lcd_context *lcd_get_context();
|
||||
|
||||
#define LCDC_BGW_ENABLE (BIT(lcd_get_context()->lcdc, 0))
|
||||
|
@ -86,6 +86,13 @@ typedef struct {
|
||||
bool debug;
|
||||
} ppu_context;
|
||||
|
||||
typedef struct {
|
||||
ppu_context ctx;
|
||||
} ppu_state;
|
||||
|
||||
void ppu_save_state(ppu_state*);
|
||||
void ppu_load_state(const ppu_state*);
|
||||
|
||||
void ppu_init();
|
||||
void ppu_tick();
|
||||
|
||||
|
@ -2,6 +2,18 @@
|
||||
|
||||
#include <common.h>
|
||||
|
||||
typedef struct {
|
||||
u8 wram[0x2000];
|
||||
u8 hram[0x80];
|
||||
} ram_context;
|
||||
|
||||
typedef struct {
|
||||
ram_context ctx;
|
||||
} ram_state;
|
||||
|
||||
void ram_save_state(ram_state*);
|
||||
void ram_load_state(const ram_state*);
|
||||
|
||||
u8 wram_read(u16 address);
|
||||
void wram_write(u16 address, u8 value);
|
||||
|
||||
|
25
include/state.h
Normal file
25
include/state.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include <audio.h>
|
||||
#include <cpu.h>
|
||||
#include <ppu.h>
|
||||
#include <cart.h>
|
||||
#include <dma.h>
|
||||
#include <gamepad.h>
|
||||
#include <ram.h>
|
||||
#include <timer.h>
|
||||
#include <lcd.h>
|
||||
|
||||
typedef struct {
|
||||
audio_state audio;
|
||||
ppu_state ppu;
|
||||
cpu_state cpu;
|
||||
cart_state cart;
|
||||
dma_state dma;
|
||||
ctlr_state ctlr;
|
||||
ram_state ram;
|
||||
timer_state timer;
|
||||
lcd_state lcd;
|
||||
} save_state;
|
||||
|
||||
void state_save(save_state*);
|
||||
void state_load(const save_state*);
|
@ -9,6 +9,13 @@ typedef struct {
|
||||
u8 tac;
|
||||
} timer_context;
|
||||
|
||||
typedef struct {
|
||||
timer_context ctx;
|
||||
} timer_state;
|
||||
|
||||
void timer_save_state(timer_state*);
|
||||
void timer_load_state(const timer_state*);
|
||||
|
||||
void timer_init();
|
||||
void timer_tick();
|
||||
|
||||
|
Reference in New Issue
Block a user