English Amiga Board


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

 
 
Thread Tools
Old 31 July 2021, 16:16   #1
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
Readin keyboard and IRQs

Hi,

Context : Amiga 500 1.3, non OS programing.

Would like to implement a pause in my program.
But I don't understand how works these keyboard thingies.

The routine doesn't detect any press at all, I suspect it's an IRQ enable pb. But I don't know which IRQ it is precisely.
I have IRQ blitter enable only in INTENA.

Code:
moveq #0,d0
bset #6,$bfee01
move.b	$bfec01,d0
bclr #6,$bfee01
not.b	d0
ror.b	#1,d0
clr.b $bfec01
cmp.b	#$50,d0		; F1 ?
bne.b	.non			; no
Also, I have another question. if the IRQ I need to enable for keys is lower priority than the actual IRQ I use in my programm, if an higher IRQ triggered during lower priority running IRQ, does it interrupted or it waits until running IRQ is finished ? In another words, does IRQs are linear sequential or like a tree sequence ?
LeCaravage is offline  
Old 31 July 2021, 16:29   #2
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
http://eab.abime.net/showthread.php?t=107718

Higher level interrupt will trigger without waiting on lower level interrupt to finish.
a/b is offline  
Old 31 July 2021, 16:54   #3
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
Quote:
Originally Posted by a/b View Post
Higher level interrupt will trigger without waiting on lower level interrupt to finish.
Madre mia, not good news for me then ^^

http://eab.abime.net/showthread.php?t=107718


Thanks dude.
Will try to adapt it. May be I'll be back for further question or stuck.
LeCaravage is offline  
Old 31 July 2021, 17:07   #4
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
By the way what is the meaning exactly of :

Code:
move.w	#$4000,$09a(a6)
?
LeCaravage is offline  
Old 31 July 2021, 18:42   #5
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
Disable ($4000) or enable ($c000) all interrupts via master enable bit.
http://amigadev.elowar.com/read/ADCD.../node0036.html
a/b is offline  
Old 31 July 2021, 19:37   #6
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
MOVE to SR can be used.
No need to save the old value cause RTE puts the right value back.

But it is a little used practice because if an IRQ has a higher priority there is usually a reason
(and remember in any case, if you do it, to make a very quick routine!)
ross is offline  
Old 01 August 2021, 11:34   #7
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
@a/b : So you turn off irqs during keys scan. No need for a keyboard irq (or sort of) to be allowed then, good news indeed.

@ross: With MOVE to SR I make sure there's no other higher irq triggered. Did I understand well ? And right after the RTE, the higher irq is triggered. If yes, that's cool trick.

