Speed-O-Meter [mdmwii]
#1
Speed-O-Meter [mdmwii]

Works everywhere.

This code will put your current vehicle speed in the milliseconds section of your timer.

NTSC-U
C27ED9F8 00000008
3F80809C 839CD110
839C0020 541A103A
7F9CD02E 839C0010
839C0010 839C0024
9381FFFC C1A1FFFC
FDA06A10 FDA0681C
D9A1FFF8 8381FFFC
60000000 00000000

PAL
C27F84F8 00000008
3F80809C 839C18F8
839C0020 541A103A
7F9CD02E 839C0010
839C0010 839C0024
9381FFFC C1A1FFFC
FDA06A10 FDA0681C
D9A1FFF8 8381FFFC
60000000 00000000

NTSC-J
C27F7B64 00000008
3F80809C 839C0958
839C0020 541A103A
7F9CD02E 839C0010
839C0010 839C0024
9381FFFC C1A1FFFC
FDA06A10 FDA0681C
D9A1FFF8 8381FFFC
60000000 00000000

NTSC-K
C27E68B8 00000008
3F80809B 839CFF38
839C0020 541A103A
7F9CD02E 839C0010
839C0010 839C0024
9381FFFC C1A1FFFC
FDA06A10 FDA0681C
D9A1FFF8 8381FFFC
60000000 00000000



Code creator: mdmwii
Code credits: JoshuaMK (millisecond display modifier that works everywhere), Vega (improvements to source), Chadderz (fixes to mdmwii's original pointer loads so the speedometer can work on any kart+character combination)



Source:
#START ASSEMBLY

#Address Ports
#807ED9F8 NTSC-U
#807F84F8 PAL
#807F7B64 NTSC-J
#807E68B8 NTSC-K

#Source Compilation Region
.set region, '' #Use E/P/J/K. Lowercase letters work too.

#Macros & Statements
.if (region == 'E' || region == 'e') # RMCE
.macro set_playerbase
lis r28, 0x809C
lwz r28, 0xFFFFD110 (r28)
.endm
.elseif (region == 'P' || region == 'p') # RMCP
.macro set_playerbase
lis r28, 0x809C
lwz r28, 0x18F8 (r28)
.endm
.elseif (region == 'J' || region == 'j') # RMCJ
.macro set_playerbase
lis r28, 0x809C
lwz r28, 0x0958 (r28)
.endm
.elseif (region == 'K' || region == 'k') # RMCK
.macro set_playerbase
lis r28, 0x809B
lwz r28, 0xFFFFFF38 (r28)
.endm
.else # Invalid Region
.err
.endif

#Register Notes
#r26 = safe
#r28 = safe

#Set Region-Specific Player-Base
set_playerbase

#Pointer Level Loading
lwz r28, 0x0020 (r28) #Load Word from 1st Level Pointer
slwi r26, r0, 2 #Shift the bits of r0 by 2 to the left, result in r11. This is the same as multiplying by 0x4. r0 is current player slot.
lwzx r28, r28, r26 #Load into 2nd Level Pointer
lwz r28, 0x0010 (r28) #Load into 3rd Level Pointer
lwz r28, 0x0010 (r28) #Load into 4th Level Pointer
lwz r28, 0x0024 (r28) #Load into 5th Level Pointer, r12 now contains the float (single precision) word for your Vehicle Speed

#Convert Vehicle Float Speed; account for negative speed, use standard rounding
stw r28, -0x4 (sp)
lfs f13, -0x4 (sp)
fabs f13, f13
fctiw f13, f13

#Replace Default Instruction (set r28's value for timer)
stfd f13, -0x8 (sp)
lwz r28, -0x4 (sp)

#END ASSEMBLY
Reply
#2
NTSC-U
C27E4C9C 0000000C
3DE0809C 81EFD110
81EF0020 1E600004
7DEF9A14 81EF0000
81EF0010 81EF0010
807FEE20 3D808168
3A600001 9A6C0163
3E608000 81EF0024
91F317C0 3D808000
C3EC17C0 FFE0FA10
FFE0F81C 38A017D0
7FE567AE 80AC17D0
90AC17E0 00000000
0453109C 3D808000
045310A0 80AC17E0



NTSC-J
C27EE618 0000000C
3DE0809C 81EF0958
81EF0020 1E600004
7DEF9A14 81EF0000
81EF0010 81EF0010
807F2678 3D808168
3A600001 9A6C0163
3E608000 81EF0024
91F317C0 3D808000
C3EC17C0 FFE0FA10
FFE0F81C 38A017D0
7FE567AE 80AC17D0
90AC17E0 00000000
04535564 3D808000
04535568 80AC17E0



NTSC-K

C27DD36C 0000000C
3DE0809B 81EFFF38
81EF0020 1E600004
7DEF9A14 81EF0000
81EF0010 81EF0010
807F1C58 3D808168
3A600001 9A6C0163
3E608000 81EF0024
91F317C0 3D808000
C3EC17C0 FFE0FA10
FFE0F81C 38A017D0
7FE567AE 80AC17D0
90AC17E0 00000000
04523C3C 3D808000
04523C40 80AC17E0



This code actually does work with karts, reverse speed works as well, mdmwii used the wrong offset for the last level of the pointer
Reply
#3
Improvements made to source to shorten length of code

Update 4/7/2020: Code has been revised with JoshuaMK's timer so it works everywhere now. Code reconfigured to do all float operations immediately after getting the final pointer loaded so the code can be just one ASM without having to use space in the exception vectors.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)