News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Arnaud

How detect if keyboard is AZERTY or QWERTY (CPCTelera)

Started by Arnaud, 17:26, 02 August 17

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Arnaud

Hello,
i'm coding the entry of name in high score and i encounter a little problem.

When i type letter under emulator all works well, but when i test on my real Amstrad in AZERTY the 'A' entered became 'Q'  :doh:

How can i detect if my keyboard is AZERTY or QWERTY ?

Thanks.

SRS

Let the User type "A" before game starts so you know the  code ?

Like "Start Game ... Press A" ?

Nich

Quote from: Arnaud on 17:26, 02 August 17
How can i detect if my keyboard is AZERTY or QWERTY ?

I have never used CPCTelera, but here is some Z80 code I wrote years ago to test for the presence of an AZERTY keyboard. Firstly, it determines where the table is located, then it checks the keyboard translation table that is stored in the lower ROM and gets the character that corresponds to key 67. If it's 'a', then it assumes that an AZERTY keyboard is being used. :) You'll need to change the line "call z,setaze" appropriately.

This routine must not be located underneath the lower ROM (i.e. between 0-&3FFF).

; Detect if an AZERTY keyboard is being used, by examining the lower ROM.
; First, it is necessary to determine the address of the key character table,
; as it is located at different addresses in the lower ROM depending on the
; machine type being used.

       di                  ; disable interrupts, otherwise interrupt routine
                           ; in lower ROM may be called.
       ld bc,&7f89         ; use MODE 1 for graphics and enable lower ROM.
       out (c),c
       
       ld hl,&1d69         ; key character table starts at &1d69 on a CPC464.
       ld a,(hl)           ; get byte at this address.
       cp &f0              ; first key in table should be character &f0.
       jr z,azert0         ; we're using a CPC464 - go to keyboard detection
                           ; routine.
       ld hl,&1eef         ; table starts at &1eef on all other CPCs.

azert0 ld de,67            ; set address of key 67.
       add hl,de
       ld a,(hl)           ; get character for this key.
       cp 'a'              ; is an AZERTY keyboard being used?
       call z,setaze       ; yes.
       ld bc,&7f8d
       out (c),c           ; disable lower ROM.

Arnaud

Thanks, it works.

I modified the code a little, it returns directly the letter associated to 'q'.

The test is in the C part : if letter == 'q' then QWERTY else AZERTY

Here the code for CPCTelera:


C binding :
extern u8 IsAzerty();

isAzerty.s
; Code from Nich : http://www.cpcwiki.eu/forum/programming/how-know-the-keyboard-layout-(cpctelera)/
; Modified and adapted for CPCTelera by Arnaud
; Detect if an AZERTY keyboard is being used, by examining the lower ROM.
; First, it is necessary to determine the address of the key character table,
; as it is located at different addresses in the lower ROM depending on the
; machine type being used.

_IsAzerty::
        di                    ; disable interrupts, otherwise interrupt routine in lower ROM may be called.               
        ld bc, #0x7f89        ; use MODE 1 for graphics and enable lower ROM.
        out(c), c
        ld hl, #0x1d69        ; key character table starts at &1d69 on a CPC464.
        ld a, (hl)            ; get byte at this address.
        cp #0xf0            ; first key in table should be character &f0.
        jr z, azert0        ; we are using a CPC464 - go to keyboard detection routine.               
        ld hl, #0x1eef        ; table starts at &1eef on all other CPCs.

    azert0:
        ld de, #67            ; set address of key 67.
        add hl, de             
        ld a, (hl)            ; get character for this key.
        ld l, a                ; return character
        ld bc, #0x7f8d       
        out(c), c            ; disable lower ROM.
        ei                     ; enable interrupts
        ret

ZbyniuR

10 IF PEEK(&BB5B)=0 THEN c=46008 ELSE c=46338
20 v=PEEK(c):IF v=37 THEN n$="French"ELSE IF v=43 THEN n$="English"ELSE IF v=58 THEN n$="Spanish"ELSE IF v=92 THEN n$="Danish"ELSE n$="gibberish" ' ;)
30  IF INP(&F500)=90 THEN n$="German" ' Schneider with English keyboard
40 PRINT"I'm guessing your CPC is "n$".

That all you need to know about it. :)
In STARS, TREK is better than WARS.

Powered by SMFPacks Menu Editor Mod