Name: | Optimize Score Display |
Author: | Fernap |
Added: | |
Tool: | Asar |
Requires Free Space: | No |
Bug Fix: | No |
Featured: | No |
Description: | Did You Know? SMW is incredibly inefficient when it displays the player score in the status bar. In the worst case (playing as Luigi, both players with max score), it can take about a full 1/6 of the entire frame to do so, lowering the threshold for slowdown. Normally, the actual amount of processing time is roughly proportional to the sum of the digits in Mario's score when playing as Mario, and the to the sum of the digits in both players' scores when playing as Luigi. This patch optimizes the way the score is stored and displayed to make it roughly constant, slightly faster than even in the best case without. The screenshots below are on a stock lorom using the CPU meter patch, without fastrom enabled, and show, in order: best case, worst case as Mario, worst case as Luigi, and finally with the patch applied. The position of the star shows roughly how much time was spent processing for the frame; further down means more time spent processing. Note that this patch is intended mainly for those using the vanilla status bar. It's unneeded if the status bar has been nuked, and probably won't work if using a custom status bar. See the asm file for some further details. |
Tags: | lorom optimize sa-1 status bar |
Comments: | 6 (jump to comments) |
Download
1.69 KiB | 159 downloads
Comments (6)
-Lunar Magic 3.40
-Asar 1.91
-bsnes v115
-Mesen 2 (Build Date: Jul 29 2024, 12:59:04)
-SA-1 1.40
Modified the patch to change Asar syntax to use Asar 1.91 standard (in other words, it won't complain about deprecated features).
Optimization is never a bad thing. Note that score-based gimmicks won't work with this unless adapted to work with the new system.
; this was originally called as part of a 24-bit hex->dec conversion, now unneeded, so we use this area for a routin to add score ; call with X/Y in 8-bit mode; A in either, which will be preserved ; A should contain the 16-bit BCD value to add to the current player's score org $009012|!bank AddScore: ldx $0DB3|!addr ; offset into score (+3 for luigi) beq .XSet ldx #$03 .XSet php sed ;GHB's note, this set the processor flag's decimal flag, modifying the behavior of ADC/SBC. rep #$21 adc $0F34|!addr,x : sta $0F34|!addr,x sep #$20 bcc .Done lda $0F36|!addr,x : adc #$00 : sta $0F36|!addr,x bcc .Done lda #$99 sta $0F34|!addr,x : sta $0F35|!addr,x : sta $0F36|!addr,x .Done: plp rtl
Another time I saw this being used was Pokemon R/B/G/Y (GBC, not SNES), with how the game stores money (as learned from the ZZAZZ glitch). Reason why decimal mode is rarely used is because:
One of the biggest benefits of BCD is fast-and-easy-to-display numbers, especially with large numbers, without loops. According to the ASM tutorial, it isn't covered but mentions that ADC and SBC (often used with CLC/SEC) are affected by this. I'd assume it makes it skip "hexadecimal letter digits" -> $09 + $01 will result $10 instead of $0A, and same goes with $10 - $01 resulting in $09 instead of $0F. Same applies to the "tens" digit, and carry is set or clear if that digit goes greater 9 or less than 0 (assuming the A register is 8-bit).