Skip to content

Commit

Permalink
Remove stuff related to rewinding, save state slots, and clean up sta…
Browse files Browse the repository at this point in the history
…te machine
  • Loading branch information
budude2 committed Aug 21, 2024
1 parent e4fb4b4 commit 2b929ac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 139 deletions.
7 changes: 1 addition & 6 deletions src/core/core_top.sv
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,9 @@ gb gb
.gg_available ( ),

// savestates
.increaseSSHeaderCount ( 0 ),
.cart_ram_size ( cart_ram_size ),
.save_state ( ss_save ),
.load_state ( ss_load ),
.savestate_number ( 0 ),
.sleep_savestate ( sleep_savestate ),

.SaveStateExt_Din ( SaveStateExt_Din ),
Expand All @@ -1017,10 +1015,7 @@ gb gb
.SAVE_out_rnw ( ss_rnw ), // read = 1, write = 0
.SAVE_out_ena ( ss_req ), // one cycle high for each action
.SAVE_out_be ( ss_be ),
.SAVE_out_done ( ss_ack ), // should be one cycle high when write is done or read value is valid

.rewind_on ( 0 ),
.rewind_active ( 0 )
.SAVE_out_done ( ss_ack ) // should be one cycle high when write is done or read value is valid
);

// Sound
Expand Down
29 changes: 5 additions & 24 deletions src/gb/gb.v
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ module gb (
output serial_data_out,

// savestates
input increaseSSHeaderCount,
input [7:0] cart_ram_size,
input save_state,
input load_state,
input [1:0] savestate_number,
output sleep_savestate,

output [63:0] SaveStateExt_Din,
Expand All @@ -114,10 +112,7 @@ module gb (
output SAVE_out_rnw, // read = 1, write = 0
output SAVE_out_ena, // one cycle high for each action
output [7:0] SAVE_out_be,
input SAVE_out_done, // should be one cycle high when write is done or read value is valid

input rewind_on,
input rewind_active
input SAVE_out_done // should be one cycle high when write is done or read value is valid
);

// savestates
Expand Down Expand Up @@ -678,7 +673,7 @@ wire [7:0] dma_data = (isGBC & dma_sel_wram) ? wram_do :
8'hFF;

video video (
.reset ( reset_ss ),
.reset ( reset_ss ),
.clk ( clk_sys ),
.ce ( ce ), // 4Mhz
.ce_cpu ( ce_cpu ), //can be 2x in cgb double speed mode
Expand All @@ -691,7 +686,6 @@ video video (
.irq ( video_irq ),
.vblank_irq ( vblank_irq ),


.cpu_sel_reg ( sel_video_reg ),
.cpu_sel_oam ( sel_video_oam ),
.cpu_addr ( cpu_addr[7:0] ),
Expand Down Expand Up @@ -1051,16 +1045,13 @@ wire [63:0] SaveStateBus_Dout = SaveStateBus_wired_or[0] | SaveStateBus_wired_o
SaveStateBus_wired_or[4] | SaveStateBus_wired_or[5] | SaveStateBus_wired_or[6] | SaveStateBus_wired_or[7] |
SaveStateExt_Dout;

wire sleep_rewind, sleep_savestates;

gb_savestates gb_savestates (
.clk (clk_sys),
.reset_in (reset_r),
.reset_out (reset_ss),

.load_done (savestate_loaded),

.increaseSSHeaderCount (increaseSSHeaderCount),
.save (savestate_savestate),
.load (savestate_loadstate),
.savestate_address (savestate_address),
Expand All @@ -1075,10 +1066,8 @@ gb_savestates gb_savestates (
.BUS_wren (SaveStateBus_wren),
.BUS_rst (SaveStateBus_rst),
.BUS_Dout (SaveStateBus_Dout),

//.loading_savestate (loading_savestate),
//.saving_savestate (saving_savestate),
.sleep_savestate (sleep_savestates),

.sleep_savestate (sleep_savestate),
.clock_ena_in (ce_2x),

.Save_RAMAddr (Savestate_RAMAddr),
Expand All @@ -1099,18 +1088,13 @@ gb_savestates gb_savestates (
.bus_out_done (SAVE_out_done)
);

gb_statemanager #(58720256, 33554432) gb_statemanager (
gb_statemanager #(58720256) gb_statemanager (
.clk (clk_sys),
.reset (reset_r),

.rewind_on (rewind_on),
.rewind_active (rewind_active),

.savestate_number (savestate_number),
.save (save_state),
.load (load_state),

.sleep_rewind (sleep_rewind),
.vsync (lcd_vsync),

.request_savestate (savestate_savestate),
Expand All @@ -1119,7 +1103,4 @@ gb_statemanager #(58720256, 33554432) gb_statemanager (
.request_busy (savestate_busy)
);

assign sleep_savestate = sleep_rewind | sleep_savestates;


endmodule
39 changes: 9 additions & 30 deletions src/gb/gb_savestates.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ entity gb_savestates is

load_done : out std_logic := '0';

increaseSSHeaderCount : in std_logic;
save : in std_logic;
load : in std_logic;
savestate_address : in integer;
Expand Down Expand Up @@ -82,7 +81,6 @@ architecture arch of gb_savestates is
SAVEINTERNALS_WRITE,
DELAY,
SAVEMEMORY_HDR,
--SAVEMEMORY_HDR_WAIT,
SAVEMEMORY_NEXT,
SAVEMEMORY_FIRST,
SAVEMEMORY_READ,
Expand Down Expand Up @@ -123,7 +121,7 @@ begin
begin
if rising_edge(clk) then

Save_RAMWrEn <= (others => '0');
Save_RAMWrEn <= (others => '0');
bus_out_ena <= '0';
BUS_wren <= '0';
BUS_rst <= '0';
Expand All @@ -148,7 +146,6 @@ 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 Down Expand Up @@ -189,12 +186,11 @@ begin
bus_out_ena <= '1';
state <= DELAY;

-- I need to make this delay bigger

when DELAY =>
bus_out_ena <= '0';
bus_out_ena <= '0';

if (bus_out_done = '1') then
state <= SAVEINTERNALS_WAIT;
state <= SAVEINTERNALS_WAIT;
end if;

when SAVEINTERNALS_WAIT =>
Expand All @@ -211,22 +207,9 @@ 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 @@ -236,10 +219,8 @@ begin
maxcount <= savetypes(savetype_counter);
Save_RAMAddr <= (others => '0');
else
state <= SAVESIZEAMOUNT;
if (increaseSSHeaderCount = '0') then
bus_out_be <= x"F0";
end if;
state <= SAVESIZEAMOUNT;
bus_out_be <= x"F0";
end if;

when SAVEMEMORY_FIRST =>
Expand Down Expand Up @@ -270,11 +251,9 @@ begin
end if;

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


-- #################
Expand Down
82 changes: 3 additions & 79 deletions src/gb/gb_statemanager.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@ use IEEE.numeric_std.all;
entity gb_statemanager is
generic
(
Softmap_SaveState_ADDR : integer; -- count: 262144 -- 256 Kbyte Data for Savestate
Softmap_Rewind_ADDR : integer -- count: 262144*128 -- 128*256 Kbyte Data for Savestates
Softmap_SaveState_ADDR : integer -- count: 262144 -- 256 Kbyte Data for Savestate
);
port
(
clk : in std_logic;
reset : in std_logic;

rewind_on : in std_logic;
rewind_active : in std_logic;

savestate_number : in integer;
save : in std_logic;
load : in std_logic;

sleep_rewind : out std_logic := '0';
vsync : in std_logic;

request_savestate : out std_logic := '0';
Expand All @@ -33,23 +27,12 @@ end entity;
architecture arch of gb_statemanager is

constant SAVESTATESIZE : integer := 16#10000#; -- 65536 Dwords = 256kbyte
constant REWIND_COUNT : integer := 128;
constant TIME_CAPTURE : integer := 10000000; -- 320 ms sim 1000000;
constant TIME_REWIND : integer := 5000000; -- 160 ms sim 1200000;

signal save_1 : std_logic := '0';
signal load_1 : std_logic := '0';
signal save_buffer : std_logic := '0';
signal load_buffer : std_logic := '0';

signal rewind_enabled : std_logic := '0';
signal rewind_load_next : std_logic := '0';

signal timer_rewind : integer range 0 to TIME_CAPTURE := 0;
signal rewind_slow : integer range 0 to TIME_REWIND := 0;
signal savestatecount : integer range 0 to REWIND_COUNT := 0;
signal savestatepos : integer range 0 to REWIND_COUNT - 1 := 0;

signal vsync_counter : integer range 0 to 2 := 0;

signal vsync_1 : std_logic;
Expand All @@ -62,7 +45,6 @@ begin

request_savestate <= '0';
request_loadstate <= '0';
rewind_load_next <= '0';

vsync_1 <= vsync;

Expand All @@ -76,79 +58,21 @@ begin
load_buffer <= '1';
end if;

if (rewind_on = '0' or reset = '1') then
rewind_enabled <= '0';
end if;

if (rewind_active = '0') then
rewind_slow <= 0;
elsif (rewind_slow < TIME_REWIND) then
rewind_slow <= rewind_slow + 1;
end if;

if (rewind_active = '1') then
timer_rewind <= 0;
elsif (timer_rewind < TIME_CAPTURE) then
timer_rewind <= timer_rewind + 1;
end if;

if (vsync_counter < 2 and vsync = '1' and vsync_1 = '0') then
vsync_counter <= vsync_counter + 1;
end if;

sleep_rewind <= '0';
if (vsync_counter = 2 and rewind_active = '1') then
sleep_rewind <= '1';
end if;

if (reset = '0' and request_busy = '0') then

if (save_buffer = '1') then
request_address <= Softmap_SaveState_ADDR + (savestate_number * SAVESTATESIZE);
request_address <= Softmap_SaveState_ADDR;
request_savestate <= '1';
save_buffer <= '0';
elsif (load_buffer = '1') then
request_address <= Softmap_SaveState_ADDR + (savestate_number * SAVESTATESIZE);
request_address <= Softmap_SaveState_ADDR;
request_loadstate <= '1';
load_buffer <= '0';
elsif (rewind_enabled = '0' and rewind_on = '1') then
request_address <= Softmap_Rewind_ADDR;
request_savestate <= '1';
rewind_enabled <= '1';
timer_rewind <= 0;
savestatecount <= 1;
savestatepos <= 1;
elsif (rewind_enabled = '1' and timer_rewind = TIME_CAPTURE) then
request_address <= Softmap_Rewind_ADDR + (savestatepos * SAVESTATESIZE);
request_savestate <= '1';
timer_rewind <= 0;
if (savestatecount < REWIND_COUNT) then
savestatecount <= savestatecount + 1;
end if;
if (savestatepos < (REWIND_COUNT - 1)) then
savestatepos <= savestatepos + 1;
else
savestatepos <= 0;
end if;
elsif (rewind_enabled = '1' and rewind_slow = TIME_REWIND) then
if (savestatecount > 1) then
savestatecount <= savestatecount - 1;
if (savestatepos > 0) then
savestatepos <= savestatepos - 1;
else
savestatepos <= REWIND_COUNT - 1;
end if;
rewind_load_next <= '1';
end if;
rewind_slow <= 0;
elsif (rewind_load_next = '1') then
request_address <= Softmap_Rewind_ADDR + (savestatepos * SAVESTATESIZE);
request_loadstate <= '1';
vsync_counter <= 0;
end if;

end if;

end if;
end process;

Expand Down

0 comments on commit 2b929ac

Please sign in to comment.