HUD Updates 4.5.9

Moehr

New member
Poking around at the routine it looks like the one in bank 18 updates a single element at a time and I felt like sometimes this was making my HUD not update an element. There's situations where you might want to limit the amount of updates happening at once, but if not you can mess around with it a bit:

First you'll need to add the following constants and values in NESMaker project settings:
HUD_0=1
HUD_1=2
HUD_2=4
HUD_3=8
HUD_4=16
HUD_5=32
HUD_6=64
HUD_7=128

I edited the UpdateHudElements macro to add the following two elements:
Code:
MACRO UpdateHudElement arg0;, arg1
    ;;; arg 0, which element to update.
    ;;; what variable should we update?
 
    TYA
    PHA
    LDY arg0
    LDA ValToBitTable_inverse,y
    STA hudUpdates
    PLA
    TAY
 
    ENDM

    ;;;new macros here
MACRO HUDMultiUpdate arg0
    ;takes a constant as arg0, like #HUD_HEALTH -
    ;in NESMaker set it to one of the following to serve as a bitmask:
    ;1,2,4,8,16,32,64,128 - 1 is for HUD_ELEMENT_0, 128 is for HUD_ELEMENT_7
    LDA hudUpdates
    ORA arg0
    STA hudUpdates
 
    ENDM

MACRO HUDMultiUpdateDone arg0
    ;takes a constant as arg0, like #HUD_HEALTH
    LDA hudUpdates
    PHA
    LDA arg0
    EOR #%11111111
    STA hudUpdates
    PLA
    AND hudUpdates
    STA hudUpdates
 
    ENDM

Then I edited the Bank18 routine as follows:

Code:
doUpdateHudElement_bank18:
 
checkForHudUpdates:
 
    LDA hudUpdates
    BNE notNoHudUpdates
    RTS
notNoHudUpdates:
    LDA updateScreenData
    AND #%00000101 ;; if queued to push tiles or attributes
    BEQ +screenNotCurrentlyUpdating
    RTS
+screenNotCurrentlyUpdating
;;;modified code
        LDA hudUpdates
        AND #HUD_0
        BEQ +notHud0
            JSR updateHudElement0
            HUDMultiUpdateDone #HUD_0
    +notHud0:
        LDA hudUpdates
        AND #HUD_1
        BEQ +notHud1
            JSR updateHudElement1
            HUDMultiUpdateDone #HUD_1
    +notHud1:
        LDA hudUpdates
        AND #HUD_2
        BEQ +notHud2
            JSR updateHudElement2
            HUDMultiUpdateDone #HUD_2
    +notHud2:
        LDA hudUpdates
        AND #HUD_3
        BEQ +notHud3
            JSR updateHudElement3
            HUDMultiUpdateDone #HUD_3
    +notHud3:
        LDA hudUpdates
        AND #HUD_4
        BEQ +notHud4
            JSR updateHudElement4
            HUDMultiUpdateDone #HUD_4
    +notHud4:
        LDA hudUpdates
        AND #HUD_5
        BEQ +notHud5
            JSR updateHudElement5
            HUDMultiUpdateDone #HUD_5
    +notHud5:
        LDA hudUpdates
        AND #HUD_6
        BEQ +notHud6
            JSR updateHudElement6
            HUDMultiUpdateDone #HUD_6
    +notHud6:
        LDA hudUpdates
        AND #HUD_7
        BEQ +notHud7
            JSR updateHudElement7
            HUDMultiUpdateDone #HUD_7
    +notHud7:
    +doneHudUpdate:
    RTS

Since the old macro UpdateHudElement only allows for one update per frame, you'll want to replace that with the new HUDMultiUpdate anyplace you'd want to allow multiple updates on a single frame (for me that's all my pickups and health changes during gameplay).

Now when you have a HUD-facing variable change its value (for example, the one represented by HUD_2), you can use the macro HUDMultiUpdate #HUD_2 to flag updates to the HUD, and the HUD will be able to update all 8 variables at the same time if need be.

Edit - bug wasn't a screen load issue, but was math above in the HUDMultiUpdate Macro, which has been fixed. Basically I had been ANDing a value instead of inverting the constant and ANDing with that.

Note: I had health bars which actually take too much time to draw nice in a single update. If you have health or energy bars using multiple consecutive tiles, you'll need to add the following snippets at the end of the logic for that element:
Code:
            JMP +doneHudUpdate
Then the hud update routine won't totally clear out the hudUpdates variable; as a result it will fire again next frame to finish the job.
 
Last edited:
Top Bottom