English Amiga Board


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

 
 
Thread Tools
Old 31 March 2023, 18:13   #1
REAKTOR BEAR
Registered User

 
Join Date: Mar 2021
Location: SWEDEN
Posts: 23
ESC key pressed?

We would like our program to exit on ESC... The issue is, that CLI captures all keypresses and only send to $bfec01 when ENTER key is pressed.

How do we instantly trigger program exit on ECS key, if the program is started from CLI?
Do we have to use DOS.library(READ) or is there an easier way.

Last edited by REAKTOR BEAR; 02 April 2023 at 09:31.
REAKTOR BEAR is offline  
Old 31 March 2023, 20:01   #2
CFou!
Moderator
CFou!'s Avatar
 
Join Date: Sep 2004
Location: France
Age: 50
Posts: 4,169
try EndCLi
CFou! is offline  
Old 31 March 2023, 20:26   #3
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 2,515
Quote:
Originally Posted by REAKTOR BEAR View Post
Do we have to use DOS.library(READ) or is there an easier way.
The easier way is to switch the console to raw-mode with SetMode(), and then use WaitForChar() of the dos.library to check whether keys have been recorded, then Read() to remove them from the input buffer. Last, switch back to cooked mode with SetMode().
Thomas Richter is offline  
Old 01 April 2023, 22:18   #4
REAKTOR BEAR
Registered User

 
Join Date: Mar 2021
Location: SWEDEN
Posts: 23
Ok thanks, I was hoping $bfec01 combined with an interupt setting could be used for ESC-key to end the program (rts)... if possible take control of mouse and keyboard from OS while our program is running, but maybe that is too advanced

P.S. Where can we learn about SetMode and WaitForChar?

