-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doom - broken enemy behavior #295
Comments
I can confirm the behavior on enemies at range using your method posted on the message board. Episode 3, from the start on an original model SD2SNES, enemies fire at you quite furiously. On MiSTer, they do virtually nothing. |
https://www.youtube.com/watch?v=Tzc3e-W6z78 - video provided by MiSTerFPGA forum user "Stupid Dufus" showing the difference in behavior. Would you test these roms on your SD2SNES and let us know the results? Thank you! I'm suspecting it has to do with the GSU test failing if that does pass on your OG hardware, because the dev of the sd2snes had to fix that to make super fx 2 games work right. |
Sure, I'll try to test this evening. |
From each of the test ROMs folder - excuse the lousy formatting. Tests are on an SD2SNES Rev. F with 1.10.3-frs-v12 firmware (furious firmware) installed, no in-game hooks enabled. SNES is a somewhat uncommon 2/1/2, unmodified. blargg_2010-03-14 test_timer_stop2: Failed blobs irq - red screen multidiv_tests div_behavior: Passed nmi_irq - red screen snes_mul_div_timing div_timing: Passed KungFuKirby irq - red screen ladida-lol white screen with red gradient at bottom PeterLemon GSUTest: All passed |
Thank you so much for the help. I passed this along with a summary and description into the mister discord as well in the core-bugs channel. This kind of testing is thorough and very helpful! :) |
Sure, glad I can help in some small way! It's y'all that are doing the real work. |
I don't really do much, just test things and try to gather information. The devs do all the real work. In summary, the DOOM SNES port's source code shows 143 uses of the Super FX 2's specific instruction "LMULT". The GSUTest rom mentioned above fails the LMULT test. The developer of the SD2SNES had to fix the Super FX and FX 2 implementations to get the GSUTest roms to completely pass in order to fix all known bugs as well, back in 2018 I think it was. So, it's plausible that the AI is broken for because LMULT is not working "perfectly" yet. Hard to tell though. |
Thought I'd seen you commit a few things around here. At any rate, very grateful for your help, and obviously the devs and their hard work. |
Very little, mostly just readme updates, and any code I have contributed has been me having my hand held by Kitrinx and sorgelig, as I'm a total newbie. Thanks for noticing :) |
Some notes I took to try and help if anyone wants to tackle this one day: GSUTEST LMULT ROMHere is the result on the MiSTer: For the Rn/Op = Source code for the LMULT test rom and the rom itself here --> LMULT.zip https://github.com/PeterLemon/SNES/blob/master/CHIP/GSU/GSUTest/LMULT/GSULMULT_gsu.asmstop // Stop GSU
nop // Delay Slot
iwt r4, #$FFFF // R4 = $FFFF
iwt r6, #$0000 // R6 = $0000
with r4 ; lmult // R4 *= R6
stop // Stop GSU
nop // Delay Slot
iwt r4, #$FFFF // R4 = $FFFF
iwt r6, #$0800 // R6 = $0800
with r4 ; lmult // R4 *= R6 Doom-FX Source Code from @RandalLinden153 uses of the LMULT instruction in the source code in total. LMULT's use is described in the sfx.txt file: https://github.com/RandalLinden/DOOM-FX/blob/master/docs/sfx.txt
Likely related source code files where LMULT is usedReality Engine (RandalLinden made his own game engine for the DOOM port) files where LMULT is used:
There's much more which I'm assuming aren't as relevant, but hopefully some of this points someone in the right direction eventually. From what I am ignorantly assuming LMULT is used frequently in the x and y deltas for movement and for enemy targeting in general. Given the bug shows that on certain difficulty settings the monsters just can't seem to target the player and their movement gets stuck, it seems likely the math is just incorrect on this. It seems to be a bug that only works when SNES_MiSTer code snippetshttps://github.com/MiSTer-devel/SNES_MiSTer/blob/master/rtl/chip/GSU/GSU_PKG.vhd--line351
((OP_FMULT, 5), (OP_LMULT, 5), (OP_FMULT, 5), (OP_FMULT, 5)), --FMULT / LMULT
-- https://github.com/MiSTer-devel/SNES_MiSTer/blob/master/rtl/chip/GSU/GSU.vhd--line 424
OP_CYCLES <= "000" when TURBO = '1' else
not (MS0 and not SPEED) & "10" when OP.OP = OP_FMULT or OP.OP = OP_LMULT else
"00" & not (MS0 and not SPEED) when OP.OP = OP_MULT or OP.OP = OP_UMULT else
"000";
--line 870
begin
A := unsigned(R(to_integer(SREG)));
if FLAG_ALT2 = '1' and (OP.OP = OP_ADD or OP.OP = OP_SUB or OP.OP = OP_AND or OP.OP = OP_MULT or OP.OP = OP_UMULT or OP.OP = OP_OR or OP.OP = OP_XOR) then
B := x"000" & OP_N;
else
B := unsigned(R(to_integer(OP_N)));
end if;
ALUR <= (others => '0');
MULR <= (others => '0');
ALUOV <= FLAG_OV;
ALUCY <= FLAG_CY;
--skipping to line 931
elsif OP.OP = OP_FMULT or OP.OP = OP_LMULT then
MUL_TEMP := signed(A) * signed(R(6));
ALUR <= std_logic_vector(MUL_TEMP(31 downto 16));
MULR <= std_logic_vector(MUL_TEMP(15 downto 0));
ALUCY <= MUL_TEMP(15);
--skipping to line 967
end if;
end process; SD2SNES source code snippetsThe behavior is correct on the SD2SNES and the LMULT test passes as well, so it's relevant to show SD2SNES source code. The GSU source code is in verilog instead of vhdl but they are both HDL so probably more simple to compare than software source code. https://github.com/mrehkopf/sd2snes/blob/develop/verilog/sd2snes_gsu/gsu.v// line 2214
// MULTIPLY
`OP_FMULT_LMULT : begin
exe_fmult_srca_r <= exe_src_r;
exe_fmult_srcb_r <= exe_r6_r;
e2c_waitcnt_val_r <= 1;
e2c_waitcnt_r <= lat_fmult_r;
end
// line 2325
`OP_FMULT_LMULT : begin
e2c_waitcnt_val_r <= 0;
exe_mult_delay_r <= 2;
EXE_STATE <= ST_EXE_MEMORY_WAIT;
end
// line 2499
case (exe_opcode_r)
`OP_FMULT_LMULT : begin
if (|exe_mult_delay_r) begin
exe_mult_delay_r <= exe_mult_delay_r - 1;
end
else begin
e2r_val_r <= 1;
e2r_data_r <= exe_fmult_out[31:16];
e2r_r4_r <= exe_fmult_out[15:0];
e2r_lmult_r <= exe_alt1_r;
e2r_z_r <= ~|exe_fmult_out[31:16];
e2r_s_r <= exe_fmult_out[31];
e2r_cy_r <= exe_fmult_out[15];
EXE_STATE <= ST_EXE_WAIT;
end
// line 2568
if (gsu_clock_en) e2r_lmult_r <= 0; bsnes source code snippetsbsnes does pass the LMULT test and does show normal enemy behavior in DOOM, therefore it's probably a useful reference for this specific game. It is also 100% compatible with all of the commercial SNES library and passes every one of the test roms out there. Finally, the SNES_MiSTer used bsnes as the primary reference so it's relevant to mention the source code here. https://github.com/bsnes-emu/bsnes/blob/master/bsnes/processor/gsu/instructions.cpp//$9f(alt0) fmult
//$9f(alt1) lmult
auto GSU::instructionFMULT_LMULT() -> void {
uint32 result = (int16)regs.sr() * (int16)regs.r[6];
if(regs.sfr.alt1) regs.r[4] = result;
regs.dr() = result >> 16;
regs.sfr.s = (regs.dr() & 0x8000);
regs.sfr.cy = (result & 0x8000);
regs.sfr.z = (regs.dr() == 0);
regs.reset();
step((regs.cfgr.ms0 ? 3 : 7) * (regs.clsr ? 1 : 2));
} |
Separated the LMULT test: |
Thank you! I'm updating the above comment a couple more times I think as I keep looking into it. |
be0cfc8 - LMULT now passes in this test rom, so that part is fixed, but this didn't fix the issue with DOOM-FX yet. I tested for regressions with PeterLemon's GSUTEST roms, there were none. Enemy behavior remains the same. @JMendou and @lhathcock can you confirm same behavior as before? Such a shame, I was hoping we had figured it out :P The following test roms are the only ones left that fail on the MiSTer but pass on original hardware and pass on bsnes. We are like 99.7% of the way there! :) mister-fail-bsnes-pass-oghw-pass.zip jonasquinn-test-romsblargg_2010-03-14timer_at_power_reset.smc
multidiv_testsdiv_behavior.smc
in DOOM-FX source code: rllines.a (reality engine lines module);line 70
ldy _RDMPYL Probably not related, but worth mentioning as maybe the targeting relies upon lines?
In DOOM-FX source code: snes.i (under cpu equates section); line 179
WRDIVL equ $4204
WRDIVH equ $4205
WRDIVB equ $4206
; line 193
_RDDIVL equ $4214
_RDDIVH equ $4215 These only seem to be used for scores (kills, etc...) and status (health, armor, etc...) though. snes_mul_div_timingdiv_timing.smc ladida-lolladida-lol.sfc |
Assuming the unstable build I grabbed here is the correct one, same behavior as before. |
I did a quick test with SNES_unstable_20211211_aab7.rbf which includes fcd808a. Ranged enemies are shooting as expected and reacting properly to getting shot, so it's an improvement. Test rom results: timer_at_power_reset.smc |
Oh that's exciting!! |
@JMendou Can you confirm resolution? Thanks! :) |
I just did a test with SNES_unstable_20211214_5a9e.rbf and seems to work on my end. Only tested the part from my video. |
I think this issue is now resolved and can probably be closed, right @JMendou ? |
Sorry for disappearing. |
Great work, guys! |
SNES Doom enemy behavior is broken in a number of ways that are significantly inaccurate to how it performs on original hardware as well as emulation through current bsnes.
These are only the most blatant examples that can be easily confirmed with a few minutes of comparison. It is possible that there are more subtle differences as well.
*Enemies with a ranged attack will almost never perform them, but rather simply march toward the player continuously emitting the grunt or roar sound they are meant to make when they are alerted upon seeing the player. They should be shooting constantly.
*Upon reaching close range with the player, enemies will now occasionally attack, though still far less frequently than is accurate.
*Enemies are meant to have injured/staggered animation frames upon being damaged by the player, as well as give sound indicating they are taking damage. Neither of these things occur.
*Taking damage is also supposed to momentarily pause / stagger the movement and actions of most enemy types. This also does not seem to be working most, if not all, of the time.
*Damage calculations to enemies may be functioning incorrectly, or the players attacks are possibly being ignored with significant frequency. This is most noticeable on higher health enemies, who often take exponentially more damage to bring down than is accurate.
Confirmed these issues are occurring in current 20210713 release. (U) and (J) versions were tested and exhibited the same problems.
The text was updated successfully, but these errors were encountered: