From 29aa9f2ccfa61a467dbbf56ebe09d10c195aedc8 Mon Sep 17 00:00:00 2001 From: birdybro Date: Fri, 8 Jul 2022 05:54:03 -0600 Subject: [PATCH] Add quirk for Ys (Japan) to fix graphics bug (#132) --- SMS.sv | 24 ++++++++++++++++++++++-- rtl/system.vhd | 3 +++ rtl/vdp.vhd | 2 ++ rtl/vdp_background.vhd | 18 ++++++++---------- rtl/vdp_main.vhd | 2 ++ 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/SMS.sv b/SMS.sv index 7f4be44..fab7068 100644 --- a/SMS.sv +++ b/SMS.sv @@ -498,6 +498,25 @@ sdramclk_ddr reg rom_wr = 0; wire sd_wrack; reg [23:0] romwr_a; +reg ysj_quirk = 0; + +always @(posedge clk_sys) begin + reg [31:0] cart_id; + reg old_download; + old_download <= cart_download; + + if(~old_download && cart_download) {ysj_quirk} <= 0; + + if(ioctl_wr & cart_download) begin + if(ioctl_addr == 'h7ffc) cart_id[31:24] <= ioctl_dout[7:0]; + if(ioctl_addr == 'h7ffd) cart_id[23:16] <= ioctl_dout[7:0]; + if(ioctl_addr == 'h7ffe) cart_id[15:08] <= ioctl_dout[7:0]; + if(ioctl_addr == 'h7fff) cart_id[07:00] <= ioctl_dout[7:0]; + if(ioctl_addr == 'h8000) begin + if(cart_id == 32'h13_70_01_4F) ysj_quirk <= 1; // Ys (Japan) Graphics Fix, forces VDP Version 1 + end + end +end always @(posedge clk_sys) begin reg old_download, old_reset; @@ -673,6 +692,7 @@ system #(63) system .smode_M1(smode_M1), .smode_M2(smode_M2), .smode_M3(smode_M3), + .ysj_quirk(ysj_quirk), .pal(pal), .region(status[10]), .mapper_lock(status[15] && ~systeme), @@ -777,7 +797,7 @@ always @(posedge clk_sys) begin joya_th <= swap ? 1'b1 : joyser_th; joyb_th <= swap ? joyser_th : 1'b1; - USER_OUT <= {swap ? joyb_tr_out : joya_tr_out, 1'b1, swap ? joyb_th_out : joya_th_out, 4'b1111, }; + USER_OUT <= {swap ? joyb_tr_out : joya_tr_out, 1'b1, swap ? joyb_th_out : joya_th_out, 4'b1111 }; end else begin joya <= ~joy[jcnt]; @@ -861,7 +881,7 @@ video video .border(border), .mask_column(mask_column), .cut_mask(status[29]), - .smode_M1(smode_M1), + .smode_M1(smode_M1), .smode_M3(smode_M3), .x(x), .y(y), diff --git a/rtl/system.vhd b/rtl/system.vhd index 6f4648d..2ca0082 100644 --- a/rtl/system.vhd +++ b/rtl/system.vhd @@ -82,6 +82,7 @@ entity system is smode_M1: out STD_LOGIC; smode_M2: out STD_LOGIC; smode_M3: out STD_LOGIC; + ysj_quirk: in STD_LOGIC; pal: in STD_LOGIC; region: in STD_LOGIC; mapper_lock: in STD_LOGIC; @@ -349,6 +350,7 @@ begin smode_M1 => smode_M1, smode_M2 => smode_M2, smode_M3 => smode_M3, + ysj_quirk => ysj_quirk, mask_column => mask_column, black_column => black_column, reset_n => RESET_n @@ -385,6 +387,7 @@ begin -- smode_M1 => smode2_M1, -- smode_M2 => smode2_M2, -- smode_M3 => smode2_M3, + ysj_quirk => ysj_quirk, -- mask_column => mask2_column, black_column => black_column, reset_n => RESET_n diff --git a/rtl/vdp.vhd b/rtl/vdp.vhd index 6fdd578..ef09195 100644 --- a/rtl/vdp.vhd +++ b/rtl/vdp.vhd @@ -35,6 +35,7 @@ entity vdp is smode_M2: out STD_LOGIC; smode_M3: out STD_LOGIC; smode_M4: out STD_LOGIC; + ysj_quirk: in STD_LOGIC; reset_n: in STD_LOGIC); end vdp; @@ -144,6 +145,7 @@ begin smode_M1 => xmode_M1, smode_M3 => xmode_M3, smode_M4 => xmode_M4, + ysj_quirk => ysj_quirk, display_on => display_on, mask_column0 => mask_column0, diff --git a/rtl/vdp_background.vhd b/rtl/vdp_background.vhd index e86d38d..97474db 100644 --- a/rtl/vdp_background.vhd +++ b/rtl/vdp_background.vhd @@ -16,6 +16,7 @@ port ( smode_M1: in std_logic; smode_M3: in std_logic; smode_M4: in std_logic; + ysj_quirk: in std_logic; y: in std_logic_vector(7 downto 0); screen_y: in std_logic_vector(8 downto 0); @@ -85,16 +86,13 @@ begin char_address(12 downto 5) := table_address(13 downto 12) & ("011100" + y(7 downto 3)); else char_address(12 downto 10) := table_address(13 downto 11); - - -- To enable version 1 of the VDP found on the SMS version 1, and you'd want to do that - -- to play only one game : Japanese version of "Ys", you can re-enable the comment in the next code line. - -- - -- Since there seems to be no difference between the Japanese version of Ys and the US one, there is no reasonable need - -- to implement a way to select the code below manually or automatically. - - char_address(9) := -- table_address(10) and - y(7) ; - char_address(8 downto 5) := y(6 downto 3); + if ysj_quirk = '1' then -- Enable VDP version 1 for Ys (Japan) + char_address(9) := table_address(10) and y(7); + char_address(8 downto 5) := y(6 downto 3); + else + char_address(9) := y(7); + char_address(8 downto 5) := y(6 downto 3); + end if; end if; char_address(4 downto 0) := x(7 downto 3) + 1; data_address := tile_index & tile_y; diff --git a/rtl/vdp_main.vhd b/rtl/vdp_main.vhd index fd87851..270aae3 100644 --- a/rtl/vdp_main.vhd +++ b/rtl/vdp_main.vhd @@ -31,6 +31,7 @@ entity vdp_main is smode_M1: in std_logic; smode_M3: in std_logic; smode_M4: in std_logic; + ysj_quirk: in std_logic; overscan: in std_logic_vector (3 downto 0); bg_address: in std_logic_vector (3 downto 0); @@ -104,6 +105,7 @@ begin smode_M1 => smode_M1, smode_M3 => smode_M3, smode_M4 => smode_M4, + ysj_quirk => ysj_quirk, priority => bg_priority);