[SOLVED] Multiple HUD Item Updates in one call?

chronosv2

New member
This issue has been solved. Solution: http://nesmakers.com/viewtopic.php?f=3&t=767

Ugh. I hate having to ask this. My plan was to learn ASM and figure this stuff out on my own.
Buuuut as some of you may have seen on Facebook, I kinda' broke it.

Okay, so I know what I did here. I was messing with the update code and accidentally took out the part that limits how far the HUD updates will go, and then it overwrote the attribute table.

So what I'm trying to do is this:
I'm working on a piece of ASM code that everyone will be able to use to have HUD objects that consists of multiple HUD items. Say, for example, a max health of 16 that can show as Var Tiles rather than numbers.
So I went on about coding it, and I've got the arithmetic part of the code finished, which is the easy part because it doesn't require much direct talking with the NES hardware bits. The problem I'm having is that, after looking at the Health Update Code, I'm not sure how to update two components, preferably in one pass. You can't double up the update code because there are values that get modified along the way and that makes only one element or the other update. But rather than ask for a direct solution I'd just like to know how the HUD updates work, and if there's a way to trigger part of the HUD to update two elements at once.

Code:
	LDA myHealth
	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
		LDA DrawHudBytes
		ORA #HUD_myHealth
		STA DrawHudBytes

	LDA myHealthHi
	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
		LDA DrawHudBytes
		ORA #HUD_myHealthHi
		STA DrawHudBytes

The above code, interestingly, draws the value for the myHealthHi element over where myHealth should be.
I'm not sure what I should be doing to change this. I know part of what the problem is and why it doesn't work -- the myHealthHi update is overwriting most of the data stored for myHealth. So it seems like I need to hold the second update for a second HUD update, or I need to somehow combine the data from both updates into one. I'm not quite sure which of those is possible. Hmmm...
 

chronosv2

New member
I've made a discovery. Thanks to a tip from Joe on using FCEUX's debugger, I've started to dissect the HUD Update code and I'm a little closer to where I need to be.
Note that my "Expected" values are one tap of the "Hurt player debug button," which brings player HP to 15 (myHealth 8, myHealthHi 7).
Code:
	LDA myHealth
	STA hudElementTilesToLoad
	STA $07FF					;ACC reads 08 (Expected, but why?)
	LDA #$00
	STA hudElementTilesMax		;Not sure of this just yet.
	STA $07FF					;ACC reads 00 (Expected)
	LDA DrawHudBytes			;The bytes representing HUD elements we need to update (Currently #$00 (Bin 00000000)
	STA $07FF					;ACC reads 00 (Expected)
	ORA #HUD_myHealth			;myHealth is Element 3, so set bit 3 (00100000)
	STA DrawHudBytes			;Save our change.
	STA $07FF					;ACC reads 20 (00100000) Expected

;Commenting the code below makes the first HUD item draw as expected but not the second. Something for updating two objects needs to be changed in this block.
	;LDA myHealthHi
	;STA hudElementTilesToLoad	;Why are we saving our number to hudElementTilesToLoad?
	;STA $07FF					;ACC reads 
	;LDA #$00					;Drawing breaks if you set this too high, because you've just set the hudElementsTilesMax variable past whatever its coded to stop at.
	;STA hudElementTilesMax
	;STA $07FF					;ACC reads 
;End "This is my target" block.
	LDA DrawHudBytes
	STA $07FF					;ACC reads 20 (00100000) Expected
	ORA #HUD_myHealthHi
	STA DrawHudBytes
	STA $07FF					;ACC reads 22 (00100010) Expected

So the code I need to figure out how to modify for a second HUD update is in here:
Code:
;Commenting the code below makes the first HUD item draw as expected but not the second. Something for updating two objects needs to be changed in this block.
	;LDA myHealthHi
	;STA hudElementTilesToLoad	;Why are we saving our number to hudElementTilesToLoad?
	;STA $07FF					;ACC reads 
	;LDA #$00					;Drawing breaks if you set this too high, because you've just set the hudElementsTilesMax variable past whatever its coded to stop at.
	;STA hudElementTilesMax
	;STA $07FF					;ACC reads 
;End "This is my target" block.
 

chronosv2

New member
I did. I posted a thread for my code over here:
http://nesmakers.com/viewtopic.php?f=3&t=767

Thanks for asking that -- reminded me that I needed to put the link to my solution at the top of the forum!

I'm going to make the warning that doing stuff with the HUD isn't the most stable thing in the world -- I don't think my solution will cause a crash, but there are a few cases that cause graphical glitches like being able to see the bar being redrawn frame-by-frame if an update happens during an update.
 
Top Bottom