Debug by showing value in the HUD

theOldGameMaker

New member
Hi, since there is no console.log() for us I set up 2 user variables, debug1 and debug2. When I try to show them in the HUD I get weird graphics.

I suppose I would have to set up debug, debug_10, debug_100... but is there another way to show a byte in the HUD?

I'm using 4.5

Thanks!
 

theOldGameMaker

New member
I posted the question on the NESMakers Facebook group and got some interesting replies. I post them here to keep a trace.

Joe Granato: "...you're trying to do what now? You're trying to see the value of variables in the hud? The problem is, variables are in hex. The hud variables work in very particular ways in order to show numbers in dec. That...probably will not work for you.
There are a lot of ways that you could give visual feedback, but sometimes it's easier to just determine if you're getting the value you want. Like if debug is equal to 0, draw a sprite somewhere. That would be an easy way to handle quick confirmation checks that doesn't involve trying to write to the PPU."

Me: "Yes that's what I'm trying to do. I'm still trying to figure out how to implement collision for my Arkanoid game, and I wanted to show the x and y coordinates and other values as well. I figured out why there was an 8bit offset when colliding DOWN and RIGHT, but now the skull just stops when a collision occurs. I know my custom collision script is called (thanks to a JMP RESET). I just thought it would be a good debug feature to be able to show the actual value of a variable. Little by little, I'm gonna make it!!!"

Joe Granato: "That would be a great debug feature...but...it's not going to be an easy thing to implement. You'll have to really understand how the number system works, AND how the draw system works, AND how the PPU works. And it will eat resources and open up a lot of funkiness. It's completely possible, but you'd have to create a table to correlate two places of hex values (00 - FF) to their representative tiles, or push position values to dec places (0-255), in which case, you'll need to write a routine to parse hex to dec.
An EASIER way to do this? Draw sprites instead. Make a sprite row 0-f. Then you can use the position offset shifted four times to represent the high place (varHi), and the position with the top four bits lopped off to represent the low place (varLo)...whatever row you put those numbers in (let's say #$70-#$7f) in your tileset...you can just say #$70+varHi and then next to it draw #$70+varLo.
That would be easier on your system and invoke less chaos to achieve a similar result (of tracking position data of an object)"

Joe Granato: "Another trick I'll often use to debug:
1) You can pop a RESET if something has a particular value. So like, if you're trying to watch for something to be #$55, you could do:
LDA var
CMP #$55
BNE +skip
JMP RESET
+skip
or 2) write to a particular address (I use $07ff) and watch that address in the debugging tools.
LDA var
STA $07ff

Justin Thomas: "The other things is sometimes you might draw a value after it has gone to bad and then be reset to good. Or there may be some other variable that is off that misapplies your good variable value. Oh also, there is a console.log sort of in FCEUX, you just need to use the debugger and either set a watch or break on the variable.
If you look at the file demo.txt, you can find the address of your variable by Ctrl+f for the name you gave the variable (early in demo.txt it will list all your variables by name and RAM address)."
 

CluckFox

Active member
I have code that will display 8-bit values in 3-digit decimal on the Background HUD but it's messy. Here's what I used it for, let me know if it's what you're after and I'll either clean it up or DM you the unfiltered mess.

 

CluckFox

Active member
I take it by the show of thumbs you would like a cleaned-up demo with source. I'm happy to oblige and will reply again once I'm done.
 

CluckFox

Active member
Is something like this what you're after?



This was done with an 8-digit HUD variable called myPosition (myPosition_10, myPosition_100, etc. etc.) and a single AI script. I can export the game objects and tiles too if you'd like, otherwise the attached code & ROM should help you along.

Enjoy!
 

Attachments

  • GRAPHPAPER.zip
    17.3 KB · Views: 3

theOldGameMaker

New member
I wanted to try your script but I get an "unknown label" error. I put the script in the macro folder and it's in the macroList.asm file too.

Is there any step to get NES maker to recognize the macro? thanks again!
 

CluckFox

Active member
I wanted to try your script but I get an "unknown label" error. I put the script in the macro folder and it's in the macroList.asm file too.

Is there any step to get NES maker to recognize the macro? thanks again!
The script only needs to be assigned to an unused AI Action Step. The macros are for readability and are only meant to be "visible" within that one script:



Here is the corresponding Action Step:



and finally, the User Variables used to hold the HUD data:



Please note this arrangement is only suitable for testing and debugging during development. As far as I'm concerned it has little practical application otherwise.

Feel free to ask any more questions you have, I'm happy to help :)
 
Top Bottom