reading the keyboard via asm (Development MSX Fora)MSX Resource Center MSX Info Update - Finnish MSX madness at its best           
            
English Nederlands Español Português Russian         
 Nieuws
   Voorpagina
  Nieuws archief
  Nieuws onderwerpen

 Informatie
   MSX Fora
  Artikelen
  Recensies
  Beursverslagen
  Fotoreportages
  Beurzen en meetings
  Enquêtes
  Links
  Zoek

 Software
   Downloads
  Webshop

 MRC
   Wie we zijn
  Kom bij ons team
  Doneren
  Policies
  Contact met het MRC
  Link naar Ons
  Statistieken

 Zoek
 
  

  

 Login
 

Gebruikersnaam

Wachtwoord




Ben je nog niet lid? Klik hier en word MSX vriend!


 Statistieken
 

Er zijn 121 gasten en 0 MSX vrienden online

Je bent een anonieme bezoeker.
 

MSX Fora


MSX Fora

Development - reading the keyboard via asm

Schrijver

reading the keyboard via asm

wur
msx friend
Berichten: 8
Geplaatst: 07 Juli 2005, 07:04   
Hello,

I've been having problems using the $0141 (eg, the "a <- line #, call $141, a == keys that are being pressed at line #" subroutine) subroutine. I noticed in the following program crashes after reading the keystrokes 4 or 5 times. I thought it might be the interrupt conflicting with my program in some way, but adding "di" didn't seem to help. Does anyone have any insight on this?

BTW, how can I access the keyboard directly, rather than going through the bios?


thanks for your time,

wur

-=============

db $fe
dw start
dw eof
dw exec

org $8800

start:

letter_a: db "You pressed 'a'. ", 0
letter_b: db "You pressed 'b'. ", 0
letter_c: db "You pressed 'c'. ", 0
exit_bye: db "x--Exiting, bye. ", 0

exec:

; disable interrupt

di


main_loop:

; scan line with 'b' / 'a', check for 'b' / 'a'

ld a, 2
call $0141
push af
and a, 10000000b
cp a, 0
jp z, &print_b
pop af
and a, 01000000b
jp z, &print_a



; scan lines with 'c' / 'x', check for 'c', then 'x'

ld a, 3
call $0141
and a, 00000001b
cp a, 0
jp z, &print_c

ld a, 5
call $0141
and a, 00100000b
cp a, 0
jp z, &quit_prog

jp &main_loop


print_a:

ld bc, &letter_a
call &puts

.wait:

; wait until the user lets go of 'a'
ld a, 2
call $0141
push af
and a, 01000000b
cp a, 0
jp z, &.wait

jp &main_loop


print_b:

ld bc, &letter_b
call puts

.wait:

ld a, 2
call $0141
push af
and a, 10000000b
cp a, 0
jp z, &.wait

jp &main_loop


print_c:

ld bc, &letter_c
call puts

.wait:

ld a, 3
call $0141
and a, 00000001b
cp a, 0
jp z, &.wait

jp &main_loop


quit_prog:

ld bc, &exit_bye
call puts
ei
.end: ret


puts:

ld a, (bc)
cp 0
ret z
call $a2
inc bc
jp puts
.end: ret

eof:
ro
msx guru
Berichten: 2320
Geplaatst: 07 Juli 2005, 07:51   
why the DI and EI ?
they don't help your conflict in no way. remove them, only brings more corruption.
Also you do a PUSH AF and after that a JUMP. This will corrupt the stack.
here for example:

Quote:


ld a, 2
call $0141
push af
and a, 10000000b
cp a, 0
jp z, &print_b
pop af
and a, 01000000b
jp z, &print_a


when PUSHING a register you need to POP it, whenever, where ever.
a better solutions would be

ld a, 2
call $0141
bit 7,a ;check for bit 7
jp z, &print_b
bit 6,a ;check for bit 6
jp z, &print_a


another thing:
when using a AND instruction to check value, you don't 'ave to use a CP (the AND already sets flags)
like this:

Quote:


and a, 10000000b
cp a, 0
jp z, &print_b


just use
and 10000000b
jp z,label


norakomi
msx professional
Berichten: 861
Geplaatst: 07 Juli 2005, 11:13   
http://map.tni.nl/articles/keymatrix.php

read this article as well.
easy reading the keyboard like this:

keys: EQU #FBE5

;
;Check whether space is pressed
;
loop
ld a,(keys+8) ;space
bit 0,a
jp nz,loop

...

ret

ro
msx guru
Berichten: 2320
Geplaatst: 07 Juli 2005, 12:13   
the above works only when INTS are on (and the BIOS is used, unless you've got your own matrixscanner on the INT)
NYYRIKKI
msx master
Berichten: 1503
Geplaatst: 07 Juli 2005, 13:30   

Here is BIOS independent version:

;
;Check whether space is pressed
;
in a,(#aa)
and #f0
or 8
out (#aa),a
loop:
in a,(#a9) ;space
rrca
jr c,loop

ro
msx guru
Berichten: 2320
Geplaatst: 07 Juli 2005, 13:36   
which answers wur's queston "BTW, how can I access the keyboard directly, rather than going through the bios?"

 
 







(c) 1994 - 2008 Stichting MSX Resource Center. MSX is een trademark van MSX Licensing Corporation.