Kodewerx

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

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: AR NDS If scope
PostPosted: Sat Apr 03, 2010 3:00 am 
Offline
Kommunist
Kommunist

Joined: Sat Apr 03, 2010 2:41 am
Posts: 4
Hi, I would like to understand how the if code work.
In c# the if statement is
if (condiction)
{
}//end if
In AR it should be:
9xxxxxxx yyyyyyyy
D0000000 00000000

But what happen if i do :
9xxxxxxx yyyyyyyy
9xxxxxxx yyyyyyyy
D0000000 00000000 <--does this line refer to the line above or to the first line?
D0000000 00000000

Thank you


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Sat Apr 03, 2010 11:10 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.
The Dx code types act almost equivalent to the } curly bracket; like popping from a stack.

Code:
9xxxxxxx yyyyyyyy ; First condition
9xxxxxxx yyyyyyyy ; Second condition
D0000000 00000000 ; End second condition
D0000000 00000000 ; End first condition


A shorter form of this example is:

Code:
9xxxxxxx yyyyyyyy ; First condition
9xxxxxxx yyyyyyyy ; Second condition
D2000000 00000000 ; End all conditions

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Mon Apr 05, 2010 8:42 am 
Offline
Kommunist
Kommunist

Joined: Sat Apr 03, 2010 2:41 am
Posts: 4
Ok, thank you, my next question is the following:
if I write this:
Code:
//IF button Pressed
94000130 000003F9
//Set Stored to current value
DA000000 0215A228
//Stored +1
D4000000 00000001
//If address = 1330 Then 0
9215A228 00001330
D5000000 00000000
D0000000 00000000
//If address = 18 Then 1330
9215A228 00000018
D5000000 00001330
D0000000 00000000
//SET VALUES
D7000000 0215A228
D7000000 022AD61E
//Close If and clear Stored
D2000000 00000000


Could you tell me why the set values is always executed, even if I don't press any button?
I tried removing the 2 if clause and without them it works ok.

The work around I found is the following, but I don't understand why the previous one doesn't work
Code:
//IF button Pressed
94000130 000003F9
//Set Stored to current value
DA000000 0215A228
//Stored +1
D4000000 00000001
//If address = 1330 Then 0
9215A228 00001330
D5000000 00000000
D0000000 00000000
//If address = 18 Then 1330
9215A228 00000018
D5000000 00001330
D0000000 00000000
//IF button Pressed     <-------------------------AGAIN-------
94000130 000003F9
//SET VALUES
D7000000 0215A228
D7000000 022AD61E
//Close If and clear Stored
D2000000 00000000


Thank you
p.s. if you are interested the code above is used to cicle the codes (first position) in "Avalon Code" (E)


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Mon Apr 05, 2010 8:31 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.
You might want to use the MASK bits for the activator, as specified here: viewtopic.php?f=11&t=98&p=7453#p7453

Next, you should verify the addresses you are writing to with the D7 code types:

Code:
D7000000 0215A228
D7000000 022AD61E


These write the data register to addresses 0x0215A228 and 0x022AD620. If you knew that, cool... read on.

Finally, the code logic seems ... awkward. Consider the pseudo code version:

Code:
if (data_reg == 0x1330) {
    data_reg = 0;
}
if (data_reg == 0x18) {
    data_reg = 0x1330;
}


If you were to press the button (set in your activator) for just a split-second, this code would do some really strange things:

  • Load the current 16-bit value from *0x0215A228 into the data register and increment the register
  • Both checks for 0x1330 and 0x18 fail
  • Store data register to addresses 0x0215A228 and 0x022AD620
  • Clear data and offset registers, end code
  • ...
  • On the next frame, the activator button is *still held* ... repeat!
  • ...
  • After 25 successive frames of holding the button, the 0x18 check passes! 0x1330 is stored to addresses 0x0215A228 and 0x022AD620
  • On the 26th frame, with the button still held, the 0x1330 check passes, and 0 is stored to addresses 0x0215A228 and 0x022AD620
  • At this point, we've come full circle, and the entire process repeats from the beginning.

Remember that the game runs at 30 or 60fps (depends on the game!) meaning all of this could potentially happen in under 1 second. It's not clear if that is the behavior you were intending, but that's what the code does.

As for your question, I don't actually have an answer for you. All I can suggest is that your latter code looks like the best way to do it, anyway. With one exception: the first activator is no longer necessary. Put the activator around just the write codes (D7) and you will be fine.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Wed Apr 07, 2010 11:21 pm 
Offline
Kommunist
Kommunist

Joined: Sat Apr 03, 2010 2:41 am
Posts: 4
Thank you,
I didn't understand why the code I wrote was called more the once.
The behaviour I was looking for is the following:

