Kodewerx

Our culture has advanced beyond all that you could possibly comprehend with one hundred percent of your brain.
It is currently Mon Jan 27, 2020 2:49 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Mon Mar 29, 2010 4:07 pm 
Offline
Kommunist
Kommunist

Joined: Mon Mar 29, 2010 3:55 pm
Posts: 3
I am trying to create a code that increment's the selected unit's Speed by 1.
Here is what I have: I'll try to comment each line as to what I was thinking.

Press SELECT for Speed + 1
721D503C FF000096 //If the selected unit's speed is less than 150 (cap is 149)
//I added 1C to the base address since if's don't seem to respect
//the offset
94000130 FFFB0000 //Press SELECT to activate
B21D5020 00000000 //Load the address data into the offset register
DB000000 0000001C //Load the data at base address + 1C into the stored register
//This should just store the current speed in the stored register
D4000000 00000001 //Add 1 to the value in the stored register
D7000000 0000001C //Write the updated value in the stored register back to the address
D2000000 00000000 //End everything, clear registers

This produces erroneous results, like the speed being incremented by 60-80+ (decimal).
If I change the bold line above to this:
D5000000 0000000F //Set the value in the stored register to F
I get the result 16 (dec), or F + 1, which is what should happen, so it looks like increment works.

If I remove the underlined line above (the increment step), speed doesn't change,
so it looks like it's just reading the value in, then putting it back, and that seems to work.

But apparently when I mix the two together everything goes crazy.

Please anyone give me some help here. I'm wracking my brain with this.


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 29, 2010 6:21 pm 
Offline
Komrade
Komrade
User avatar

Joined: Tue Mar 27, 2007 6:23 pm
Posts: 1354
Location: Mario Raceway, 1509.831, 217.198, -564.429
Title: Mario Kart 64 Hacker
Goes crazy? Is it incrementing once for every frame the select button is held (i.e. by about 60 per second)?

_________________
Image 143
HyperNova Software is now live (but may take a few tries to load) currently down; check out my PSP/DS/Game Boy/Windows/Linux homebrew, ROM hacks, and Gameshark codes!


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 29, 2010 6:32 pm 
Offline
Kommunist
Kommunist

Joined: Mon Mar 29, 2010 3:55 pm
Posts: 3
Now that you mention it, that might be the case.
How can I stop it from doing that?


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 29, 2010 7:23 pm 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3765
Title: All in a day's work.
Use one of the button state transition flags. (Whatever you want to call them.)

The universal activator will not work, because it records the exact button state. The game also keeps track of when a button changes state (meaning the flag is only set for a single frame; when the last state was on/off/different). It's hard to explain, but you'll know it if you see it. Sadly, the only way to find it is by digging in with a debugger.

*This really needs a better description.*

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 31, 2010 7:47 pm 
Offline
Komrade
Komrade
User avatar

Joined: Tue Mar 27, 2007 6:23 pm
Posts: 1354
Location: Mario Raceway, 1509.831, 217.198, -564.429
Title: Mario Kart 64 Hacker
Aside from the "buttons currently held" value (activator value), there will be somewhere in RAM a "buttons just pressed this frame" value. Use that.

_________________
Image 143
HyperNova Software is now live (but may take a few tries to load) currently down; check out my PSP/DS/Game Boy/Windows/Linux homebrew, ROM hacks, and Gameshark codes!


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 02, 2010 10:35 pm 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
It's not that hard to simulate those variables yourself if you can't find them. I've written code (which I've put on this site!) that does so. Probably less efficiently than I could have, though...

Of course, if you don't have good tools for finding what you need then what are you going to do?

_________________
Image


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 03, 2010 11:27 am 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3765
Title: All in a day's work.
Right, it's not hard to do. Typically you only need a few logical instructions: AND, XOR, and NOT.

I explained all of this in a very early post: viewtopic.php?f=6&t=834&p=14244#p14244 (This is probably one of the most useful things on this site to have been lost in the noise over the years.)

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 03, 2010 7:06 pm 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
Could that possibly be done faster? You're xor'ing the old with the new, creating a bit pattern of "0 for no transition, 1 for transition", and then and'ing with the keys that are pressed (as opposed to released) to remove transitions that are releasing the keys and leaving those that are being newly pressed.

But what about doing this?

Code:
keys = readIO();
keys_down = ~keys & last_keys;
last_keys = keys;

This returns true for each bit if and only if the previous frame the key was not pressed AND the key is pressed in the current frame. Isn't this the same result?

And this saves an instruction?

Or am I going crazy?

old ^ new = (old and ~new) or (~old and new)
((old and ~new) or (~old and new)) and ~new = (~new and old and ~new) or (~new and ~old and new)
(~new and old and ~new) reduces to ~new and old
(~new and ~old and new) is impossible, so it reduces to false
Anything or false is itself, so the whole thing reduces to "~new and old"

Assuming I got my boolean algebra correct.

_________________
Image


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 04, 2010 1:25 am 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3765
Title: All in a day's work.
Yes, you're correct. The EOR instruction is redundant and can be removed. Nice catch.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 04, 2010 7:01 pm 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
Oddly enough I caught it because I was confused. It had been a while since I needed to determine the logic for seeing which keys had been pressed starting on the current frame and I wanted to be sure I could do it efficiently in the future, so I stopped and came up with it on my own and compared it to yours. And of course I thought I had screwed something up when I got a different result...

Nice timing though. I actually need a hack I'm working on to ignore presses of the L button until they occur after having released it from the previous time the L button was being polled (for an N64 game, though).

But for some reason my code handler (embedded in the ROM and loaded by the thread switch code) crashes the emulator whenever it processes that code (using a code type I designed with the C0 code type from GeckoOS in mind, which calls the assembly after the C0 line in the cheat handler).

Speaking of which, you should check out my code type spec and comment on it. It's in the Jet Force Gemini thread in Konsole Hacking. I currently have a working ROM hack that runs in Mupen64++, allowing for online play, that lets more than one player play the campaign as a normal character.

_________________
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group