Language…
12 users online: Alyssa,  Blaagon, drkrdnk, Firstnamebutt, hhuxy, howardadam1126, Jamie,  Lazy, MiracleWater, Scags, Suru48, the_name_is_already_taken - Guests: 49 - Bots: 274
Users: 65,857 (2,177 active)
Latest user: King Paiden 64

Optimize Score Display

Waiting SMW Patches → Optimize Score Display

Submission Details

Name: Optimize Score Display
Author: Fernap
Submitted: by  Fernap
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 sa1 status bar
Comments: 3 (jump to comments)
Download 1.72 KiB | 54 downloads

Screenshots

View all

Comments (3)

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}