#163785 - cualquiercosa327 - Sat Oct 11, 2008 2:58 pm
Hello , i would like ask some help with this asm.
It is the code was created to use the ds motion pack with mario kart and other games.
it patchs the game when you press select+start and let you use the cartidge for moving the game.But it doesnt work to me.
I have a TTDS card.I know other codes works for me,i tried the "demo" of mario ds with an ar code and it works,but the part select+start has to be deleted also.
here are the code:
push {r0-r7}
ldr r0,values
ldrh r1,data
ldr r2,values+4
ldrh r3,data+2
cmp r1,#0
ldreqh r4,[r0]
tsteq r4,#4
tsteq r4,#8
cmpeq r1,#0
moveq r1,#1
streq r1,data
cmp r1,#1
bne end
mov r4,#0x02000000
add r5,r4,r3,lsl #0x10
add r3,#0x1
strh r3,data+2
add r6,r4,r3,lsl #0x10
loop:
ldr r7,[r5],#4
cmp r7,r0
streq r4,[r5,#-4]
cmp r5,r6
blt loop
cmp r3,#0x40
moveq r3,#0
streq r3,data
streq r3,data+2
end:
pop {r0-r7}
bx r14
values:
.word 0x04000130
.word 0x02400000
data:
.word 0x00000000
i would like know what part is the select+start code,and delete or maybe change for "if i press L" as example.
I was trying to understand the code and i deleted this :
cmp r1,#0 //compara r1 con 0
ldreqh r4,[r0]
tsteq r4,#4
tsteq r4,#8
cmpeq r1,#0
moveq r1,#1
streq r1,data
cmp r1,#1
bne end
but i am unable to make it works :(
thanks
#163789 - Miked0801 - Sat Oct 11, 2008 6:01 pm
tsteq r4,#4
tsteq r4,#8
These two lines are what test for start+select. To check for L-Button instead, use:
tsteq r4,#0x20
with the rest of the code the same.
BTW, this assembler code is obviously hand-written and also is overly complex for what it has to do. It feels like someone showing off who has no business showing off.
#163792 - cualquiercosa327 - Sat Oct 11, 2008 9:05 pm
a lot of thanks
i am going to test it now
#163793 - cualquiercosa327 - Sat Oct 11, 2008 10:35 pm
i deleted this part ,and also tried to change the select+start code for L,but it also doesnt work.
I think it would be the error ,but it seem not.(in the example of asmtoar it was).I have trying several thing but i am new with asm code.
this is the other second part of the code
push {r0-r5}
mov r5,#0x04000000
ldr r5,[r5,#0x130]
ldrh r1,counter
add r1,r1,#1
strh r1,counter
mov r2,#0x0A000000
mov r3,#0x02000000
mov r4,#2
tst r1,#2
addne r4,#2
tst r1,#1
ldrneb r0,[r2]
ldreqb r1,[r2,r4]
beq end
tst r1,#2
bne Y
cmp r0,#0x71
biclt r5,#0x010
cmp r0,#0x8f
bicgt r5,#0x020
strh r5,counter+2
b end
Y:
ldrh r5,counter+2
cmp r0,#0x71
biclt r5,#0x040
cmp r0,#0x8f
bicgt r5,#0x080
strh r5,[r3]
end:
pop {r0-r5}
bx r14
counter:
.word 0x00000000
some idea why it doesnt work?? (or a easier way to write it),the idea is
reading the pad and the dsmotion pack(and/or other cartidge), and "join" them together.
a lot of thanks
I am trying a lot of tests,(i also tried use the wario ware cartidge before using this code as base and adapting to wario cartidge but also i was unable to make it working).
Now i have just bought a dsmotion pak and the original code also doesnt work :(
#163844 - Miked0801 - Mon Oct 13, 2008 6:36 pm
Honestly, without all the code in front of me and a lot of spare time (which I don't have at the moment), I'm not going to be able to do this for you. The previous example was reading bits from the input port. That was easy to figure out. Your new example is reading from all over the place, without comments, and that makes it a pain to figure out. I'll let others give it a shot if they wish. :)
#163859 - cualquiercosa327 - Mon Oct 13, 2008 9:48 pm
ok,thanks Miked0801.
I have comment the second code.It took me a lot of time,but now i am able to understand it,but i go on without having sucessfull with it.
I go on with it,but thanks
Dani
#163890 - Cearn - Tue Oct 14, 2008 3:41 pm
This, as far as I can tell, is what those two routines are doing:
Code: |
struct {
u16 isPatched; //!< Check to see if the patching's been done.
u16 block; //!< Block index in RAM (used for patch progress).
} ALIGN(4) gMotionPatch; // aka data
u16 counter[2]= { 0, 0 };
void sub_1(void)
{
if(gMotionPatch.isPatched==0)
{
// Select and Start are both down: start patching.
keys= REG_KEYINPUT;
if((~keys&KEY_START) && (~keys&KEY_SELECT))
{
gMotionPatch.isPatched= 1;
gMotionPatch.block= 0;
}
}
if(gMotionPatch.isPatched!=1)
return;
// If we're here, we're patching.
u32 *ptr= &MAINRAM32[gMotionPatch.block*0x4000];
gMotionPatch.block++;
// Find a reference to the REG_INPUT register in a section of
// RAM and redirect it to the start of MAINRAM.
for(i=0; i<0x4000; i++)
{
if(ptr[i] == (u32)®_KEYINPUT)
ptr[i]= (u32)MAINRAM;
}
// Err ...
if(gMotionPatch.block==0x40)
{
gMotionPatch.isPatched= 0;
gMotionPatch.block= 0;
}
}
void sub_2(void)
{
keys= REG_KEYINPUT;
counter[0]++;
if(counter[0] & 2)
r4= 4;
else
r4= 2;
if(counter[0] & 1)
{
r0= SRAM[0];
if(counter[1] & 2) // Y part
{
keys= counter[1];
if(r0 <= 0x70)
keys &= ~KEY_UP;
if(r0 >= 0x90)
keys &= ~KEY_DOWN;
MAINRAM16[0]= keys;
}
else // X part
{
if(r0 <= 0x70)
keys &= ~KEY_RIGHT;
if(r0 >= 0x90)
keys &= ~KEY_LEFT;
counter[1]= keys;
}
}
else
{
r1= SRAM[r4]; // no-op ???
}
}
|
What I've called sub_1 seems to do the patching, or at least part of it. If St+Se are down, it goes to a patching loop that searches out references to REG_KEYINPUT in RAM and replaces them with a link to the start of Main RAM. I think the idea is that the motion-control routine updates the values there and any routine that used REG_KEYINPUT will use those values instead. Note that the patch-loop runs in 0x10000-byte blocks, but it looks like only the first block is actually patched. If there is code in higher blocks, I think they will still use the regular keypad. Of course, any data at the start of Main RAM will be overridden. Let's hope it wasn't important.
The second routine is probably the motion-control routine itself. counter[0] is probably a frame counter, and every two frames data from the motion pack (via SRAM) is read. In the counter[1] conditional blocks, the direction-bits in the key-input is overridden by checking the motion values against a dead-zone (the 0x70-0x90 range, apparently).
At least, that's what the code is trying to do. The `r1= SRAM[r4]' (corresponding to the `ldreqb r1,[r2,r4]' in the middle somewhere) seems to be a no-op. I think some NE or EQ may have been wrong there.
#164273 - cualquiercosa327 - Sat Oct 25, 2008 10:44 am
Thanks cearn.Excuse me for answering so later,i had read the post but i have not answer.
Yesterday night i was reading and "undersanding" your code.
i have two question
1)what make r4 in void sub_2(void) ??
2)Where read (in your code and/or asm code ) the motion
thanks