A92: Hi, again
[Prev][Next][Index][Thread]
A92: Hi, again
I have done more research on my little problem (see below, or see my last
e-mail). I found that it is not every 2nd time that the port is read
incorrectly. It seems to be much more rare than that (but frequent enough
to cause a problem). This is obvious if we just consider the partial
solution I found of reading the port twice in a row. Since it is prforming
a logical AND on the results of the 2 reads, it would require that 2
subsequent reads would be the same in order for the function to return a 1.
This is happening. This makes it safe to assume that the error only occurs
once every 3 reads AT MOST, and probably a lot less than that. However, it
seems impossible (as far as I can tell) to figure out how to know when this
error will occur, or how to prevent it. The way I mentioned of reading the
port twice and comparing them works, but there must be another solution.
The single-read method seemed to work fine for the game "Fernando" (check it
out if you haven't yet, it is really good).
Thanks again.
Kebes
>From: "Kevin Rees" <kebes22@hotmail.com>
>Reply-To: assembly-92@lists.ticalc.org
>To: assembly-92@lists.ticalc.org
>Subject: A92: Hi, I have a question too.
>Date: Fri, 05 Nov 1999 01:35:28 MST
>
>
>I am learning assembly for the 68K. I have been working on writing a
>library for reading keypresses. It is capable of checking a specified key
>to see if it is held down or not. It returns 1 if the key is held down,
>and
>0 if not. I am accomplishing this by writing the row mask of the key to be
>checked to [600018].w pausing briefly (using about 6 NOP instructions) and
>then reading [60001B].b and checking the bit coresponding to the column of
>the key being read. (see LowLevel.txt) I used the same format as is used
>by
>"Fernando3" for reading the keys. My program works fine except for one
>little bug. When any key in the same column is pressed (rows 0-6 only) the
>function thinks that the key specified is also pressed. I have been
>working
>on this for 3 days now, and have now gathered more info. It seems that
>once
>out of every 2 times that [600018] is written and then [60001B] is read it
>returns the correct result (a byte containing the state of columns 0-7 in
>the row specified by the mask)
>However every 2nd time the port is written and then read it returns a byte
>coresponding to to a seemingly random row between 0 and 6 (Hence the
>problem
>mentioned earlier). The program that is calling this function is just an
>infinite loop with the key check inside, and a conditional jump out of the
>loop (when the key specified is pressed). it looks something like this:
>
>
>main_loop:
>
> move.l <key code>,d0
> jsr check_key
> tst.b d0
> beq exit
> bra main_loop
>
>exit:
>rts
>
><key code> is a value between 0 and 80 in the format of
>bit 7 6 5 4 3 2 1 0
> X X X X X X X X
> |-----| <- 3 bits (0-7) coresponding to column of key
> |-------| <- 4 bits coresponding to row of key (0-9)
>
>and the check_key function looks something like this
>
>
> movem.l d1-d3,-(a7) ; save registers
>
> move.l d0,d1
> andi.l #7,d1 ; finds column
>
> move.w #$FFFF,d2 ; used for row mask
> lsr.b #3,d0 ; finds row
> bclr.w d0,d2 ; sets row mask
>
> move.w d2,$600018 ; write row mask to I/O
> nop ; \
> nop ; \
> nop ; \ wait for I/O
> nop ; / to recover
> nop ; /
> nop ; /
> move.b $60001B,d3 ; read I/O
> not.b d3 ; invert d3
>
> btst.b d1,d3 ; test column
> beq key_not_pressed
> movem.l (a7)+,d1-d3 ; restore registers
> move.l #1,d0 ; return 1 if key is pressed
> rts
>
>key_not_pressed:
> movem.l (a7)+,d1-d3 ; restore registers
> move.l #0,d0 ; return 0 if key not pressed
> rts
>
>
>It is pretty simple code, yet it is giving me a huge headache. I have
>found
>that by repeating the Write and Read section of the code and then doing a
>logical AND on the 2 results, I can get an accurate read on the key
>specified (hence the conclusion that at least 1 out of 2 reads is accurate)
>but doing so takes extra processor time, and is inconvenient. If any of
>you
>have any ideas on how I can solve this please let me know.
>
>Thanks
>
>Kebes
>
>
>______________________________________________________
>Get Your Private, Free Email at http://www.hotmail.com
>
>
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com