Re: A92: Thanks David


[Prev][Next][Index][Thread]

Re: A92: Thanks David





Kevin Rees schrieb:
> 
> I tried your idea of disabling the interrupts before reading the keypresses.
>   It works perfectly.  Thanks for the help.  Also, At one point I tried to
> create a custom interrupt for handling the keypresses (so it would all be
> done automatically)  but it failed.  I couldn't get the old interrupt out
> and the new one in.  It kept crashing and stuff.  Maybe you have something
> that could help me here.  

Maybe something is wrong with your interrupt redirection code. If you
could
post that specific code sequence I could propably tell what's wrong.
(I'm sure
that it is possible)

> If anyone has any ideas to help please send them.
> 
> Thanks
> 
> Kebes
> 
> >From: David Kühling <dkuehlin@hell1og.be.schule.de>
> >Reply-To: assembly-92@lists.ticalc.org
> >To: assembly-92@lists.ticalc.org
> >Subject: Re: A92: Hi, I have a question too.
> >Date: Fri, 05 Nov 1999 13:22:12 +0100
> >
> >
> >Hallo!
> >
> >I think I know, what caused the problem: When a key is pressed, one of
> >the Auto-Ints is triggered periodically 300 times per second. This
> >interrupt is in use by the TIOS and checks all the keyboard matrix for
> >keypresses (I'm not sure, maybe that auto-interrupt only sets a flag,
> >and the 300Hz timer interrupt (another Auto-Int) will do the keyboard
> >read). The problem is just, that this keyboard interrupt changes the
> >keyboard matrix, which keeps you from reading correctly. So you should
> >switch off interrupts before reading.
> >You should also consider to use a little longer delay for reading, since
> >the required time differs from calculator to calculator and depends
> >on the battery power etc. (I figured out that 3 times 'move.l (a7),
> >(a7)'
> >is sufficient).
> >
> >Hope this helped.
> >                                                       David Kühling
> >
> >Kevin Rees schrieb:
> > >
> > > 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


References: