#inject @ 0x8025bb44
#r0 = stage ID
cmpwi r0, 0x2
blt FINISHED
cmpwi r0, 0x15
beq FINISHED
cmpwi r0, 0x1A
beq FINISHED
cmpwi r0, 0x20
bgt FINISHED #if the stage is not on the SSS, skip to the end
mr r6, r0
mr r7, r3 #save needed information that would be overwritten by RNG function
li r3, 0x9 #number of options for RNG
lis r0, 0x8038
ori r0, r0, 0x0580 #load RNG function address
mtctr r0
bctrl #bl to RNG function, r3 is now a random int (0-8)
addi r5, r6, -0x2 #used later
cmpwi r3, 0x8
bne ALTSTAGE
#use original stage
lis r3, 0x8000
ori r3, r3, 0x35DE #load table offset
mulli r4, r5, 0x2
add r3, r3, r4 #add 2 * (stage ID - 2) to get offset of stage name
lhz r3, 0x0 (r3) #load stage name
b STORENAME
ALTSTAGE:
mulli r4, r5, 0x8 #get lowest alt ID
add r3, r4, r3 #add a random number between 0 and 7
cmpwi r3, 0xBB #Big Blue >_<
blt ASCII
addi r3, r3, 0x1
ASCII:
#r3 = ones digit
li r4, 0x0 #tens digit
ASCIILOOP:
cmpwi r3, 0x10
blt CONVERT #if the ones digit is less than ten, break out of the loop
addi r3, r3, -0x10 #subtract ten from the ones digit
addi r4, r4, 0x1 #add one to the tens digit
b ASCIILOOP #loop
CONVERT: #convert the digits to ASCII
cmpwi r3, 0xA
blt LESS1 #if the ones digit is less than 0xA, add 0x30, else add 0x37
addi r3, r3, 0x37
b TENS
LESS1:
addi r3, r3, 0x30
TENS: #if the tens digit is less than 0xA, add 0x30, else add 0x37
cmpwi r4, 0xA
blt LESS10
addi r4, r4, 0x37
b ASCIICOMPLETE
LESS10:
addi r4, r4, 0x30
ASCIICOMPLETE:
mulli r4, r4, 0x100 #multiply 0x10's by 0x100 to shift it over two columns
add r3, r3, r4 #add 0x10's to 0x1's
STORENAME:
lis r4, 0x8000
addi r4, r4, 0x361C #load table offset
mulli r5, r5, 0x4
add r5, r5, r4
lwz r5, 0x0 (r5) #get RAM address of name from table
sth r3, 0x0 (r5) #store name
mr r0, r6 #original r0 value (stage ID)
mr r3, r7 #original r3 value
FINISHED:
sth r0, 0x001E (r3) #store stage ID (original code line)