@a/b : You're routine is cool but we waste 2 scanlines, may be more because in my case I use all 6 bitplans DMA and also blitter. Any chance to split this routine at two locations in loop where we are sure to have enough time between ?
LeCaravage is offline  
Old 01 August 2021, 12:33   #8
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by LeCaravage View Post
@ross: With MOVE to SR I make sure there's no other higher irq triggered. Did I understand well ? And right after the RTE, the higher irq is triggered. If yes, that's cool trick.
Yes, a
MOVE #$2600,SR
prevent any IRQ <= 6 from happening (you cannot stop an IRQ7..).
And yes, right after the RTE the higher IRQs, if any, are triggered.
ross is offline  
Old 01 August 2021, 15:03   #9
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
Thanks pal, now I just have to make sure the code run in supervisor mode.
LeCaravage is offline  
Old 01 August 2021, 15:46   #10
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by LeCaravage View Post
Thanks pal, now I just have to make sure the code run in supervisor mode.
For sure it run in supervisor mode, IRQ call activate it
ross is offline  
Old 01 August 2021, 17:22   #11
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
Delay can be (partially) eliminated but that heavily depends on when, how and what your code is doing, and how exact the keyboard handler has to be. E.g. if you press 3 keys at the same time, is it ok to detect a single key in each consecutive frame or do you have to detect all 3 in a single frame (meaning you have to do 3 delays in single frame)?
You could start a handshake, do some processing and then finish a handshake with an optional wait just in case you are running on a very fast cpu (e.g. if you are doing this in a vblank interrupt, start with keyboard polling and start a handshake, then at the end of the interrupt finish a handshake if needed + optional wait). Or you could use a CIA timer interrupt to finish a handshake. Or if you are polling the keyboard at exactly the same screen position every time (e.g. first thing you do in a vblank interrupt) you could use copper to optionally trigger an interrupt to finish a handshake, etc.
Also, delay has to be at least 85 microsec and I don't know how much slower it can be, if there even is a cap, so this opens more possibilities but that could be tricky because it might not work on all keyboard models. For example, start with finishing a handshake from the previous frame (after a ~20 *millisecond* delay), do some processing to give the keyboard enough time to fill in the next keycode if there is one, then poll the keyboard and if there is a new keycode start a handshake (which will be finished in the next frame).
Too many unknowns to know what would be the best fit...
a/b is offline  
Old 01 August 2021, 17:27   #12
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
@ross : hehe, no doubt, I learn a lot there. I wonder how many cycles cpu takes to switch to supervisor and reverse at exit.

@a/b : CIA is the way to go I guess, because I use a copper lvl 1 irq for vertical sync.

Ok, the pause routine works just fine now. The pb was coming from the fact that I didn't understand how works this keys scan (still I don't to be honest). The flag is set only when the key is pressed down. I assumed it was always when key is down.. So need two flags for pause managment, one for key down and another for switch pause state on/off.

Anyway, thanks @all for help and have a nice sunday.
LeCaravage is offline  
Old 01 August 2021, 17:33   #13
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Just for reference.
Some users in the past have reported to me that 85us was not enough for their keyboard.
I was using some code with precise timed delay (CIA), not by beam counter wait that's imprecise by definition.

They weren't standard keyboards from the Amiga 500 or 1200, I think they were from the Amiga 2000.
And despite 85us being the reference value in HRM, some keyboards need 200us…, so use this value if possible as a minumum.
ross is offline  
Old 01 August 2021, 23:44   #14
redblade
Zone Friend
 
redblade's Avatar
 
Join Date: Mar 2004
Location: Middle Earth
Age: 40
Posts: 2,127
Quote:
Originally Posted by ross View Post
Just for reference.
Some users in the past have reported to me that 85us was not enough for their keyboard.
I was using some code with precise timed delay (CIA), not by beam counter wait that's imprecise by definition.

They weren't standard keyboards from the Amiga 500 or 1200, I think they were from the Amiga 2000.
And despite 85us being the reference value in HRM, some keyboards need 200us…, so use this value if possible as a minumum.
Was this all Amiga 2000s or is there a difference between the German and US Amiga 2000?
redblade is offline  
Old 02 August 2021, 00:04   #15
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by redblade View Post
Was this all Amiga 2000s or is there a difference between the German and US Amiga 2000?
Problematic ones are some (or all?) A2000 keyboards made by Cherry.
Some EU users of this forum have them, I don't know for US users.

EDIT:
ah! NetBSD kbd.c:
Code:
	/* wait 200 microseconds (for bloody Cherry keyboards..) */
	DELAY(200);			/* fudge delay a bit for some keyboards */
	ciaa.cra &= ~(1 << 6);

Last edited by ross; 02 August 2021 at 00:11.
ross is offline  
Old 02 August 2021, 04:01   #16
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 839
Quote:
Originally Posted by ross View Post
Problematic ones are some (or all?) A2000 keyboards made by Cherry.
Some EU users of this forum have them, I don't know for US users.
I have one that came with a B2000 rev 4.2(or was it 4.1?), but I'm pretty sure it works fine with 85ms. IIRC I used E-Clock syncing to busy-wait.
It does definitely not work with a whole lot of stuff that assumes instant reaction like A500 keyboards.
NorthWay is offline  
Old 02 August 2021, 11:13   #17
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Out of curiosity I checked handshake time on kickstarts (rough values because only by vertical beam position between write, but enough for an estimation).

