Re: [hatari-devel] Hatari debug mode |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] Hatari debug mode
- From: Vincent Rivière <vincent.riviere@xxxxxxxxxxx>
- Date: Sun, 3 Aug 2025 15:51:40 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754229111; x=1754833911; darn=lists.tuxfamily.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=d8vMnBUiZX+tEKjV1oygd0jNqJsODR+w/JcaDyVkQQM=; b=HvBXS4shhfaIeZtRUhT2z3BdyHlSbx2VLCEXcekPvT3lcHu11BhtdwQMUIxTriielg 2ViW6ref5FaxPGBJr0cJgXG5zLf5rtPsJlfSwBAwJ0z6ReGSUI+Gh5aRexX9WuUheg9S D95cYy7A1emkqXbU6fUstIVN1pOB3eepssuQQNFltvSp24uiV54cSNhR3QJ01pA6UEaj M9FGkcUgqeBb9UCp92xxu6f5ycgMbI9+9DYapLZDQ7bwbuvloc1GgculuYtV+47XTzwl DR7tgMgtfOurVZLlAHffgnfsQkT4J2YIvD2NNs1MFQELnjAIvA2Oh7GsJmaGC6EZ/yni wFsg==
On 31/07/2025 at 21:08, Nicolas Pomarède wrote:
regarding this console issues, do you know if there's a way to detect in
which "context" Hatari was launched ? ie from an already opened console or
by clicking on its icon (or using windows menu to launch it) ?
Unfortunately, Windows isn't designed to do that at runtime. Availability of
a console is normally specified at link-time: either "console application"
or "GUI application". This sets a specific bit in the .exe header.
- If the program is a "console application" (compiled with gcc -mconsole),
Windows ensures there is always a console to perform text I/O. If the
program is run from a shell (i.e. cmd.exe), the shell's console is reused.
If the program is double-clicked from the Explorer, a new console is opened.
printf() output is of course directed to that console. This is the classic
UNIX behaviour, except that the console is automatically opened by the
operating system if there is none. This is a good thing for text-mode
programs, but undesirable for GUI programs.
- If the program is a "GUI application" (compiled with gcc -mwindows), no
console is reused or opened on startup. printf() does nothing, as console
I/O isn't initialized. Furthermore, if run from a cmd, the program is
started asynchronously (like "&" suffix on bash shell), so the user can type
new commands without having to wait for the program's end. Such programs can
be run synchronously by using the "start /w" prefix, such as "start /w
notepad". On the contrary, when programs are run from a .bat file, they are
always run synchronously.
When run from cmd, a GUI program can attach itself to the cmd's console
using AttachConsole(ATTACH_PARENT_PROCESS). Then it can reinitialize stdout
using GetStdHandle / freopen_s / setvbuf (*), so it can use printf. But this
isn't ideal, because the starting cmd isn't aware of that special behaviour
going to happen, so it starts the program asynchronously anyway. And as
Thorsten mentioned, such hacks don't work well with MinTTY (the terminal
used by Cygwin and MSYS2).
(*) https://forum.qt.io/topic/144399/command-line-and-gui-at-same-time/4
The most common solution is to avoid those hacks, and simply provide 2
executables. One compiled with -mconsole (to run with console), and the
other one with -mwindows (to run without console). This is the solution
chosen by the Java Runtime Environment. On UNIX systems, there is a single
"java" command, which may or may not produce output to the console. On
Windows systems, "java.exe" is a console application, so output can be
displayed. And a second executable "javaw.exe" is provided, that one being a
GUI application, silently ignoring all console output. So the user is free
to use "java" or "javaw" depending on the context. Hatari could to the same,
with hatari.exe and hatariw.exe executables.
--
Vincent Rivière