andkrau / NuanceResurrection

Other
56 stars 5 forks source link

Expose KPrintf output log properly in UI #20

Closed gwald closed 8 months ago

gwald commented 11 months ago

Hi, I noticed KPrintf is implemented but disables. https://github.com/andkrau/NuanceResurrection/blob/be792e8e3716bbc127b79fa80165d8790b3ff618/bios.cpp#L673C8-L673C8

Could we please get the kprintf output to something similar to the button status, ie IDC_COMM_STATUS

This is what I've found: https://www.thehelper.net/threads/what-is-kprintf.181777/

gwald commented 11 months ago

I kinda need this feature. I've setup a VM with VS-C++ and tested removing the comments to pop up the kprintf lines, and it works. Edit: only the string part works, it doesn't process the string parameters.

It needs a manual prototype: extern void kprintf(const char *, ...); and linking to: -lrombios

If I can do it, i'll submit a pull request.

image

gwald commented 11 months ago

I wasn't able to figure out the winAPI stuff to duplicate the functionality of the buttons. It's a bit of a quick hack, using externs, but it's clear enough and it works fine. I forgot to mention in the PR, the fullscreen on cmdline starts is a pain, so it's turned off via reusing config bAutomaticLoadPopup... but it should really get it's own config option to control auto fullscreen.

There is also a release binary on my repo, if anybody wants it. https://github.com/andkrau/NuanceResurrection/pull/21

toxieainc commented 11 months ago

Is the PR complete then? Thanks!!

gwald commented 11 months ago

yes, I was using for a few hours after posting it.

toxieainc commented 11 months ago

Will leave this here open then to eventually expose it as described by you above

toxieainc commented 11 months ago

I also slightly tweaked the commit (mainly using the kprintf int to toggle fullscreen or not) and removed the .exe again.

gwald commented 11 months ago

cool, no problems :+1:

toxieainc commented 11 months ago

@gwald Could you please attach 2 versions of your sample program here? One with the string conversion done by your program, one without. And please as vars with different parameters/values, so e.g. %.3f %u %s, etc. Then i could properly implement kprintf

gwald commented 11 months ago

no problems, I'll use a little sample and upload the code and builds.

gwald commented 11 months ago

Example is based on the safe area sample program. USE_ONLY_KPRINTF files are kprintf only, the rest are via mvsprintf, as per the #ifdef in the code. This is the format: LOG("xpos:03%d ypos:%3d str<%s> u:%u h08:0x%08x f3:%.3f f:%f", xpos, ypos, buf, xpos<<16, xpos<<16,float_test,float_test);

kprintf-demo.zip

Type make test to rebuild it as required. I couldn't get floats to work at all, i'm guessing it's a mvsprintf issue, I couldn't get sprintf to work at all, but I had issues with the original makefile also, so it's probably something I'm not fully understanding somewhere.

I hope this helps :)

toxieainc commented 11 months ago

Yes, thanks it helps.

But unfortunately its not as easy as i thought. So i cannot spot where/how the args are passed in (easily/for now, mpe regs seem to not point somewhere useful and the mem behind the 'main' string is also not useful). So this will have to wait some more to tackle completely.

On the other hand, maybe the implementation in the rombios lib is also incomplete? After all its not even documented in the SDK AFAIK.

gwald commented 11 months ago

TMK it's not documented or in the headers. So you could be right about the kprintf parameters not being implemented.

toxieainc commented 11 months ago

Reopening again for the missing UI exposure.

cubanismo commented 8 months ago

@gwald PR #24 does everything you wanted. UI integration and kprintf parameter passing.

@toxieainc, the parameters to variadic functions are passed on the stack, after the first parameter, so all you have to do to get them is walk the stack pointer the code was already fetching. I've implemented this, including figuring out how to handle 64-bit parameters (long long unsigned, long long int, double/float). Then I piggybacked off of the MSVC implementation of sprintf to do the actual string conversions.

Once I had that working, the UI integration was really easy. Just added another button to the status dialog, used that to select the kprintf output, and set it up to auto-update whenever the kprintf bios code runs.

I replaced the file-based logging with my own version that I think is a bit cleaner (Let's you specify an arbitrary file to log to, and appends rather than replaces it at startup, integrates better with the NuonEnvironment class rather than using extern variable declarations all over the place), and eliminated the message box mode. Let me know what you think.

Note, the test program I attached to the PR prints a bunch of stuff using various format conversions/parameters at startup, and then prints it again every time you press the 'A' button. It includes a line counter so you can watch it scroll in the status dialog. Personally, I like to run this on Linux via WINE, enable the file logging, and then just run 'tail -f mykprintf.log' to track the output, but the UI is nice for quick checks, and probably more natural for windows-based devs.

toxieainc commented 8 months ago

D'oh, now that you say it, it makes total sense. :/

Great stuff, so closing here..