Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
There is an option called "GB CPU usage meter" in BGB (press F11, go to "Debug" tab, last checkbox at bottom left). Is this a feature that allow to view how much CPU is spend executing code (eg :draw or update) vs waiting for VSync ?
I don't know how to use it. It seems it is the green bar in the debugger near registers (since double clicking on it will disable "GB CPU usage meter" option). Anyway it's always green (even with some rom running in background)
Does anybody know how to use that feature ?
Offline
This feature measures how much time is used for executing code vs how much CPU time is spent in low power mode using the HALT opcode. Time spent in the HALT mode is indicated with a dark green. Note however that many games don't use the HALT opcode, despite Nintendo's recommendations and in this case the meter will be solid green.
If you are developing your own software, you should generally put a HALT in your mainloop instead of an endless loop.
xor A ; Clear A (A=0)
ld [rIF],A ; Clear the pending interrupt register
inc A ; Increment A from 0 to 1
ld [rIE],A ; Enable the VBlank interrupt
ei ; Done with all initialization. Enable interrupts.
MainLoop:
halt ; Sleep until the next interrupt happens
jr MainLoopIf you need to do other stuff in the mainloop, you could signal this from the VBlank interrupt handler.
xor A ; Clear A. (A=0)
ld [rIF],A ; Clear the pending interrupt register.
inc A ; Increment A from 0 to 1.
ld [rIE],A ; Enable the VBlank interrupt.
ei ; Done with all initialization. Enable interrupts.
MainLoop:
halt ; Sleep until the next interrupt happens.
ld A,[vblank_happened]
dec A ; Check if A == 1. Also makes A == 0 if it was 1.
jr nz,MainLoop
ld [vblank_happened],A ; Write back 0.
; Do other stuff.
; ...
jr MainLoop
VBlankHandler:
; Do other stuff.
; ...
ld A,1 ; Signal that a VBlank happened.
ld [vblank_happened],A
POPA
retiThere's also another secret meter that you can access by pressing ctrl+shift+9 while the game is running. (Not in the debugger. In the debugger it places a bookmark in the code instead.) The left part is always either black or pink and isn't part of the CPU meter. The meter has three parts: Yellow for normal code. Red for code that BGB was able to detect and skipped over, and could probably be replaced with a HALT loop. And black for time spent in HALT mode.
Offline
Thanks for your detailed answer.
The game I am debugging (SML3/WL1) simply waits for VBlank in a loop (by checking value of a flag set in VBlank interrupt handler).
That is why the BGB feature does not work.
I will maybe patch it and use HALT as you suggested. I want to check how much CPU game use to see how far it push GB to the limit.
EDIT : using your instructions, I was able to patch the ROM (and replace pooling with an HALT instruction)
It works really great. CPU usage during level gameplay is 60% in average, sometimes going up to 95% depending what is on the screen (but never reach 100%, probably to keep 60 fps)
When using doors, it goes as low as 10% (during fade in / out) then reach 100% for a short burst (probably to load new tiles to video memory)
Last edited by tigrou (2020-02-19 10:00:39)
Offline