The address 0x0215A228 and 0x022AD620 is where the slot 1 "item" is stored.
The hex values from 0x0000 to 0x0018 indicate the various "item" of the game, item 0x1330 is the empty "item"
What I would like to do was look at the current value, add 1 save the value.
The reason why I put the if is that 0x0019 is an invalid item and to avoid it I restart from "item" 0x0000, adding an extra step to allow the empty "item".

The problem as you said is the way the "procedure" is called more than once every second.
Do you know how I could avoid this behaviour and wait for the bottun up event?

Is there and advantage in using the MASK bits for the activator?

Thank you


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Thu Apr 08, 2010 5:31 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.
The advantage to using the MASK bits in button activators is that it allows you to also press other buttons at the same time, since they will be masked out (ignored). This is really nice in many cases. I'll give you an example: The Metroid Prime: Hunters "Levitate" code allows you to fly by holding B. If I wanted to fly to the top of the map and snipe enemies, I would just have to hold B until I reached the top, and I wouldn't come down until I released B. Sounds perfect, right? Well, consider if the code was not masking out any other buttons... What happens if I shoot (L or R buttons) while I'm holding B at the top of the map? Well, the activator fails when you press L or R! And then you start to fall. This is because B [~0x0002] != B + R [~0x0102] != B + L [~0x0202] != B + R + L [~0x0302]

If you are checking the pad register for a simple equality, then your activator will fail under this kind of condition (pressing your activator button combination + any other button). The mask feature can effectively solve this problem. This is why I originally suggested the universal activators in that form.


To answer your other question, there has been some recent talk on a related subject: viewtopic.php?f=17&t=7240 Just read the whole thread.

How do you use a code like that? Well, here's the code:
Code:
Button-Down Activator Enabler
023FE074 012FFF11
E0000000 00000034
E9F00024 E9F02024
E05000B0 E1D212BC
E1800001 E05210B0
E04200B0 E1E00000
E0000001 E1C200B2
E12FFF1E 04000130
027FFF7C 00000000
023FE074 E3520003


Just place that into its own code on your AR. It will give you a new special 16-bit variable at address 0x027FFF7E. This variable records only button-down transitions.

To use it:
Code:
927FFF7E 0000xxxx

For xxxx:
0001: A
0002: B
0004: Select
0008: Start
0010: Right
0020: Left
0040: Up
0080: Down
0100: R
0200: L
0400: X
0800: Y
2000: Debug Button (not available on commercial NDS)
8000: NDS not folded


Now you have an activator that will only trigger once when a button is pressed. The first problem with this code is that you cannot reliably combine multiple buttons. Another problem with this code is that you can't just hold the button to continue firing the activator. (Like holding a key on your keyboard... it won't automagically do that.) I'll fix those problems if someone doesn't get to it before I do.

Anyway, this should solve your immediate problem. Just replace the original universal activator with this one, and remember to turn on the button-down activator enabler as above. Let me know how it works for you.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Sat Apr 10, 2010 12:26 am 
Offline
Kommunist
Kommunist

Joined: Sat Apr 03, 2010 2:41 am
Posts: 4
Thank you, it work great.
But how do you know that the game is not using the address 0x027FFF7E for something else?
Is there a way to find unused address?

Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Sat Apr 10, 2010 11:29 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.
Because I know that the address range 0x027FFF60 - 0x027FFF7F are reserved for the Nitro debugger!

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Sat Apr 10, 2010 9:24 pm 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
Why the 7?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Sun Apr 11, 2010 11: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.
Because even though the commercial NDS only has 4MB of main RAM, the Nitro debugger has 8MB. And while we're at it, the commercial DSi has 16MB of main system memory. So on DSi (in real DSi mode) you would have to change the pointers to 02FFFF7E, for example.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Sun Apr 11, 2010 3:08 pm 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
If it's reserved for nitro, then extending to 8 meg by using the debugger would effectively nullify your belief that the area is free, right?

And if the NEW DSs that no one cares about have 16 meg, then why not just use F the whole way and not worry about it ever again? :P

Edit: Ugh, why does this site still have no center tag but a heaping helping of bad smilies? Para, you're lazy.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Sun Apr 11, 2010 3:21 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.
It's not just "my believe" that those 32 bytes are unused, but a documented fact. The reason I use the address near the 8MB mark was for some level of future-proofing the code[s]. But this obviously wasn't enough. Using 02FFFF7E from the beginning would have been much more future-proofed.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject: Re: AR NDS If scope
PostPosted: Tue Apr 13, 2010 4:52 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.
Fla8246: Does the "Button-Down Activator Enabler" code work for you as I described?

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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