Shorten up this code?

Started by Bully@Wiiplaza, June 16, 2011, 07:11:27 PM

Previous topic - Next topic

Bully@Wiiplaza

What´s the best way to shorten this up? :confused:

Give All Items [Bully@Wiiplaza]
C2143860 0000001B
2C1D0000 4082000C
380001AA B0030002
2C1D0001 4082000C
38000132 B0030002
2C1D0002 4082000C
380001B5 B0030002
2C1D0003 4082000C
38000145 B0030002
2C1D0004 4082000C
38000131 B0030002
2C1D0005 4082000C
3800013C B0030002
2C1D0006 4082000C
38000133 B0030002
2C1D0007 4082000C
38000134 B0030002
2C1D0008 4082000C
38000138 B0030002
2C1D0009 4082000C
3800018A B0030002
2C1D000A 4082000C
38000135 B0030002
2C1D000B 4082000C
3800012D B0030002
2C1D000C 4082000C
380001A4 B0030002
A8030002 00000000
[spoiler]
cmpwi r29, 0x0
bne- _END1
li r0, 0x01AA
sth r0,2(r3)
_END1:
cmpwi r29, 0x1
bne _END2
li r0, 0x0132
sth r0,2(r3)
_END2:
cmpwi r29, 0x2
bne _END3
li r0, 0x01B5
sth r0,2(r3)
_END3:
cmpwi r29, 0x3
bne _END4
li r0, 0x0145
sth r0,2(r3)
_END4:
cmpwi r29, 0x4
bne _END5
li r0, 0x0131
sth r0,2(r3)
_END5:
cmpwi r29, 0x5
bne _END6
li r0, 0x013C
sth r0,2(r3)
_END6:
cmpwi r29, 0x6
bne _END7
li r0, 0x0133
sth r0,2(r3)
_END7:
cmpwi r29, 0x7
bne _END8
li r0, 0x0134
sth r0,2(r3)
_END8:
cmpwi r29, 0x8
bne _END9
li r0, 0x0138
sth r0,2(r3)
_END9:
cmpwi r29, 0x9
bne _END10
li r0, 0x018A
sth r0,2(r3)
_END10:
cmpwi r29, 0xA
bne _END11
li r0, 0x0135
sth r0,2(r3)
_END11:
cmpwi r29, 0xB
bne _END12
li r0, 0x012D
sth r0,2(r3)
_END12:
cmpwi r29, 0xC
bne _END13
li r0, 0x01A4
sth r0,2(r3)
_END13:
lha   r0,2(r3)[/spoiler]
My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully

Deathwolf

I don't think this would be possible because you need every cmpwi and branch instruction : /
lolz

Y.S.

How about this?

C2143860 00000008
A8030002 281D000C
41810034 48000021
01AA0132 01B50145
0131013C 01330134
0138018A 0135012D
01A40000 7D8802A6
57A0083C 7C0C02AE
B0030002 00000000

[spoiler]lha   r0,2(r3)
cmplwi  r29,0xC
bgt- _return

bl 0f

.short 0x01AA
.short 0x0132
.short 0x01B5
.short 0x0145
.short 0x0131
.short 0x013C
.short 0x0133
.short 0x0134
.short 0x0138
.short 0x018A
.short 0x0135
.short 0x012D
.short 0x01A4
.align 2

0:

mflr r12
rlwinm r0,r29,1,0,30
lhax r0,r12,r0
sth   r0,2(r3)

_return:[/spoiler]

dcx2

#3
Nice job using a Look Up Table (LUT) to simplify this.  There's a discussion about LUTs in the Collective.

I can do you one better, though.  Notice the high byte of each half-word is 01.  They only differ by low byte.  So this can be compressed even more, and we can get rid of the rlwinm too.

If you can ensure that r29 will never be any value greater than 0xC, you can remove the cmplwi, bgt-, and the first lha too.

[spoiler=r29 can be greater than 0xC]lha   r0,2(r3)
cmplwi  r29,0xC
bgt- _return

bl 0f

.byte 0xAA,0x32,0xB5,0x45
.byte 0x31,0x3C,0x33,0x34
.byte 0x38,0x8A,0x35,0x2D
.byte 0xA4
.align 2

0:

mflr r12
lbzx r0,r12,r29
ori r0,r0,0x100
sth r0,2(r3)

_return:[/spoiler]

[spoiler=r29 can NOT be greater than 0xC]
bl 0f

.byte 0xAA,0x32,0xB5,0x45
.byte 0x31,0x3C,0x33,0x34
.byte 0x38,0x8A,0x35,0x2D
.byte 0xA4
.align 2

0:

mflr r12
lbzx r0,r12,r29
ori r0,r0,0x100
sth r0,2(r3)

[/spoiler]

EDIT:

Whoops!  lhax should be lbzx.

Bully@Wiiplaza

#4
Thx Y.S. and dcx2 O0

... if I haven´t provided enough information, I´ll do that now.

The inventory assembly lha   r0,2(r3) cycles between about 14 different item adresses (r29 shows which one from 00 until 0D).
The last 2 of them have the same value, so I didn´t like to write to it twice because it wouldn´t have an effect.
So I wanted to write the corresponding item value to each slot from 00 until 0C, even though there is still an "additional" slot.

since the value can be greater than 0x0C:
[spoiler]bl 0f

.byte 0xAA,0x32,0xB5,0x45
.byte 0x31,0x3C,0x33,0x34
.byte 0x38,0x8A,0x35,0x2D
.byte 0xA4
.align 2

0:

mflr r12
lbzx r0,r12,r29
ori r0,r0,0x100
sth r0,2(r3)[/spoiler]
code
[spoiler]
C2143860 00000005
48000015 AA32B545
313C3334 388A352D
A4000000 7D8802A6
7C0CE8AE 60000100
B0030002 00000000[/spoiler]
That´s a great coding improvement, cool I´ll post this one up! :)

I possibly could cmpwi once and use multiple offsets and stw´s to write to the other slots, but that would increase the lengh by a lot again.
My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully

dcx2

You chose the wrong one if it can be greater than 0x0C.  If it goes up to 0x0D, you need to add the last element to the LUT.

bl 0f

.byte 0xAA,0x32,0xB5,0x45
.byte 0x31,0x3C,0x33,0x34
.byte 0x38,0x8A,0x35,0x2D
.byte 0xA4,0xA4
.align 2

0:

mflr r12
lbzx r0,r12,r29
ori r0,r0,0x100
sth r0,2(r3)

Bully@Wiiplaza

#6
Moonjump P1 *All Sports* [Bully@Wiiplaza]
284CDDA2 DBFF2400
48000000 80A6E0C0
DE000000 80008180
58010000 00000090
DE000000 80008180
92210001 0000009C
86900001 3C23D70A
94210001 0000009C
E0000000 80008000
284CDDA2 BBFF4400
48000000 80A6E0C0
DE000000 80008180
58010000 00000090
DE000000 80008180
92210002 0000009C
86900002 BC23D70A
94210002 0000009C
E0000000 80008000
284CDDA2 BBFF4400
040E4268 60000000
E2100000 00000000
040E4268 F0240098
E0000000 80008000
I´ve the feeling that this one can be shortened by a lot...
It´s for Mario Sports Mix [RMKP01] btw.
Pointer in Pointer :P
My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully