English Amiga Board


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

 
 
Thread Tools
Old 14 January 2023, 16:02   #1
geldo79
Registered User
 
geldo79's Avatar
 
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
keyboard reset

Hi,


i have the possibility in my game to pause it by pressing p using the following code:


Check_key:


move.b $bfec01,d0

not.b d0

ror.b #1,d0

cmp.b #$19,d0

.
.
.
bset #6,bfee01

rts



In my main loop, i use



bclr #6,$bfee01


for the handshake. Everything works fine. But there is one problem. When the game ends and i get back to the title screen, i can press p, and when i start a new game, it starts in pause mode. Think its because $bfec01 is also written to in my title screen. Is there a possibility to reset $bfec01 when my game starts, so that it does not recognize a key press during the title screen?


Greetings
Christian

Last edited by geldo79; 14 January 2023 at 16:13.
geldo79 is offline  
Old 14 January 2023, 20:30   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
More information needed.

Switching the SP back to input by clearing bit 6 of CIA-A CRA ends the handshake. But I see nothing which initiates the handshake and waits long enough.

Usually you want to handle your key presses via an interrupt handler. If you neither took over the system nor registered a proper interrupt handler with AmigaOS there will be more complications, because the OS keyboard handler may be still active.
phx is offline  
Old 16 January 2023, 21:21   #3
geldo79
Registered User
 
geldo79's Avatar
 
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
I extracted the relevant parts. This is what it looks like.

Code:
        jsr	-$78(a6)		   ; close Workbench
	jsr	-$132(a6)		   ; Disable Multitasking
        .
        .
        .

main_loop:

        move.l        $dff004,d0
        and.l         #$1ff00,d0
        cmp.l         #240<<8,d0
        bne.w         main_loop
        bsr.w         Check_Key
        .
        .
        .
        Here all the calculations for the frame
        .
        .
        .
	
GamePause:

	cmpi.w        #0,PauseGame
	beq.w         noGamePause
	bclr          #6,$bfee01
	
VSync_pause:

	cmpi.b        #$ff,$dff006
	bne.w         VSync_pause
	bsr.w         Check_Key
	bra           GamePause	

noGamePause:
	
	bclr          #6,$bfee01
	bra           main_loop
	
******************************
	
Check_Key:

	move.b        $bfec01,d0      
	not.b         d0
	ror.b         #1,d0          
	cmp.b         #$19,d0         
	beq           PKeyPress
	bra           keyreset
	
PKeyPress:
	
	cmpi.w        #0,ppressed
	bgt.w         Check_Key_End
	cmpi.w        #0,PauseGame
	bgt.w         PKeyPress_Reset
	move.w        #1,PauseGame
	move.w        #1,ppressed
	bra            Check_Key_End
	
PKeyPress_Reset:
	
	move.w        #0,PauseGame
	move.w        #1,ppressed
	bra           Check_Key_End
	
keyreset:
	move.w        #0,ppressed

Check_Key_End:

	bset          #6,$bfee01
	rts
	
**********************************

PauseGame:
	dc.w    0
	
ppressed:
	dc.w    0

Last edited by geldo79; 16 January 2023 at 22:28.
geldo79 is offline  
Old 16 January 2023, 21:37   #4
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
Forbid() is -132 (decimal), -$132 is SetSignal().