KS1.x - 480us
KS3.x - 400us

Of course you should check the code to have the actual values and not influenced by the multitasking system or the processor speed (bare 68k used).

Surprisingly (KS3.1 code):
Code:
00FBA7B4 0039 0040 00bf ee01      OR.B #$40,$00bfee01
00FBA7BC 41ee 0114                LEA.L (A6,$0114) == $00008868,A0
00FBA7C0 2f0e                     MOVE.L A6,-(A7) [00008754]
00FBA7C2 2c6e 0108                MOVEA.L (A6,$0108) == $0000885c [000081f4],A6
00FBA7C6 4eae ffc4                JSR (A6,-$003c) == $00008718
00FBA7CA 2c5f                     MOVEA.L (A7)+ [00fba7ea],A6
00FBA7CC 7036                     MOVEQ #$36,D0     <----------
00FBA7CE d1ae 0118                ADD.L D0,(A6,$0118) == $0000886c [001e6fc7]
00FBA7D2 6404                     BCC.B #$04 == $00fba7d8 (T)
00FBA7D4 52ae 0114                ADDQ.L #$01,(A6,$0114) == $00008868 [00000000]
00FBA7D8 4e75                     RTS
This basically setup a 'delayed check' (so fortunately it is not a pointless wait) based on E clock ticks, and the value used is #$36! -> 1/709309*54=76us! (with PAL crystal, ~75 on NTSC)
Even if the OS coders intended to use a shorter handshake, the management routine is so slow that in any case even Cherry keyboards have never had functional problems just for that reason .

This mean that:
- on VERY fast processor you can have a handshake of ~76us (on KS3.x, I've not checked the code on previous versions)
- on A2000 with Cherry keyboard everything works without problems because the processor is slow
ross is offline  
Old 02 August 2021, 17:54   #18
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by ross View Post
This mean that:
- on VERY fast processor you can have a handshake of ~76us (on KS3.x, I've not checked the code on previous versions)
- on A2000 with Cherry keyboard everything works without problems because the processor is slow
So if you install a fast cpu (possibly with rom in fastram) in an A2000, the keyboard no longer works? I doubt it..
hooverphonique is offline  
Old 02 August 2021, 19:33   #19
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by hooverphonique View Post
So if you install a fast cpu (possibly with rom in fastram) in an A2000, the keyboard no longer works? I doubt it..
You missed a step: "some Cherry keyboards".

And yes, if these keyboards really exist (and only if!, I can only know from hearsay, and also from that code in NetBSD) and if you find a fast enough setup for these A2000s, then yes.
Try disassembling the KS3.1 ROM to make sure, maybe that code appeared just for me

Probably such a configuration never existed and the problem never arose.
ross is offline  
Old 03 August 2021, 09:57   #20
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by ross View Post
Probably such a configuration never existed and the problem never arose.
That could be the case, of course
hooverphonique 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
Amiga and multiple IRQs at the same time. ross Coders. Asm / Hardware 14 15 May 2019 17:31
WANTED: Mitsumi/Amiga Keyboard for parts to mod A1200 keyboard! ProdigalAmigan MarketPlace 13 09 July 2017 02:08
Keyboard Problem with AOS 4.1 FE Classic in WinUAE.. Keyboard doesn't work! QBit support.WinUAE 1 07 January 2015 13:43
Wanted: Amiga 600 keyboard membrane (Blue) or full keyboard assembly RetromanIE MarketPlace 8 19 August 2012 14:48
IRQs Big-Byte support.Hardware 5 01 June 2002 20:42

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 23:34.

Top

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