Last edited by REAKTOR BEAR; 01 April 2023 at 22:37.
REAKTOR BEAR is offline  
Old 02 April 2023, 02:28   #5
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,173
You can read about those functions in the autodocs for dos.library. It's in the AmigaOS NDK.
idrougge is offline  
Old 02 April 2023, 08:40   #6
REAKTOR BEAR
Registered User

 
Join Date: Mar 2021
Location: SWEDEN
Posts: 23
Great found it (https://d0.se/autodocs/dos.library)
Our program runs 320x256 fullscreen, so disabling OS interupt and read ESC keycode from $bfec01 is possible, we just don't know how to set the proper interupts for this to work.

Code:
	
move.b	$bfec01,d0		;keyboard buffer
not.b	d0			
ror.b	#1,d0			;rotate right 1 bit
cmp.b	#$45,d0			;is esc keycode $45 pressed?
beq	exit			;goto exit
In ASMPro it works fine, but not when running from CLI... It has something to do with intena ($dff09a) or intreq ($dff09c).

Last edited by REAKTOR BEAR; 02 April 2023 at 09:20.
REAKTOR BEAR is offline  
Old 02 April 2023, 09:17   #7
koobo
Registered User

koobo's Avatar
 
Join Date: Sep 2019
Location: Finland
Posts: 278
Quote:
Originally Posted by REAKTOR BEAR View Post
Great found it (https://d0.se/autodocs/dos.library)
Our program runs 320x256 fullscreen, so disabling OS interupt and read ESC keycode from $bfec01 is possible, we just don't know how to set the proper interupts for this to work.

Code:
	
move.b	$bfec01,d0		;keyboard buffer
not.b	d0			
ror.b	#1,d0			;rotate right 1 bit
cmp.b	$45,d0			;is esc keycode $45 pressed?
beq	exit			;goto exit
In ASMPro it works fine, but not when running from CLI... It has something to do with intena ($dff09a) or intreq ($dff09c).
Reading keyboard is actually pretty complicated. The system handles all this for you of course.

If I recall correctly, which I might not, the keyboard is a serial device and needs correct interaction for transferring key data (which is visible in $bfec01). There is a level 2 interrupt triggered for a key press, after which the keyboard needs a correct timed handshaking procedure, if this is not done, no further data will be available in $bfec01.

You might get away by killing the system but keeping the correct level 2 interrupt enabled, so $bfec01 still be updated with keys codes
koobo is offline  
Old 02 April 2023, 09:23   #8
REAKTOR BEAR
Registered User

 
Join Date: Mar 2021
Location: SWEDEN
Posts: 23
So maybe that's the issue... when using AsmPro it works fine because it does the serial handshaking for us.... I will try Level 2 interupts (http://amigadev.elowar.com/read/ADCD.../node0036.html), and also some dos.lib methods and return with a solution.

Last edited by REAKTOR BEAR; 02 April 2023 at 09:45.
REAKTOR BEAR is offline  
Old 02 April 2023, 09:52   #9
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 2,515
Quote:
Originally Posted by REAKTOR BEAR View Post
Ok thanks, I was hoping $bfec01 combined with an interupt setting could be used for ESC-key to end the program (rts)... if possible take control of mouse and keyboard from OS while our program is running, but maybe that is too advanced
Look, that's not how programming AmigaOs works. With the Os interface functions, you receive keyboard events only if the window (or interface) of your program is in the input focus, and the input focus is set by the mouse.


The above functions are for reading raw keys from the console, if that is the user interface of your program. If your user interface is a window on the screen, you use the IDCMP port of the window, and then intuition will deliver keyboard events only if the window is in the input focus.


Banging the hardware is not the answer - this is not a C64. If you bang the hardware, you not only confuse the Os and by that all other programs that run on the machine at the same time - you also "receive" input even if your program should not, because the input focus is another window.


Quote:
Originally Posted by REAKTOR BEAR View Post
P.S. Where can we learn about SetMode and WaitForChar?
In the AmigaDOS manual, from Bantam Books, or in the includes and autodocs RKRM. The latter are even available online.
Thomas Richter is offline  
Old 02 April 2023, 21:52   #10
REAKTOR BEAR
Registered User

 
Join Date: Mar 2021
Location: SWEDEN
Posts: 23
Yes Thomas, we would love to read the rawcodes with IDCMP or dos.lib, but as a beginner, where do we go to actually read how to access rawcodes from the con window... I totally understand that it has something to do with intuition.library, and I know how to access a library... but for a beginner how can we learn IDCMP to get the ESC rawcode using intuition.library?

Our program is 320x256 fullscreen, started from myProgram.exe in CLI, so it should be able to read keys from that CLI con handle.

We just need some pro coder, to show how its done

Last edited by REAKTOR BEAR; 02 April 2023 at 22:17.
REAKTOR BEAR is offline  
Old 02 April 2023, 22:39   #11
remz
Registered User

 
Join Date: May 2022
Location: Canada
Posts: 115
Perhaps as a suggestion, have you tried looking at the ACE engine? It is in C and it shows how to read keyboard, etc.
(Are you working directly in assembler for your project?)
remz is offline  
Old 02 April 2023, 23:32   #12
No.3
Registered User

 
Join Date: Sep 2022
Location: Switzerland
Posts: 68
It would be better if he familiarizes himself with screens, windows and message ports. Especially window message ports and corresponding IDCMP messages?!?
No.3 is offline  
Old 03 April 2023, 02:17   #13
redblade
Zone Friend

redblade's Avatar
 
Join Date: Mar 2004
Location: Middle Earth
Age: 39
Posts: 2,007
http://aminet.net/package/dev/asm/Asm_course

Is a tutorial that contains ASMOne 1.6 and its example files. One of the example files opens a lo-res screen, draws the Julia set and waits for the user to hit the space bar to quit, it is well commented and doesn't use the includes as all the offsets are included in the source.

I'm hoping that might be good enough to use as a template.

I don't know if its GettingStarted.S or SystemStartup.s

I hope that helps
redblade is offline  
Old 03 April 2023, 14:05   #14
REAKTOR BEAR
Registered User

 
Join Date: Mar 2021
Location: SWEDEN
Posts: 23
Thanks for all the help, we managed to open a custom screen and read the ESC key. The underlying CLI still records keystrokes, but at least now we can exit the program with ESC

Does anyone know how to stop the underlying CLI from reading all the key strokes? It looks a bit silly that the CLI is full of chars when the program exits.

Code:
*** System constants ***

execbase = 4
openlib = -408
openscreen = -198
closescreen = -66
ciaserial = $bfec01

*** Open intuition library ***

intuitionlib:
	move.l	execbase,a6	;execbase
	lea 	intlib,a1	;what library to open
	moveq	#0,d0		;specify library version? 0 = no
	jsr	openlib(a6)	;open library
	move.l	d0,intbase	;save library memory address

*** Open screen ***

screenopen: 
	move.l	intbase,a6	;use intuition libraray
	lea 	screendefs,a0 	;settings for screen
	jsr 	openscreen(a6)	;call openscreen function in library
	move.l	d0,screenhandle	;save screen memory address

*** Loop ***

waitloop:
	move	#$0f0f,$dff180	;background color = pink

*** ESC key ***

esckey:
	move.b	ciaserial,d0	;keycode data input address
	not.b	d0
	ror.b	#1,d0		;rotate bits right 1 postiton
	cmp.b	#$45,d0		;esc raw-keycode = $45
	bne	waitloop

*** Exit ***

screenclose: 
	move.l	intbase,a6		;use intuition library
	move.l	screenhandle,a0 	;what screen to close
	jsr	closescreen(a6) 	;call close funtion in library
	rts				;end program

*** -------------------- DATA ---------------- ***

*** Intuition library ***

intlib: 
	dc.b	"intuition.library",0
	even 

intbase:
	dc.l	0

*** Screen settings ***

screenhandle: 
	dc.l 	0 	;screen pointer 
	dc.l 	0 	;no bitmap of our own 
	dc.w 	150 	;smallest width 
	dc.w 	50 	;smallest height 
	dc.w 	320 	;maximum width 
	dc.w 	200 	;maximum height 
	dc.w 	15 	;screen type = custom screen 

screendefs: 
	dc.w 	0	 	;xpos 
	dc.w 	0	 	;ypos
	dc.w 	320  		;width
	dc.w 	200  		;height
	dc.w 	2  		;depth
	dc.b 	0 		;detail pen
	dc.b 	1  		;block pen
	dc.w 	2  		;view modes
	dc.w 	15  		;screen type
	dc.l 	0 		;font
	dc.l 	screenname	;pointer to screentitle
	dc.l 	0 		;gadgets
	dc.l 	0 		;bitmap

screenname: 
	dc.b 	"Our Screen",0 
	even

Last edited by REAKTOR BEAR; 03 April 2023 at 14:26.
REAKTOR BEAR is offline  
Old 03 April 2023, 15:13   #15
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,347
Quote:
Originally Posted by REAKTOR BEAR View Post
Does anyone know how to stop the underlying CLI from reading all the key strokes? It looks a bit silly that the CLI is full of chars when the program exits.
You need a new active window to receive the keyboard strokes. You can open a borderless window on that screen (so you don't even see it).

And, most importantly, decide if you want to program the hardware directly or use the OS. Never do direct hardware access when the OS is alive!
phx is offline  
Old 03 April 2023, 15:16   #16
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 2,515
Quote:
Originally Posted by REAKTOR BEAR View Post
Yes Thomas, we would love to read the rawcodes with IDCMP or dos.lib, but as a beginner, where do we go to actually read how to access rawcodes from the con window... I totally understand that it has something to do with intuition.library, and I know how to access a library... but for a beginner how can we learn IDCMP to get the ESC rawcode using intuition.library?
First, are you working from a console, or do you plan to open a new window? Depending on your course of action, the answer will be different.


Quote:
Originally Posted by REAKTOR BEAR View Post
Our program is 320x256 fullscreen, started from myProgram.exe in CLI, so it should be able to read keys from that CLI con handle.
No, you should not. The input focus will then be of course that of the window on the screen, and not of the console. Nothing will go to the console, and it would be rather confusing if the user had to switch back to the console to press ESC.


In that case, you open a backdrop borderless window on the screen, so you do have the chance of receiving input, set as IDCMP the IDCMP_RAWKEY, and you will receive raw key events, with ie_Code being the key code.
Thomas Richter is offline  
Old 03 April 2023, 18:28   #17
REAKTOR BEAR
Registered User

 
Join Date: Mar 2021
Location: SWEDEN
Posts: 23
Post

We are using only hardware coding to open displaywindow bitplanes copper and all of that... That is why it seems silly to use intuition just to get an ESC key to work.. But I really dont care what method, as long as ESC key can trigger "rts" end program

There is a dos.lib function that seem to work, but is hangs the entire system until a char is received.

Code:
	
getchar:
	move.l	dosbase,a6
	move.l	conhandle,d1
	jsr	fgetc(a6)
Thomas: We are doing a classic 90's demo with some copper FX and such... it is started as an EXE from CLI window. So maybe a borderless window is the way to go.

How do we open a borderless window to recieve IDCMP_RAWKEY?

Last edited by REAKTOR BEAR; 03 April 2023 at 18:37.
REAKTOR BEAR is offline  
Old 03 April 2023, 19:43   #18
redblade
Zone Friend

redblade's Avatar
 
Join Date: Mar 2004
Location: Middle Earth
Age: 39
Posts: 2,007
If you are hitting the hardware directly for your production then use some of the source code from flashtro.com. There should be some trainer code on that site which uses the Function keys to set values and replace that code with the raw key code for the ESC button.
redblade is offline  
Old 03 April 2023, 19:44   #19
REAKTOR BEAR
Registered User

 
Join Date: Mar 2021
Location: SWEDEN
Posts: 23
Thumbs up

I used some of Thomas's inputs and here is the final solution to whomever would need it:

Code:
*** System constants ***

execbase = 4
ciaserial = $bfec01
output = -60
openlib = -408
setmode = -426

*** Execbase ***

	move.l	execbase,a6	;execbase to a6

*** DOS library ***

	lea 	doslib,a1	;dos.library pointer
	moveq	#0,d0		;specify a library version 0 = no
	jsr	openlib(a6)	;open dos.lib
	move.l	d0,dosbase	;save pointer to -> dosbase

*** Get conhandle ***

	move.l	dosbase,a1	;dosbase pointer
	jsr	output(a1)	;get conhandle
	move.l	d0,d1		;conhandle to d1
	move.l	d0,conhandle	;save pointer to -> conhandle

*** Set CLI to raw-mode ***

	move.l	dosbase,a1	;dosbase pointer
	move.l	conhandle,d1	;conhandle pointer
	move.l	#1,d2		;mode 1 = rawmode
	jsr	setmode(a1)	

*** Read serial data ***

	move.b	ciaserial,d0	;pointer to serial data	
	not.b	d0
	ror.b	#1,d0		;rotate right 1 position
	cmp.b	#$45,d0		;was key press ESC $45?
	beq	exit		;goto exit

---- Frameloop goes here ---
---- Frameloop goes here ---

*** Restore CLI to con-mode ***

exit:
	move.l	dosbase,a6	;dosbase pointer
	move.l	conhandle,d1	;conhandle pointer
	clr.l	d2		;clr d2 to set con mode
	jsr	setmode(a6)	;call setmode function in dos.lib
	rts			;end program

*** -------------------- Data ------------------- ***

doslib:
	dc.b	"dos.library",0
	even

dosbase:
	dc.l	0

conhandle:
	dc.l	0
There may be some typo's but hopefully people will get the general idea. Thanks for all the help

Last edited by REAKTOR BEAR; 03 April 2023 at 19:52.
REAKTOR BEAR is offline  
Old 04 April 2023, 07:58   #20
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 2,515
No, you still get it wrong. You *do not* bang the hardware. "ciaserial" is not for you to access. If you want to read the console, use Read() or WaitForChar(). Or, and that is the correct method if your program opens its own window, use the IDCMP of that window. The hardware is a shared resource - the way how you program does not allow the user to shift the input focus and press ESC within a completely different application.
Thomas Richter 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
ESC key in Budokan on FS-UAE NetSlut support.WinUAE 2 05 April 2022 12:26
fault esc key smashngrab support.Other 8 27 March 2016 21:37
ESC Key AGS Coders. System 10 14 August 2014 17:15
Debian crashes with kernel 2.6.8 when key pressed mark_k support.WinUAE 1 27 September 2013 19:55
ESC key seems to crash Leslie Viljoen support.FS-UAE 1 17 December 2012 17:25

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 19:02.


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