O: Programování Amiga C , Amiga Python a rozdíly mezi Amigou a PC v jejich používání
Tu mas upraveny nas keytest na vypis celej matice v dvojkovej sustave:
Tu mas upraveny nas keytest na vypis celej matice v dvojkovej sustave:
Code:
// keytest.c - priklad testu klavesy pre Lisiaka a aj pre inych ktorym to poradi...
// - 29.10.2014 DJM / DTA za podpory Bukasoveho Masivu ;-)
#include <stdio.h>
#include <devices/keyboard.h>
#include <proto/exec.h>
#define BYTETOBINARY(byte) \
(byte & 0x80 ? 1 : 0), \
(byte & 0x40 ? 1 : 0), \
(byte & 0x20 ? 1 : 0), \
(byte & 0x10 ? 1 : 0), \
(byte & 0x08 ? 1 : 0), \
(byte & 0x04 ? 1 : 0), \
(byte & 0x02 ? 1 : 0), \
(byte & 0x01 ? 1 : 0)
// konstanty s raw hodnotami
#define KESC 0x45
#define KA 0x20
#define KB 0x35
// pomocne makro na kontrolu danej klavesy v keyboard matici
#define KEY(x) (KeyboardMatrix[(x)>>3]&(1L<<((x)&7L)))
struct MsgPort *KeyboardMsgPort=NULL;
struct IOStdReq *KeyboardIO=NULL;
UBYTE KeyboardMatrix[16];
int p;
void main()
{
//otvorenie keyboardu
if((KeyboardMsgPort=(struct MsgPort *)CreateMsgPort())==NULL) { printf("chyba\n"); goto Koniec; }
if((KeyboardIO=(struct IOStdReq *)CreateIORequest(KeyboardMsgPort,sizeof(struct IOStdReq)))==NULL) { printf("chyba\n"); goto Koniec; }
if(OpenDevice("keyboard.device",0,(struct IORequest *)KeyboardIO,0)) { printf("chyba\n"); goto Koniec; }
//printf("KeyTest - test klaves A,B a ESC=exit\n");
printf("Vypis keyboard matice v dvojkovej sustave (ESC exit)\n");
printf("Klikni mimo toto output okno, aby si sem nepisal..\n");
// cyklus
engine:
//naplnenie matice a test klaves
KeyboardIO->io_Data = KeyboardMatrix;
KeyboardIO->io_Length = 16;
KeyboardIO->io_Flags = 0;
KeyboardIO->io_Command = KBD_READMATRIX;
DoIO((struct IORequest *)KeyboardIO);
if(CheckIO((struct IORequest *)KeyboardIO)) {
for(p=0;p<16;p++) printf("%1d%1d%1d%1d%1d%1d%1d%1d ",BYTETOBINARY(KeyboardMatrix[p]));
for(p=0;p<9*16;p++) printf("\b");
if(KEY(KESC)) { /*printf("ESC stlacene = exit\n"); */goto Koniec; }
/*if(KEY(KA) && KEY(KB)) printf("A + B stlacene naraz\n");
else {
if(KEY(KA)) printf("A stlacene = staci tento text?\n");
if(KEY(KB)) printf("B stlacene\n");
}*/
}
goto engine;
Koniec:
//zrusenie keyboardu
if(KeyboardIO) { DeleteIORequest((struct IOStdReq *)KeyboardIO); KeyboardIO=NULL; }
if(KeyboardMsgPort) { DeleteMsgPort(KeyboardMsgPort); KeyboardMsgPort=NULL; }
}
.

Komentovat