This patch will make the title screen show the percentage of exits obtained in the save files, rather than the absolute number. You just need to set the total amount of exits your hack has in the asm file. Included is a slightly modified GFX29 file containing the % sign.

Requested by Ondore's Lies.

P.S.: the patch can display up to 199%, so you can in theory have post-game levels that increase the number over 100%. You just need to set the number of exits in the patch as the exits required for the "main game".

v1.1: added option to display a decimal digit to show more accurate percentages. Note that values greater or equal than 100% won't display the decimal part (due to limited number of tiles per row in the file select tilemap).

Surprised this wasn't an existing thing, but it definitely has some usage and it worked fine so it's accepted. Rounding and decimal options all seemed to work well when I messed around, so there should be no issue with its calculation for larger hacks.

Ooh, I think I found a potential bug-- if you make it display a decimal and have roundup being set, it may be possible that the decimal point gets incremented, from 9 to 10, which could increment the integer part from 99 to 100. An easy fix for that is simply check if both if the integer part is 99, and the remainder is attempted to increment past 9, to simply display 99.9%.

I know about this, I didn't care to handle it since it can only happen for hacks with 1000+ exits, which is not even possible when using the normal event counter. Even if it was, the percentage can only be computed properly with up to 655 exits (since you do *100, which for higher values would be higher than $FFFF), so this "bug" will never happen.
Also, don't tell me how I should format my code.

Ooh, I think I found a potential bug-- if you make it display a decimal and have roundup being set, it may be possible that the decimal point gets incremented, from 9 to 10, which could increment the integer part from 99 to 100. An easy fix for that is simply check if both if the integer part is 99, and the remainder is attempted to increment past 9, to simply display 99.9%.

Code

else
pha ; Save percentage for later.
lda $4216 ;\ If remainder is 0, decimal digit is 0.
beq + ;/
sta $4202 ;\
lda.b #10 ;|
sta $4203 ;| DecimalUnit = Remainder * 10 / TotalExits.
jsr .sub ;|
lda $4214 ;/
if !RoundUp
ldy $4216 ;\ If the remainder is 0, don't round up.
beq + ;/
cmp.b #9 ;\
bne ++ ;|
pla ;| If we have to round up 9, increase the
inc ;| integer units by 1 and set decimal digit to 0.
pha ;|
lda #$00 ;|
bra + ;/
++ inc ; Otherwise, just increase the decimal unit by 1.
endif

Also, I would recommend indenting the if statement, so that the nested if statement is double-indented for anyone wanting to edit the patch for their hacks to understand it easier.

An easy way to deal with displaying percentages with decimals is by using fixed-point arithmetic. Where instead of dealing with x/100, you deal with x/1000. So instead of ExitsFound * 100 / TotalExits, you do ExitsFound * 1000 / TotalExits, and after the hexdec display, note this:

Code

FixedPointInteger -> Display
1s place -> 1/10s place
10s place -> 1s place
100s place -> 10s place
1000s place -> 100s place

And when rounding via that, will round upwards by 0.1% automatically.

Perhaps, I made my own percentage converter (CTRL+F “ConvertToPercentage”). This one rounds 1/2 up, and you can use the Y register to check for misleading displays.

Small update: added a check so 99 isn't rounded to 100 when using the RoundUp option, added support for values between 101% and 199% and changed mode 7 multiplication regs to normal regs since the results were wrong when having more than 127 exits.

Be careful that when you have more than 100 exits, and you have the round up setting, there is a potential that the game may misleadingly display 100% indicating you got all the exit despite you only got 99.99%. A way to avoid that is by checking after you divide by the number of exits, the modulo is usually in between 0 and the number of exits. During the rounding upwards, check if it went from 99 to 100, then simply display 99%.

## Follow Us On