Pretty Speedometer [stebler]
#61
(11-21-2021, 05:26 PM)Vega Wrote: Which exact source is not compiling for you?

Every source for every region option compiles for me on old legacy PyiiASMH2. I only use the old version because I can't get the new version to run/compile on Debian 10. So I'm unable to test on PyiiASMH3.

Codewrite & ASMWiiRD won't compile the 5th source. It will reject it and say that 'string16' is an unknown pseudo-op. You can easily fix this though by just putting in the raw hex. Is that what you are attempting to do (hence why you get the alignment error)?

If so try this...

Replace .string16 "%.2f\0"

with...
.long 0x0025002e #16-bit ASCII for %.
.long 0x00320066 #16-bit ASCII for 2f
.long 0x00000000 #Alignment

This will compile the 16-bit ascii string and then have enough null bytes for the alignment

this one 
Code:
# inject at 807ed1d8 (PAL)
# inject at 807e392c (NTSC-U)
# inject at 807ec844 (NTSC-J)
# inject at 807db598 (NTSC-K)

.set region, 'E'

.if (region == 'P')
    .set swprintf, 0x80017814
    .set LayoutUIControl_setMessageAll, 0x8063ddb4
    .set RaceConfig_s_instance, 0x809bd728
    .set KartManager_s_instance, 0x809c18f8
.elseif (region == 'E')
    .set swprintf, 0x80016cb4
    .set LayoutUIControl_setMessageAll, 0x8060c994
    .set RaceConfig_s_instance, 0x809b8f68
    .set KartManager_s_instance, 0x809bd110
.elseif (region == 'J')
    .set swprintf, 0x80017738
    .set LayoutUIControl_setMessageAll, 0x8063d420
    .set RaceConfig_s_instance, 0x809bc788
    .set KartManager_s_instance, 0x809c0958
.elseif (region == 'K')
    .set swprintf, 0x8001787c
    .set LayoutUIControl_setMessageAll, 0x8062c0cc
    .set RaceConfig_s_instance, 0x809abd68
    .set KartManager_s_instance, 0x809aff38
.else
        .err
.endif

lbz r3, 0x81 (r30)
cmpwi r3, 0x0 # check if the control is custom
bne end # if not, we are done

# get the local player id
lbz r31, 0x190 (r30)

# get the player id
lis r3, RaceConfig_s_instance@ha
lwz r3, RaceConfig_s_instance@l (r3)
add r3, r3, r31
lbz r4, 0xb84 (r3)

# get the speed
lis r3, KartManager_s_instance@ha
lwz r3, KartManager_s_instance@l (r3)
lwz r3, 0x20 (r3)
slwi r4, r4, 2
lwzx r3, r3, r4
lwz r3, 0x0 (r3)
lwz r3, 0x28 (r3)
lfs f1, 0x20 (r3)

# format the string
addi r3, r1, 0x8
li r4, 0xd
bl format
.short 0x001a, 0x0800, 0x0001, 0x0030 # color
.string16 "%.2f\0"
format:
mflr r5
crset 4 * cr1 + eq
lis r12, swprintf@h
ori r12, r12, swprintf@l
mtctr r12
bctrl

addi r4, r1, 0x10

# change the color depending on the local player id and the team
addi r3, r31, 0x30
lis r5, RaceConfig_s_instance@ha
lwz r5, RaceConfig_s_instance@l (r5)
mulli r6, r31, 0xf0
add r5, r5, r6
lwz r5, 0xf4 (r5)
cmpwi r5, 0x2
beq no_team
addi r3, r5, 0x20
no_team:
sth r3, -0x2 (r4)

# replace digits, dashes and dots with the timer versions
loop:
lhz r3, 0x0 (r4)
cmpwi r3, 0x0
beq out

cmpwi r3, 0x2d
bne not_a_dash
li r3, 0x246d

not_a_dash:
cmpwi r3, 0x2e
bne not_a_dot
li r3, 0x246b

not_a_dot:
subi r5, r3, 0x30
cmplwi r5, 0x9
bgt not_a_digit
addi r3, r5, 0x2460

