Custom Time Trial Rankings [WhatisLoaf]
#1
Custom Time Trial Rankings [WhatisLoaf]

Hey everyone, this code will allow you to create fully custom time trial rankings in the Mario Kart channel.
Since there is a lot of data to fill in I'm not going to post the code here as it changes heavily based on what you fill in.
Instead I've made a tool that generates these codes which you can find at tt-rec.com
I know this is kind of unorthodox but this is the only way to not make it a nightmare to use.
This is my first time making a code for mkw so feel free to give feedback on what can be improved.

I've ported to all regions but only tested PAL and NTSC-U, I suspect the other regions should be fine though.

The code includes Anarion's globe position changer and region changer. For the preprogrammed globe position I used Vega's extensive database of globe positions.
Vega's CRC bypass code is also used which means not having to deal with checksums.
Besides that there are 2 codes: A title changer (that is displayed above the rankings) and the code that fills in the entire top 10, below is the source code for both:

Custom Rankings Title:
Code:
#Address Ports
#NTSC-U = 805C12AC
#PAL = 805CDDCC
#NTSC-J = 805CD6A8
#NTSC-K = 805BBD8C

mflr r11

bl set_address

# the entire string is placed in and can vary in length
# it's important to include 0000 at the end to terminate the string
.long XXXXXXXX

set_address:
cmpwi r14, 0x1776 # message ID for continental rankings title
bne- function_end
mflr r3 # replace the address with our address
stw r3, 0x20(sp)
function_end:
or r3, r21, r21
mtlr r11

Custom Top 10:
The source code here only includes 1 entry as an example. Big thanks to Vega for providing a more easy to read version of the code and shortening it by a few lines.
Code:
#Time Entry Packet Symbol Map
#0x1 (halfword) Milliseconds
#0x4 (word) Minutes, Seconds, then Milliseconds
#0x8 thru 0x53 Entire Mii Data including its CRC16 checksum; 0x4C in size
#0x57 (byte) Controller; 0 - Wheel, 1 - Wiichuck, 2 - Classic, 3 - GCN; useful if you wanna display wheel icon
#0x60 (byte) Country Code, use 0xFF to disable flag or use a country code that normally doesn't have a flag
#0x61 (byte) State Code (location within country), editing this is useless for this code
#0x62 (halfword) Location Code (location within state, this was never implemented/finalized in mkwii); useless to edit

#Address Ports
#NTSC-U = 806414CC
#PAL = 8060BFAC
#NTSC-J = 8060B720
#NTSC-K = 805FA3CC

#Backup Global Variable Registers (r18 thru r31), 0x34 amount of space
stmw r18, -0x34 (sp) #No function calls in code, safe to do

#FYI: LR is already backed up in r0

#Set r4 as 0 (friend rankings) to skip WFC connect
li r4, 0 #Default instruction not needed as r4's value is now set

#Change Byte in memory back to 1 (Regionals); Friend Rankings won't show for some reason
li r12, 1
stw r12, 0x58 (r3)

#Set Amount of Entries (1 thru 10)
li r12, 1 #1 used just for compilation, !!!adjust this for how many time entries will be used in the code!!!
stw r12, 0x60 (r3) # set amount of times to show
mtctr r12

#Set r11 to points to where the first data needs to be written to
addi r11, r3, 0x0068

#Make Mii Data Table
bl read_data

.short 0xDDDD #Millisecond
.byte 0xEE #Minute
.byte 0xEE #Second

#Mii Data from 0x00 to 0x1b
.llong 0xFFFFFFFFFFFFFFFF
.llong 0xFFFFFFFFFFFFFFFF
.llong 0xFFFFFFFFFFFFFFFF
.long 0xFFFFFFFF
#Mii Data from 0x20 to 0x31
.llong 0xFFFFFFFFFFFFFFFF
.llong 0xFFFFFFFFFFFFFFFF
.long 0xFFFFFFFF
.short 0xFFFF

.byte 0xEE #Flag (Country code) Value, use 0xFF to disable flag
.byte 0xEE #Wheel/Not-Wheel Value; 0 = Wheel & 1 = No Wheel

#!!!For more than one entry, add in another set of the data from the template just above!!!

read_data:
mflr r12

#Loop, based on amount of entries
loop:

#Load all data from current time entry to r24 thru r31
lmw r18, 0 (r12)

#Store Time to proper spots in the Time Entry Packet
sth r18, 0x1 (r11)
stw r18, 0x4 (r11)

#Copy-paste first half of Mii Data to its spot in the Time Entry Packet
stmw r19, 0x8 (r11)

#Copy-paste second half of Mii Data to its spot in the Time Entry Packet
stmw r26, 0x28 (r11)

