Welcome! Log In Create A New Profile

Advanced

Access to Registers

Posted by dancinninja 
Access to Registers
November 24, 2009 05:44AM
Hey all, I've been having trouble profiling my code on the Wii, so I looked around for some sort of hardware timer that I could use. I found the Starlet Timer which could prove useful. However, I am at a loss. How am I supposed to access the value stored in a specific register, such as HW_TIMER?

Thanks.
Re: Access to Registers
November 24, 2009 06:07AM
have you tried insight? it can debug and show memory and registers. you need a USB gecko or to use the wifi patch for libogc to allow it to connect to your wii while the app is running. eclipse can also debug using the same methods, but idk if it lets you access registers and whatnot.

also if you have a USB gecko, you can load the geckoOS code handler into memory and then start your dol. and you can debug with wiird. it has a built in disassembler. it lets you mess with the registers and nop stuff and addi and all that good stuff.
Re: Access to Registers
November 24, 2009 08:09PM
I have tried insight, but seeing as how my computer is an AMD processor, and I can't seem to get Dolphin to run, I am unable to run any code without a Wii.

I do not have a USB gecko, and (I am a bit ashamed to admit this) I do not know how to patch libogc with the wifi patch. I got the patch, and was bewildered beyond belief as to how I could use it.

All I really wanted was just the ability to use the built-in timer... I just wanted to see if one piece of code was faster than another.
Re: Access to Registers
November 24, 2009 10:01PM
Quote
dancinninja
I have tried insight, but seeing as how my computer is an AMD processor, and I can't seem to get Dolphin to run, I am unable to run any code without a Wii.

I do not have a USB gecko, and (I am a bit ashamed to admit this) I do not know how to patch libogc with the wifi patch. I got the patch, and was bewildered beyond belief as to how I could use it.

All I really wanted was just the ability to use the built-in timer... I just wanted to see if one piece of code was faster than another.
2 points, i can run dolphin on a amd sempron 1.8ghz, should be no problem for you (if you follow the super secret guide on the forums)

also, the wifi patch seems to not always work for some reason idk if anyone knows why but it just doesnt always work
Re: Access to Registers
November 24, 2009 10:48PM
Isn't this enough?

Hope it helps, ignore me if it doesn't.
Aruskano
Re: Access to Registers
November 25, 2009 05:58AM
For some reason, Dolphin keeps giving me the error about 1GB of memory. I've checked it out on their forum, and I haven't been able to find a solution (disabling virus/etc. software still doesn't work, grr!). Maybe it's because I only have 1GB of memory total? Not sure.

As for the Wifi patch, I don't even know how to ATTEMPT it. How do you patch something like libogc?

Aruskano, thanks for the link. I have been reluctant to use a straight "time" function, as that can lead to misleading results, particularly if a program is running at the same time. This brings up the question, however: does homebrew have 100% of the Wii's "attention"? Like, if one were running the program on Windows, it's also running a bunch of stuff in the background, which makes straight "time" measurements inconsistent and unreliable. However, if the homebrew had the full capacity of the Wii (I believe this is called running it in Kernel mode?) then it wouldn't be running anything else and hence, would make the time function a good indicator (at least, a better indicator).

Thoughts?
Re: Access to Registers
November 25, 2009 11:12AM
Quote

This brings up the question, however: does homebrew have 100% of the Wii's "attention"? Like, if one were running the program on Windows, it's also running a bunch of stuff in the background, which makes straight "time" measurements inconsistent and unreliable. However, if the homebrew had the full capacity of the Wii (I believe this is called running it in Kernel mode?) then it wouldn't be running anything else and hence, would make the time function a good indicator (at least, a better indicator).

The time() implementation directly access hardware timers so even if there was an OS (which is not the case, the Wii has 2 cpu and your application has full access on the one it's running on), that won't make time measurement unreliable, it' s perfectly safe to use them.
Re: Access to Registers
November 25, 2009 05:48PM
Awesome! Now all I have to do is figure out why (oh why?) the time function seems to return a nonsense result when I run it on the Wii. Nothing fancy, really:

int start;
int end;
//More declarations...

start = time(NULL); 
printf("\n\t Start: %d", start);

//More code...

end = time(NULL); 
printf("\n\t End: %d", end);

I've included time.h, what am I doing wrong here?
Re: Access to Registers
November 25, 2009 07:31PM
try this:

#include "gctypes.h"
external u64 gettime();

u64 start;
u64 end;
//More declarations...

start = gettime(); 
printf("\n\t Start: %llu", start);

//More code...

end = gettime(); 
printf("\n\t End: %llu", end);

"gettime()" return the number of ticks elapsed (directly from hardware timer I guess)
The function "ticks_to_millisecs()" function can convert this to a number of milliseconds.



Edited 3 time(s). Last edit at 11/25/2009 07:41PM by ekeeke.
Re: Access to Registers
November 28, 2009 02:18AM
Ekeeke! That's it! Awesome!

Yes, it is directly from the hardware timers. It's a count of how many clock ticks since the program began. Yeah, I dug deep, deep, DEEP into it and found the actual assembly code. Whew.

In any case, I can finally do my tests! So far I've done a few and it works marvelously. Thank you so much, all of you!
Sorry, only registered users may post in this forum.

Click here to login