Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interrupt instruction for games to print to terminal #1947

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

abaresk
Copy link

@abaresk abaresk commented Jan 9, 2024

If the game executes svc 0xFC, the contents of the null-terminated string addressed in register r0 will be printed to the terminal.

For consistency, this is the same mechanism that is used in Desmume (source).

u32 c;
cpu->DataRead8(addr++, &c);
if (!c) break;
printf("%c", c);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Platform::Log instead of printf. Then the output can go wherever the frontend wants it to instead of always stdout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you.

@windwakr
Copy link

Is there actually any homebrew out there that uses this over nocash prints?

@abaresk
Copy link
Author

abaresk commented Jan 11, 2024

This is more helpful for rom-hacking and decompilation, where you'd have the ability to insert arbitrary print statements.

Additionally, as far as I'm aware, Desmume does not support the nocash debug registers. It would be nice to have a printing mechanism that works across both emulators.

@abaresk
Copy link
Author

abaresk commented Jan 18, 2024

Just following up, are there any concerns with merging in this feature?

@abaresk
Copy link
Author

abaresk commented Feb 28, 2024

Sorry to keep bugging, is it okay to merge this?

@Gericom
Copy link

Gericom commented Jun 7, 2024

I would suggest that if this feature will be added it should be an opt-in feature to avoid clashing with possible other uses of this swi. E.g. someone can map vectors to itcm and have their own swi handler. It's rare, but possible (for example in gbarunner3). Personally I think the existing way to print with no$ IO registers is less intrusive in that regard.

@@ -266,6 +266,22 @@ void A_MRC(ARM* cpu)

void A_SVC(ARM* cpu)
{
// Print from game. Execute `svc 0xFC` with the null-terminated string address in `r0`.
if ((cpu->CurInstr & 0xFF) == 0xFC && cpu->NDS.GetDebugPrint())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried ((cpu->CurInstr >> 16) & 0xFF) as suggested, but this didn't work in practice. The interrupt instruction (swi 0xFC) was compiled to the following:

   8:   ef0000fc        svc     0x000000fc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants