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


Messages In This Thread
Speed-O-Meter [mdmwii] - by Vega - 12-16-2018, 04:50 PM
RE: Rounded Speed-O-Meter - by SwareJonge - 12-17-2018, 04:30 PM
RE: Speed-O-Meter; Vehicle Based - by Vega - 01-26-2019, 03:23 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)