English Amiga Board


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

 
 
Thread Tools
Old 01 September 2022, 12:52   #1
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 209
Keyboard Problems

Hello!

I'll try to keep it simple. I'm attempting to use "keyboard.device" to get keyboard input, and it seems like it's working. However, I wouldn't be here if it was.

Here are the relevant snippets from my code:
Initializing keyboard device:
Code:
Call	CreateMsgPort		; Create a message port
	move.l	D0,KeyboardPort		; Save the message port's pointer in "KeyboardPort"
	move.l	D0,A0			; copy it to A0 aswell
	move.l	#IOSTD_SIZE,D0		; Read the size of the "IOSTD" structure into D0
	Call	CreateIORequest		; Create an I/O request (message)
	move.l	D0,KeyboardMessage	; Save the request's pointer in "KeyboardMessage"
	lea	KeyboardName,A0
	move.l	D0,A1
	clr.l	D0
	clr.l	D1
	Call	OpenDevice
	tst.l	D0
	bne	KeyboardError
	move.l	KeyboardMessage,A0
	move.l	KBD_READMATRIX,IO_COMMAND(A0)
	move.l	#13,IO_LENGTH(A0)
	move.l	MemSpace,A1
	add.l	#80,A1
	move.l	A1,IO_DATA(A0)
Waiting for a certain key to be pressed:
Code:
	move.l	KeyboardMessage,A1
	move.l	#5,A0
	lea	IO_DATA(A1,A0),A0
WLoop	Call	DoIO ; 4th bit of byte 5
	move.l	(A0),D0
	btst	D0,4
	beq	WLoop
The assembler nor the (emulated) Amiga throw any errors. It just doesn't work.

When I paused the code execution without pressing any keys, it was going through the loop just fine.
However, if I pressed a random key and then paused, it was looping the first command in the program.
If I pressed the key it's listening for (enter), I couldn't pause the program and the Amiga froze.

I can program well, but the lack of good documentation for this is infuriating.
Steam Ranger is offline  
Old 01 September 2022, 13:11   #2
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,087
Code:
;	move.l	KBD_READMATRIX,IO_COMMAND(A0)
 move.l	#KBD_READMATRIX,IO_COMMAND(A0)
Code:
WLoop
 move.l	a0,-(a7)
	Call	DoIO ; 4th bit of byte 5
 move.l	(a7)+,a0
	move.l	(a0),d0
;	btst	D0,4
 btst	#4,D0	; maybe? not sure what you are trying to do since you say byte *5*

Last edited by a/b; 01 September 2022 at 13:16.
a/b is offline  
Old 02 September 2022, 15:34   #3
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,569
Quote:
Originally Posted by Steam Ranger View Post
Code:
    move.l    KBD_READMATRIX,IO_COMMAND(A0)
IO_COMMAND
is a word. And, as a/b already pointed out, you want to write the constant KBD_READMATRIX to it (immediate addressing mode):
Code:
        move.w  #KBD_READMATRIX,IO_COMMAND(A0)
Quote:
Code:
    move.l    KeyboardMessage,A1
    move.l    #5,A0
    lea    IO_DATA(A1,A0),A0
WLoop    Call    DoIO ; 4th bit of byte 5
    move.l    (A0),D0
    btst    D0,4
     beq    WLoop
This is not good. At all.
  1. A0, like D0, D1 and A1, are scratch registers when calling OS functions. So the contents of A0 is trashed after calling DoIO.
  2. IO_DATA
    hopefully still has the pointer to your keyboard matrix, but you don't read the pointer but calculate an offset on the location of that pointer within the IO-Request structure using LEA.
  3. Even if A0 would not be trashed after DoIO, you access an illegal memory location definitely not part of the kbd-matrix, which is guaranteed to crash 68000 and 68010 systems (odd address).
  4. As a/b already noted,
    btst d0,4
    is definitely wrong, as it tests the bit specified in D0 (modulo 8) at the absolute memory address 4.
Assuming the IO-Request is correctly set up in
KeyboardMessage
and you really want to check the 4th bit from the 5th byte of the matrix (which means keycode 44) you may try this:
Code:
        move.l  KeyboardMessage,a2
WLoop   move.l  a2,a1
        Call    DoIO
        move.l  IO_DATA(a2),a0
        btst    #4,5(a0)
        beq     WLoop
phx is offline  
Old 03 September 2022, 11:05   #4
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 209
Thanks! I don't often use libraries in the software I make, so I just forget all the things they do, apart from the inputs/outputs.
Steam Ranger 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 problems dlsa support.Hardware 4 05 April 2021 10:28
WHDLoad and Keyboard Problems Ebster project.WHDLoad 4 19 January 2010 18:32
Keyboard problems Feltzkrone New to Emulation or Amiga scene 0 31 May 2004 18:05
keyboard problems webwurm support.WinUAE 1 27 July 2003 07:57
Problems with the Keyboard Unregistered support.WinUAE 0 14 August 2002 11:18

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 16:57.

Top

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