17 September 2021, 17:39 | #1 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,709
|
Close console after pressing ESC in program?
I have a non-window asm program that in Workbench spawns a console process when you run it, and in its main loop I check $bfec01 for ESC to end the program if it was pressed.
However, this has a problem... The program itself does end, but the console is kept open until you press enter. I think the reason for this is that it's listening to stdin, and an ESC press will put one character into stdin, and the console is waiting for you to press enter. Is there any way I can get rid of this problem? I want the console to quit together with my program. I don't really want the console to print any key presses. My main loop looks like this: Code:
.mainLoop move.l GraphicsBase(pc),a6 jsr _LVOWaitTOF(a6) jsr _LVOWaitTOF(a6) ; we're now in idle time, call software mixer bsr.w MixAudioFrame move.b $bfec01,d0 ; read key (not very system-friendly, but should work?) not.b d0 ror.b #1,d0 ; d0 = raw key cmp.b #69,d0 ; check for ESC bne.b .mainLoop |
17 September 2021, 19:46 | #2 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
Quote:
Besides, if you want to wait for a key pressed, why don't you open a RAW: window and wait for a key by a Read() on the stream? Poking the hardware is considered very bad practise. WaitTOF() is not your "generic delay function". For that, please use dos/Delay() instead. WaitTOF() may do something different on graphics cards. |
|
17 September 2021, 19:48 | #3 | |||
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,709
|
Quote:
Quote:
Quote:
|
|||
17 September 2021, 20:27 | #4 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
No, it doesn't. If you use "Execute" from the workbench window, or XIcon, your program will executed from a shell, and the shell will open the window, and in the shell, your program will execute. The workbench will open an AUTO/CLOSE/WAIT window, which means it will stay open until the user closes it.
|
17 September 2021, 20:30 | #5 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,709
|
Whatever. Whenever I run the binary, it opens a console. Maybe because I print messages?
|
18 September 2021, 09:34 | #6 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
Create an icon for your program, and make sure you handle the workbench startup mechanism. No, a program that has been started by the workbench process does not receive a console.
|
18 September 2021, 10:00 | #7 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,709
|
EDIT: I see, my program is not spawning a console, but an "output window". I have the same problem there as when running it from the shell:
When I press ESC, the process terminates (music stops), but the output window is kept open with an ESC character printed to its character buffer. Shell is also just showing the ESC character in its output buffer instead of getting back to prompt. In the case of running it from a shell and pressing ESC, you just press enter and the shell will get back to the prompt. In terms of the output window, you have to manually close it. Quite annoying! I wish I could get rid of both symptoms, e.g. shell goes back to prompt after pressing ESC, and output window closes after ESC (if you ran it through double-clicking on the program). Last edited by 8bitbubsy; 18 September 2021 at 10:29. |
18 September 2021, 11:04 | #8 |
Registered User
Join Date: Sep 2019
Location: Leicester / England
Posts: 201
|
If you start from Workbench, there is no standard output file handle, so it sounds like your debug output function is fnding the fact that there is no handle and therefore opens this "output window".
Are you linking to a pre-built library (like amiga.lib) and then using something like a printf for your debug messages? |
18 September 2021, 11:12 | #9 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,709
|
They are not debug messages, they are the program's actual output by calling _LVOPutStr. It prints messages and then enters a loop until you press ESC. And no, I don't link anything.
The program is an XM player that for the time being works in the console (or the output window if you didn't run it from the shell). I want the user to see the messages, it shows important information. Anyway, this thread is a mess, I see now that I managed to not ask what I really wanted to ask, and it shows confusing messages. Last edited by 8bitbubsy; 18 September 2021 at 11:18. |
18 September 2021, 12:36 | #10 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Any program run from a WB pseudo icon will spawn an "output window". This window will not close until the user presses the close button and AFAIK you have no control on this.
But it won't physically open if nothing is done with input/output handles. So I think you'd be better off by opening your own. Another problem is that you're peeking the keyboard without proper handshaking and with the OS still running - i.e. pretty dirty but this looks temporary. Either use the OS to get keyboard input (don't ask ME how ), or turn it off and do correct keyboard reading (which is not that easy either). Or keep actual code, but this is only valid for a test program. |
18 September 2021, 12:56 | #11 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,709
|
Ok, I see. I think I'll end up programming a small GUI for the player instead. However, I need to be able to have a loop that runs WaitTOF twice and then mixes audio samples. Is this possible when you have an Intuition/window loop instead?
I can't use a vblank interrupt for this, because I'll not end up in idle time. This is important, the mixer should only mix samples in idle time so that it doesn't slow down the system. |
18 September 2021, 13:40 | #12 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
You can open a CON window yourself and use that instead of stdin/stdout. Then you have control over closing the window and next to no changes in your program.
|
18 September 2021, 13:55 | #13 |
Registered User
Join Date: Sep 2009
Location: Norway
Posts: 1,709
|
Maybe I should. But how will it act when I run the player from within the shell? Will the current shell stall, and a new console opens?
|
18 September 2021, 14:11 | #14 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Check in your program if it runs from workbench or a shell - if shell, assign stdout to your output stream variable, if workbench, open a console yourself and assign its output stream to your variable.
|
18 September 2021, 14:27 | #15 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
The current shell will stall, unless you launch your program with the run command. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Simple CLI program to close all open windows? | DEAT | support.Apps | 7 | 31 March 2020 05:49 |
ESC Key | AGS | Coders. System | 10 | 14 August 2014 17:15 |
Can an amiga program close WinUAE? | xxxxx | support.WinUAE | 3 | 06 August 2014 06:21 |
Disable LALT-ESC | Ed Cruse | request.UAE Wishlist | 6 | 02 March 2011 19:56 |
|
|