English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 17 September 2021, 17:39   #1
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
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
8bitbubsy is online now  
Old 17 September 2021, 19:46   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,214
Quote:
Originally Posted by 8bitbubsy View Post
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.
Not enough information. What means "spawn a console"? If you open a console window with stream=Open("CON:...",MODE_NEWFILE), you close the window with Close(stream).



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.
Thomas Richter is offline  
Old 17 September 2021, 19:48   #3
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,709
Quote:
Originally Posted by Thomas Richter View Post
Not enough information. What means "spawn a console"? If you open a console window with stream=Open("CON:...",MODE_NEWFILE), you close the window with Close(stream).
Any program that doesn't attempt to open an Intuition window, will spawn a console when ran in Workbench. That's my understanding of it, at least. I don't spawn a console manually.

Quote:
Originally Posted by Thomas Richter View Post
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.
Because it's the simplest way, I'm new to Amiga programming, and I still need the main loop to be up and functioning.

Quote:
Originally Posted by Thomas Richter View Post
WaitTOF() is not your "generic delay function". For that, please use dos/Delay() instead. WaitTOF() may do something different on graphics cards.
I'm fully aware, I'm using it to wait until all vblank interrupts are done so that I'm in "idle time" in the frame. http://amiga.nvg.org/amiga/reference.../node048B.html
8bitbubsy is online now  
Old 17 September 2021, 20:27   #4
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,214
Quote:
Originally Posted by 8bitbubsy View Post
Any program that doesn't attempt to open an Intuition window, will spawn a console when ran in Workbench. That's my understanding of it, at least. I don't spawn a console manually.
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.
Thomas Richter is offline  
Old 17 September 2021, 20:30   #5
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,709
Whatever. Whenever I run the binary, it opens a console. Maybe because I print messages?
8bitbubsy is online now  
Old 18 September 2021, 09:34   #6
Thomas Richter
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.
Thomas Richter is offline  
Old 18 September 2021, 10:00   #7
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
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.
8bitbubsy is online now  
Old 18 September 2021, 11:04   #8
Exodous
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?
Exodous is offline  
Old 18 September 2021, 11:12   #9
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
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.
8bitbubsy is online now  
Old 18 September 2021, 12:36   #10
meynaf
son of 68k
 
meynaf's Avatar
 
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.
meynaf is offline  
Old 18 September 2021, 12:56   #11
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
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.
8bitbubsy is online now  
Old 18 September 2021, 13:40   #12
thomas
Registered User
 
thomas's Avatar
 
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.
thomas is offline  
Old 18 September 2021, 13:55   #13
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
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?
8bitbubsy is online now  
Old 18 September 2021, 14:11   #14
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by 8bitbubsy View Post
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?
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.
hooverphonique is offline  
Old 18 September 2021, 14:27   #15
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by 8bitbubsy View Post
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.
Yes, you can have a window and still use your WaitTOF pair. Just poll intuition events (without waiting) before or after each of them.


Quote:
Originally Posted by 8bitbubsy View Post
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?
The current shell will stall, unless you launch your program with the run command.
meynaf is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 14:26.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09751 seconds with 15 queries