not_a_digit:
sth r3, 0x0 (r4)
addi r4, r4, 0x1
b loop

out:

# update the message
mr r3, r30
addi r4, r1, 0x8
li r5, 0x0

lis r12, LayoutUIControl_setMessageAll@h
ori r12, r12, LayoutUIControl_setMessageAll@l
mtctr r12
bctrl

end:
lwz r0, 0xe4 (r1) # original instruction
Reply
#62
Compiling that source as-is in CodeWrite should pop up a message about string16 being an unknown psuedo-op. I supplied a fix to that on my previous post. If you are getting an alignment issue, then somehow when you copy-pasted the source to CodeWrite, something got altered, or you modified something prior to compilation?

I can't speak for PyiiASMH3 as I can't get it to run on my personal Debian machine. But as mentioned already, apply that 'fix/patch' I provided. Then the source will compile on Codewrite.
Reply
#63
One possible issue is that changing the string format would break instruction alignment because it was manually padded with a null character at the end. I just replaced it with a .balign pseudo-op.
Reply
#64
what font does this code use? in coin.brlyt, it says the font is mario_font_number_red.brfnt, but that font contains no letters, and numbers that are not used in the code
Reply
#65
(11-22-2021, 07:55 PM)jawa Wrote: what font does this code use? in coin.brlyt, it says the font is mario_font_number_red.brfnt, but that font contains no letters, and numbers that are not used in the code

It uses kart_kanji_font.brfnt / kart_font_korea.brfnt (font id 1) which is set via BMG attributes in the second to last code.
Reply
#66
Does this cap the max string size at 8? cus if i try to change the text from "%.2f" to "VEHICLE SPEED: %.2f" the game only renders the first 8 characters
Reply
#67
(11-28-2021, 09:51 PM)jawa Wrote: Does this cap the max string size at 8? cus if i try to change the text from "%.2f" to "VEHICLE SPEED: %.2f" the game only renders the first 8 characters

In the 5th source which you are editing. You can see Stebler calls the swprintf function. It's similar to sprintf but uses 16-bit ASCII and the args are slightly different. https://www.cplusplus.com/reference/cwchar/swprintf/

Code:
lis r12, swprintf@h
ori r12, r12, swprintf@l
mtctr r12
bctrl

swprintf requires 3 'main' args
r3 = Where to output the completed C wide string (format strings are replaced with appropriate data)
r4 = Amount of wide characters (including the null halfword at end) of r3; simply put the length of r3 in halfwords
r5 = Where non-completed C wide string is at (contains format strings: i.e. %.2f)

Since r4 is the amount of wide characters of the output, you will need to do a tiny bit of work to figure out what the length of the completed C wide string will be. However, you don't need to do this, you can just set this to an amount that you know will exceed the length of completed string. So you can set r4 to something like 0x50, lol.

But another issue is that if you look at r3 in the source that's for the arg of swprintf. It's sp + 0x8. You would need to allocate more stack space. However since Stebler hooked the Assembly at an epilogue of a function, it appears you have some wiggle room.

0x8 thru 0xD7 in reference to sp appears to be free to use from just looking at the address in Code View. So that would be 0xD0 bytes of free space. As long as your output string (including the null halfword at end) isn't over 0x68 halfwords, you should be fine.

So you shouldn't need to do anything but edit r4 to cover the halfword size of r3.
Reply
#68
On top of what Vega said you will also need to change the maximum size in the brlyt (in bytes) in the 3rd source.
Reply
#69
Can I change the x position but only for splitscreen 4 players (and 3 players) ?
Reply
#70
(03-10-2022, 06:28 PM)pakrett Wrote: Can I change the x position but only for splitscreen 4 players (and 3 players) ?

Yes, by replacing c3a6 for P1 and P3 and 43ac for P2 and P4. All values are the 2 upper bytes of 32-bit floating point (you can convert with https://www.h-schmidt.net/FloatConverter/IEEE754.html) and are listed in the 4th asm source.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)