Language…
5 users online: Alex No, Cape, Doopu, Odyssey K., X11Gbyte - Guests: 869 - Bots: 112
Users: 70,469 (2,469 active)
Latest user: zimu26

Optimize Score Display

SMW Patches → Optimize Score Display

Submission Details

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

Screenshots

Comments (6)

Rrose80149 Link
Is there a way to change the 7 Koopa Shell hit sounds to the spin jump stomp sound every time you jump and hit an enemy?
 Fernap Author Link
I think you've maybe posted this in the wrong spot. This is a patch that optimizes the code that draws the score display. You might want to check out the general hacking help thread here: https://www.smwcentral.net/?p=viewforum&f=5
 RussianMan Link
Tested With:
-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.
HammerBrother Link
Interesting, you are using decimal mode (or binary-coded decimal (packed)), kinda like this that adds more digits to the score:
Code
; 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:
  • The digits does not directly represent the raw value, e.g. 10 in hex is NOT 10 in decimal, when represented as a number line with consecutive representable values highlighted, you'll have "gaps" where numbers with nybbles greater than 9 excluded, and hardware and most codes accepts raw values and not BCD (not sure if the SNES multiplication/division registers support BCD).
  • They take up more bytes for more digits than raw binary number. For 1-byte and using raw binary, you can represent values from 0-255 unsigned, but in packed BCD, 0-99 can be shown. This deviation grows fast with with more digits. In 16-bit, 0-65535 can be shown in raw, in packed BCD, 0-9999


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).
 Daizo Dee Von Link
What have you done? You took away God Luigi's GREATEST power! #smrpg{gasp}
 Fernap Author Link
#w{=P}