#Store Wheel Bit Value, Store Flag Byte value
stb r31, 0x57 (r11) #Wheel; 0 = Yes, 1 = No
sth r31, 0x60 (r11) #Flag; use 0xFF to disable flag

#Increment r12 & r11 for next Time Entry (if applicable)
addi r12, r12, 0x38
addi r11, r11, 0x68

#Decrement Loop
bdnz+ loop

#Restore LR, already backed up in r0 before code was executed
mtlr r0

#Restore Global Variable Registers (r18 thru r31)
lmw r18, -0x34 (sp)

Code created by: WhatisLoaf
Code credits: Anarion (globe position changer & region changer), Vega (globe position database, CRC Bypass Code)
Reply
#2
WOW I can't wait to try this out.
Reply
#3
Latest source in post #5

Here's a rewritten source where I was able to reduce the compiled code by 4 lines by removing the Mii Creator Name + CRC off the end of the Mii data, plus backing up necessary registers in the negative space of the stack frame, and using lmw+stwm to transfer most of the data. Because the Mii Data is altered, you need my Bypass Mii CRC code - https://mkwii.com/showthread.php?tid=1572 As long as the end user also runs that code, then you don't need the Java CRC-CCITT function on your website anymore.

This rewritten source has only been tested with 1 time entry, but it should work with any amount of time entries.

I included a small symbol map of the Time Entry packet if anybody wants to know on what goes where specifically for each entry.

This code is so awesome. Awesome work Loaf!

Code:
#Code creator: WhatIsLoaf

#Time Entry Packet Symbol Map
#0x1 (halfword) Milliseconds
#0x4 (word) Minutes, Seconds, then Milliseconds
#0x8 thru 0x53 Entire Mii Data including its CRC16 checksum; 0x4C in size
#0x57 (byte) Controller; 0 - Wheel, 1 - Wiichuck, 2 - Classic, 3 - GCN; useful if you wanna display wheel icon
#0x60 (byte) Country Code, use 0xFF to disable flag or use a country code that normally doesn't have a flag
#0x61 (byte) State Code (location within country), editing this is useless for this code
#0x62 (halfword) Location Code (location within state, this was never implemented/finalized in mkwii); useless to edit

#Address Ports
#NTSC-U = 806414CC
#PAL = 8060BFAC
#NTSC-J = 8060B720
#NTSC-K = 805FA3CC

#Backup Global Variable Registers (r18 thru r31), 0x38 amount of space for all the mii data that will be transferred
stmw r18, -0x38 (sp) #No function calls in code, safe to do

#FYI: LR is already backed up in r0

#Set r4 as 0 (friend rankings) to skip WFC connect
li r4, 0 #Default instruction not needed as r4's value is now set

#Change Byte in memory back to 1 (Regionals); Friend Rankings won't show for some reason
li r12, 1
stw r12, 0x58 (r3) # change to continental rankings (rankings don't show for some reason when it's a friend ranking)

#Set Amount of Entries (1 thru 10)
li r12, 1 #1 used just for compilation, !!!adjust this for how many time entries will be used in the code!!!
stw r12, 0x60 (r3) # set amount of times to show
mtctr r12

#Set r11 to point where the first data needs to be written to (start of Time Entry packet)
addi r11, r3, 0x0068

#Make Mii Data Table
bl read_data

#Note: Garbage values used so source can compile, fill in all values accordingly

.short 0xAAAA #Millisecond
.byte 0xBB #Minute
.byte 0xCC #Second

.llong 0xDDDDDDDDDDDDDDDD #Start of Mii Data
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDEEFF #End of Mii Data (does NOT include Creator Name or CRC), then Flag/Country Byte, then Wheel Byte

!!!FYI: For adding more time entries, simply follow the data template above, and append it accordingly!!!

read_data:
mflr r12

#Loop, based on amount of entries
loop:

#Store Time to proper spots in the Time Entry Packet
lwz r18, 0 (r12)
sth r18, 0x1 (r11)
stw r18, 0x4 (r11)

#Copy-paste Mii Data to its spot in the Time Entry Packet
lmw r18, 0x4 (r12)
stmw r18, 0x8 (r11) #This will cause the halfword of flag and wheel bytes to put into part of the mii data where the creator name goes, but it doesn't matter as long as you use the Bypass Mii Data CRC16 Check code.

#Load Flag+Wheel Halfword, store Wheel byte, store Flag byte
lhz r18, 0x3A (r12)
stb r18, 0x57 (r11) #Wheel; 0 = Yes, 1 = No
sth r18, 0x60 (r11) #Flag; use 0xFF to disable flag, State ID is overwritten but it doesn't matter as that data isn't shown for time rankings

