Skip to content

Commit

Permalink
Save states should be working now
Browse files Browse the repository at this point in the history
  • Loading branch information
budude2 committed Aug 20, 2024
1 parent 95cff9f commit c30aef8
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions src/gb/gb_savestates.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ end entity;

architecture arch of gb_savestates is

--constant STATESIZE : integer := 16#B0CA#;
constant STATESIZE : integer := 16#0000#;
constant STATESIZE : integer := 16#B0CA#;

constant SETTLECOUNT : integer := 100;
constant HEADERCOUNT : integer := 2;
Expand All @@ -81,6 +80,9 @@ architecture arch of gb_savestates is
SAVE_WAITSETTLE,
SAVEINTERNALS_WAIT,
SAVEINTERNALS_WRITE,
DELAY,
SAVEMEMORY_HDR,
--SAVEMEMORY_HDR_WAIT,
SAVEMEMORY_NEXT,
SAVEMEMORY_FIRST,
SAVEMEMORY_READ,
Expand Down Expand Up @@ -146,6 +148,7 @@ begin
reset_out <= '1';
BUS_rst <= '1';
elsif (save = '1') then
--state <= SAVE_WAITVSYNC;
state <= SAVE_WAITVSYNC;
header_amount <= header_amount + 1;
elsif (load = '1') then
Expand All @@ -157,8 +160,10 @@ begin
-- #################
-- SAVE
-- #################

when SAVE_WAITVSYNC =>
bus_out_ena <= '0';

if (lcd_vsync = '1') then
state <= SAVE_WAITSETTLE;
settle <= 0;
Expand All @@ -171,13 +176,26 @@ begin
elsif (settle < SETTLECOUNT) then
settle <= settle + 1;
else
state <= SAVEINTERNALS_WAIT;
state <= SAVEMEMORY_HDR;
bus_out_Adr <= std_logic_vector(to_unsigned(savestate_address + HEADERCOUNT, 26));
bus_out_rnw <= '0';
BUS_adr <= (others => '0');
count <= 1;
saving_savestate <= '1';
end if;
end if;

when SAVEMEMORY_HDR =>
bus_out_Din <= std_logic_vector(to_unsigned(STATESIZE, 32)) & std_logic_vector(header_amount);
bus_out_ena <= '1';
state <= DELAY;

-- I need to make this delay bigger

when DELAY =>
bus_out_ena <= '0';
if (bus_out_done = '1') then
state <= SAVEINTERNALS_WAIT;
end if;

when SAVEINTERNALS_WAIT =>
bus_out_Din <= BUS_Dout;
Expand All @@ -193,9 +211,22 @@ begin
BUS_adr <= std_logic_vector(unsigned(BUS_adr) + 1);
else
state <= SAVEMEMORY_NEXT;
--state <= SAVEMEMORY_HDR;
count <= 8;
end if;
end if;

--when SAVEMEMORY_HDR_WAIT =>
-- bus_out_Adr <= std_logic_vector(to_unsigned(savestate_address, 26));
-- bus_out_Din <= std_logic_vector(to_unsigned(STATESIZE, 32)) & std_logic_vector(header_amount);
-- bus_out_ena <= '0';
-- if (count < INTERNALSCOUNT) then
-- state <= SAVEMEMORY_HDR_WAIT;
-- count <= count + 1;
-- else
-- state <= SAVEMEMORY_NEXT;
-- count <= 8;
-- end if;

when SAVEMEMORY_NEXT =>
if (savetype_counter < SAVETYPESCOUNT) then
Expand All @@ -206,9 +237,6 @@ begin
Save_RAMAddr <= (others => '0');
else
state <= SAVESIZEAMOUNT;
bus_out_Adr <= std_logic_vector(to_unsigned(savestate_address, 26));
bus_out_Din <= std_logic_vector(to_unsigned(STATESIZE, 32)) & std_logic_vector(header_amount);
bus_out_ena <= '1';
if (increaseSSHeaderCount = '0') then
bus_out_be <= x"F0";
end if;
Expand Down Expand Up @@ -242,11 +270,11 @@ begin
end if;

when SAVESIZEAMOUNT =>
if (bus_out_done = '1') then
--if (bus_out_done = '1') then
state <= IDLE;
saving_savestate <= '0';
sleep_savestate <= '0';
end if;
--end if;


-- #################
Expand Down

0 comments on commit c30aef8

Please sign in to comment.