OK, looking at the code.. Handshake is not done properly. You start a handshake (bset #6) at the end of Check_key, and then immediately finish it (bclr #6) without waiting.

Last edited by a/b; 16 January 2023 at 21:50.
a/b is offline  
Old 16 January 2023, 22:26   #5
geldo79
Registered User
 
geldo79's Avatar
 
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
Quote:
Originally Posted by a/b View Post
Forbid() is -132 (decimal), -$132 is SetSignal().

Aahhh! I never disabled multitasking?!



Quote:
Originally Posted by a/b View Post
OK, looking at the code.. Handshake is not done properly. You start a handshake (bset #6) at the end of Check_key, and then immediately finish it (bclr #6) without waiting.

Ok....but there's a lot of code in between, that is not shown here. Maybe this does the waiting. I Edited the code above. In fact it works.
geldo79 is offline  
Old 16 January 2023, 22:59   #6
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
Well, a 68040/060 can eat a lot of code for breakfast ;p. Let me check, so i don't mix up CIA timer value and actual time... HRM says at least 85 microsec. For comparison, one rasterline in PAL mode is approx. 64 microsec.
But if you have a lot of stuff in between, yeah then it should work.

While we are at it, consider using sf (set false) and st (set true) instead of move #0/1, and then tst.b instead of cmp #0/1 if you only need a true/false flag.
a/b is offline  
Old 17 January 2023, 01:14   #7
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Forbid() does not disable interrupts. Which means the input.device interrupt-handler for the keyboard is still running in parallel to your code.

Also, the handshaking is still wrong.
After reading the keycode from the CIA-A serial port you should initiate handshaking by driving the SP as output (set bit 6 of CRA), then after 85us back to input (clear bit 6 of CRA).

Probably your keyboard code only works (most of the time, when typing slowly) because the OS interrupt handler is still running and does the handshaking for you. You only read the last state of the SDR.

Solution: Take over the system or use the OS.
phx is offline  
Old 17 January 2023, 03:11   #8
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
-$78(a6) = -120(a6) is Disable(), so that part is covered but the comment is 'slightly' deceiving :P.
Looking at the edited code, phx is right. Once you pause (go to the VSync_pause branch), you call Check_Key and then immediately loop back to GamePause, which does bclr #6 without a delay (because now there's no all the extra stuff you normally do that would delay it).
a/b is offline  
Old 17 January 2023, 10:55   #9
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by a/b View Post
-$78(a6) = -120(a6) is Disable(), so that part is covered but the comment is 'slightly' deceiving :P.
Indeed, you may be right! I am not that familiar with LVOs in hexadecimal notation.
But then the wrong Forbid() shouldn't matter.

It's also hard to determine actual key-presses without checking for interrupts. If you don't want to establish a keyboard interrupt handler, then I would at least check bit 3 of the ICR whether an SP-interrupt happened (indicating a new key code transmitted by the keyboard). Only then read the SDR and do the handshaking.
phx is offline  
Old 17 January 2023, 17:29   #10
geldo79
Registered User
 
geldo79's Avatar
 
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
Ok. But to get back to the main issue (the Keyboard reading works in my main loop...maybe i can make it better anyway). But as i wrote above, when i leave the main loop at the end of a game and get back to the title screen (which is another loop where i do not explicitly read the Keyboard), press then "p" anyway, and start a new game afterwards, it immediately jumps into the pause loop. Thus, the key reading is being executed in my title loop, and leads to the game pause when started. Any ideas how to prevent the key reading in the title loop?
geldo79 is offline  
Old 17 January 2023, 18:01   #11
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
Then you should flush any buffered keystrokes (basically, keep reading as long as you're getting keycodes from the keyboard and discard them) before starting to accept new ones.
a/b is offline  
Old 17 January 2023, 19:32   #12
geldo79
Registered User
 
geldo79's Avatar
 
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
But how can i discard them? I thought $bfec01 keeps the last pressed key. Seems that i can not reset it.
geldo79 is offline  
Old 17 January 2023, 19:39   #13
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,098
Quote:
Originally Posted by geldo79 View Post
But how can i discard them? I thought $bfec01 keeps the last pressed key. Seems that i can not reset it.
Really, you should implement better keyboard handling like already suggested. But as a quickish fix just read the keyboard on the title screen (ignoring the result) and clear the pause related flags before starting.


The CIA SDR register where you're reading the key from isn't an instantaneous value representing what key is currently pressed, but rather a buffer of the last key event (both up and down). If you don't process a key event it'll stay there.
paraj is offline  
Old 17 January 2023, 23:42   #14
geldo79
Registered User
 
geldo79's Avatar
 
Join Date: Oct 2019
Location: Eydelstedt / Germany
Age: 44
Posts: 114
That works. I just call Check_key in my title screen loop now, and reset the pause flags when starting a new game. Thanks a lot.
geldo79 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
Keyboard wait, register reset? TCH Coders. Asm / Hardware 39 29 July 2021 08:41
Kipper CD32 riser keyboard reset? lord of time support.Hardware 0 31 August 2019 16:21
A1200 can't reset from Ctrl+A+A, keyboard problem? MrD support.Hardware 7 28 October 2016 17:16
Keyboard reset warning support broke in 2.4.0 beta 21 mark_k support.WinUAE 2 17 April 2012 15:32
A500 keyboard, reset problem orange support.Hardware 10 04 November 2010 19:51

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

Top

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