ChildOfCv Posted September 30, 2021 Share Posted September 30, 2021 While disassembling some 6502 code, I ran across this loop. I'm pretty sure the X indirect write is wrong for all nonzero X, but wanted to make sure I wasn't just seeing things. What say you? STA $E0 LDX #0 copy_loop: LDA ($31),Y INY STA ($E1,X) INX DEC $E0 BNE copy_loop Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted September 30, 2021 Share Posted September 30, 2021 Do we know the value range of Y and $E0? In which ROM did you find this? The code might work if X would be increased by two. But as it is now I cannot see how it would make sense. Maybe more context would help. Quote Link to comment Share on other sites More sharing options...
ChildOfCv Posted September 30, 2021 Author Share Posted September 30, 2021 Y comes from a bytecode script stream. The top nibble (E0) is the copy command, followed by a word destination address and then the bytes to copy. When I stopped in the debugger, the count was 2 that time. The first byte went to the intended location (5C5), but the second was written to 405. The ROM in question is Mike Tyson's Punch-Out. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted September 30, 2021 Share Posted September 30, 2021 That's a NES game. You are in the Atari 2600 Programming forum. Quote Link to comment Share on other sites More sharing options...
ChildOfCv Posted September 30, 2021 Author Share Posted September 30, 2021 (edited) Yeah but it's a 6502 question and I figured there would be more Atari programmers here Also, there's no NES programming sub-forum either Edited September 30, 2021 by ChildOfCv Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted September 30, 2021 Share Posted September 30, 2021 (edited) The problem is that STA ($E1,X) looped pokes "somewhere" in the 64K range. And that "somewhere" makes no sense for an Atari 2600, since most of that area is ROM, not RAM. The NES hardware is unknown, at least to me. Maybe some of the addresses are e.g. hotspots on the NES which trigger additional stuff, maybe there is RAM, maybe ROM. Edited September 30, 2021 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted September 30, 2021 Share Posted September 30, 2021 I often analyze 2600 games using Stella's integrated debugger, such as here were I figured out why BattleZone was misbehaving with a video upscaler. As such I suggest running Punch Out in an NES emulator that likewise has an integrated debugger so you can see exactly what the code is doing. I'm not familiar with NES so don't know any of the emulators for it. I've seen many videos on @ckrtech's YouTube channel Displaced Gamers where he analyzes NES code while its running, so he may be able to recommend an emulator to use. Quote Link to comment Share on other sites More sharing options...
ChildOfCv Posted September 30, 2021 Author Share Posted September 30, 2021 I do need to find out what he's using since it seems to allow for some nice scripting. Well, I'm currently using FCEUX, which also seems to have scripting capabilities, but is a bit clunky. That emulator he uses looks nice. But I have definitely confirmed that it writes to odd locations when count>1. And NES RAM goes from 0-0x800 so no hot spots there. It's likely that they never use this to copy more than a byte or 2, since the game is almost glitch-free. The scripting handled by this function modifies the opponent's fighting strategy at specific times during the round. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.