#Increment r12 & r11 for next Time Entry (if applicable)
addi r12, r12, 0x3C
addi r11, r11, 0x68

#Decrement Loop
bdnz+ loop

#Restore LR, already backed up in r0 before code was executed
mtlr r0

#Restore Global Variable Registers (r18 thru r31)
lmw r18, -0x38 (sp)
Reply
#4
Thank you for rewriting the code, looks a lot better now and with the CRC bypass code things are a lot easier.
I've updated the original post with the new code.

In the end this saves 3 lines of code which may not seems that much for a code that's about 90 lines long but in the javascript
code for the site it did manage to save around 100 lines so pretty big deal.

I've also taken the liberty to add all countries from Atlas' Extended Regions mod so the tool is now compatible! (Suggestion from Diamond)
Reply
#5
You're welcome. But I just realized I goofed up on something really silly.

I load then store the time entry data (parts of it) on 3 separate occasions. I can simply just load all the data with one lmw instruction into r17 thru r31. Lol.

Here's the latest updated source with that fix. this should now be as optimized as possible.

Code:
#Code creator: WhatIsLoaf

#Time Entry Packet Symbol Map
#0x1 (halfword) Milliseconds
#0x4 (word) Minutes, Seconds, then Milliseconds
#0x8 thru 0x53 Entire Mii Data including its CRC16 checksum; 0x4C in size
#0x57 (byte) Controller; 0 - Wheel, 1 - Wiichuck, 2 - Classic, 3 - GCN; useful if you wanna display wheel icon
#0x60 (byte) Country Code, use 0xFF to disable flag or use a country code that normally doesn't have a flag
#0x61 (byte) State Code (location within country), editing this is useless for this code
#0x62 (halfword) Location Code (location within state, this was never implemented/finalized in mkwii); useless to edit

#Address Ports
#NTSC-U = 806414CC
#PAL = 8060BFAC
#NTSC-J = 8060B720
#NTSC-K = 805FA3CC

#Backup Global Variable Registers (r18 thru r31), 0x3C amount of space for all the data of each time entry
stmw r17, -0x3C (sp) #No function calls in code, safe to do

#FYI: LR is already backed up in r0

#Set r4 as 0 (friend rankings) to skip WFC connect
li r4, 0 #Default instruction not needed as r4's value is now set

#Change Byte in memory back to 1 (Regionals); Friend Rankings won't show for some reason
li r12, 1
stw r12, 0x58 (r3) # change to continental rankings (rankings don't show for some reason when it's a friend ranking)

#Set Amount of Entries (1 thru 10)
li r12, 1 #1 used just for compilation, !!!adjust this for how many time entries will be used in the code!!!
stw r12, 0x60 (r3) # set amount of times to show
mtctr r12

#Set r11 to point where the first data needs to be written to (start of Time Entry packet)
addi r11, r3, 0x0068

#Make Mii Data Table
bl read_data

#Note: Garbage values used so source can compile, fill in all values accordingly

.short 0xAAAA #Millisecond
.byte 0xBB #Minute
.byte 0xCC #Second

.llong 0xDDDDDDDDDDDDDDDD #Start of Mii Data
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDDDDD
.llong 0xDDDDDDDDDDDDEEFF #End of Mii Data (does NOT include Creator Name or CRC), then Flag/Country Byte, then Wheel Byte

#!!!FYI: For adding more time entries, simply follow the data template above, and append it accordingly!!!

read_data:
mflr r12

#Loop, based on amount of entries
loop:

#Load all data from current time entry to r17 thru r31
lmw r17, 0 (r12)

#Store Time to proper spots in the Time Entry Packet
sth r17, 0x1 (r11)
stw r17, 0x4 (r11)

#Copy-paste Mii Data to its spot in the Time Entry Packet
stmw r18, 0x8 (r11) #This will cause the halfword of flag and wheel bytes to put into part of the mii data where the creator name goes, but it doesn't matter as long as you use the Bypass Mii Data CRC16 Check code.

#Store Wheel byte, store Flag byte
stb r31, 0x57 (r11) #Wheel; 0 = Yes, 1 = No
sth r31, 0x60 (r11) #Flag; use 0xFF to disable flag, State ID is overwritten but it doesn't matter as that data isn't shown for time rankings

#Increment r12 & r11 for next Time Entry (if applicable)
addi r12, r12, 0x3C
addi r11, r11, 0x68

#Decrement Loop
bdnz+ loop

#Restore LR, already backed up in r0 before code was executed
mtlr r0

#Restore Global Variable Registers (r17 thru r31)
lmw r17, -0x3C (sp)
Reply
#6
Alright, updated the original post and the site.
In total with all these changes the code is now 5 lines shorter! Big Grin
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)