gba: add support for mGBA debugging#5443
Conversation
Implements `putchar` when `mgbadebug` build tag is set which outputs text through the mGBA debugging output interface. mGBA allows the games running in the emulator to output debug text the process to do so is: 1. set 0x4FFF780 to value of 0xC0DE 2. write text in memory 0x4FFF600 to 0x4FFF700 3. set 0x4FFF700 to the desired log level value from 0x100 (fatal) to 0x104 (debug) Once this is done mGBA will output the text in its logs view as well as through stdout. (Setting the log level to fatal also produces a dialog box with the text) The text output in the CLI is prefixed with `[DEBUG] GBA Debug: ` so I modified the regex used for address matching in panic messages to be able to read the address when the output line doesn't start with `panic`.
|
Nice! I was looking at adding this too except I was going to add it to https://github.com/tinygo-org/tinygba . I like the ability to just use |
|
Hmm I didn't realize I've had the code for mGBA debug printing in my code for at least 2 years as a custom log package. Eventually as the scale grew I started running into mysterious crashes very often that were really annoying to debug without seeing runtime panics, so having this code in the actual runtime has been pretty helpful. |
|
@zowhoey do please publish whatever code you have for gba. It would be amazing to have more support implemented, however we get it out there. If we can merge some of that into tinygba, great. If not, also fine. Just having a way to see working code that does things will be very helpful I'm sure! |
| logLevel uint16 = 0x104 // use the debug log level | ||
| // Once we are ready to output we set the debug flags register to logLevel | ||
| // mGBA will output the text and then clear the text buffer when set | ||
| debugFlags = (*volatile.Register16)(unsafe.Pointer(uintptr(0x4FFF700))) |
There was a problem hiding this comment.
I just wonder if it might be better to add this to https://github.com/tinygo-org/tinygo/blob/dev/src/device/gba/gba.go what do you think?
There was a problem hiding this comment.
I was a bit split on whether I should put the registers in the gba.go file or in runtime_mgba.go, I've decided to put it in the runtime_mgba.go file as it'd keep all mGBA specific code behind a build tag so it's easy to avoid using it on real hardware.
Although I suppose having it in gba.go makes it easier for people to implement their own logging if they want different log levels in the output.
There was a problem hiding this comment.
Actually you are right. Never mind, my suggestion was incorrect.
There was a problem hiding this comment.
Yes, please. Sorry about that.
There was a problem hiding this comment.
No problem at all, thank you for reviewing!
|
Thank you for the improvement @zowhoey now merging. |
Implements
putcharwhenmgbadebugbuild tag is set which outputstext through the mGBA debugging output interface.
mGBA allows the games running in the emulator to output debug text
The process to do so is:
0x104 (debug)
Once this is done mGBA will output the text in its logs view as well as
through stdout. (Setting the log level to fatal also produces a dialog
box with the text)
The text output in the CLI is prefixed with
[DEBUG] GBA Debug:so Imodified the regex used for address matching in panic messages to be
able to read the address when the output line doesn't start with
panic.After the change
results in output such as:

This makes debugging much easier as panic messages are shown and we can also do
debug prints.