Annotation of hatari/tests/keymap/keytest.c, revision 1.1

1.1     ! root        1: /* ------------------------------------
        !             2:  * Program to show what keycodes evnt_multi & co.
        !             3:  * return...
        !             4:  */
        !             5: 
        !             6: #ifdef __AHCC__
        !             7: # include <aes.h>
        !             8: # include <tos.h>
        !             9: #else
        !            10: # ifdef __SOZOBONX__
        !            11: #  include <minimum.h>
        !            12: #  include <osbind.h>
        !            13: #  include <xgemfast.h>
        !            14: # endif
        !            15: #endif
        !            16: #include <stdlib.h>
        !            17: #include <stdio.h>
        !            18: 
        !            19: #ifndef FALSE
        !            20: #define FALSE 0
        !            21: #define TRUE  !FALSE
        !            22: #endif
        !            23: 
        !            24: /* resource set indices for KEYTEST */
        !            25: #define TREEMENU   0 /* menu */
        !            26: #define MENUINFO   7 /* STRING in tree TREE001 */
        !            27: #define MENUTABL  16 /* STRING in tree TREE001 */
        !            28: #define MENUQUIT  18 /* STRING in tree TREE001 */
        !            29: 
        !            30: #define MY_MU (MU_MESAG | MU_KEYBD)
        !            31: 
        !            32: OBJECT *tree_menu;
        !            33: 
        !            34: /* ------------------------------------
        !            35:  * Function prototypes.
        !            36:  */
        !            37: static void prg_init (void);
        !            38: static void prg_exit (void);
        !            39: static void msg_handler (short *msgbuf);
        !            40: static void do_menu (short entry);
        !            41: static void ascii_table (void);
        !            42: static void show_key (short key, short state);
        !            43: 
        !            44: /* ------------------------------------
        !            45:  * Standard GEM handling functions (main loop).
        !            46:  */
        !            47: 
        !            48: int main()
        !            49: {
        !            50:        short  mbuf[8];
        !            51:        short  evnt_m, m1fl, pmx1, pmy1, pm1w, pm1h,
        !            52:               m2fl, pmx2, pmy2, pm2w, pm2h, pmx, pmy, pmstate,
        !            53:               state, key, clicks, tlo_cnt, thi_cnt;
        !            54:        m1fl = pmx1 = pmy1 = pm1w = pm1h = 0;
        !            55:        m2fl = pmx2 = pmy2 = pm2w = pm2h = 0;
        !            56:        tlo_cnt = thi_cnt = 0;
        !            57: 
        !            58:        prg_init ();
        !            59:        graf_mouse(0, ARROW);
        !            60:        while (TRUE) {
        !            61:                /* mouse button, mouse co-ordinate 1,
        !            62:                 * mouse co-ordinate 2, message and timer events.
        !            63:                 * mouse co-ordinate, mouse button, special key and normal key states.
        !            64:                 * number of mouse clicks.
        !            65:                 */
        !            66:                evnt_m = evnt_multi(MY_MU, 259, 3, 0, m1fl, pmx1, pmy1, pm1w, pm1h,
        !            67:                                    m2fl, pmx2, pmy2, pm2w, pm2h, mbuf, tlo_cnt, thi_cnt,
        !            68:                                    &pmx, &pmy, &pmstate ,&state, &key, &clicks);
        !            69: 
        !            70:                if (evnt_m & MU_MESAG)
        !            71:                        msg_handler (mbuf);
        !            72: 
        !            73:                if (evnt_m & MU_KEYBD)
        !            74:                        show_key (key, state);
        !            75:        }
        !            76:        return 0;
        !            77: }
        !            78: 
        !            79: /* ------------------------------------
        !            80:  * GEM startup.
        !            81:  */
        !            82: static void prg_init (void)
        !            83: {
        !            84:        appl_init ();
        !            85: 
        !            86:        if (!rsrc_load ("keytest.rsc")) {
        !            87:                appl_exit ();
        !            88:                exit (1);
        !            89:        }
        !            90: 
        !            91:        /* TREEMENU should be defines, generated by the rsc editor */
        !            92:        rsrc_gaddr (R_TREE, TREEMENU, &tree_menu);
        !            93:        menu_bar (tree_menu, TRUE);             /* show menubar */
        !            94: }
        !            95: 
        !            96: /* GEM exit. */
        !            97: static void prg_exit (void)
        !            98: {
        !            99:        menu_bar (tree_menu, FALSE);
        !           100:        rsrc_free ();
        !           101:        appl_exit ();
        !           102:        exit (0);
        !           103: }
        !           104: 
        !           105: /* message handling code. */
        !           106: static void msg_handler (short *msgbuf)
        !           107: {
        !           108:        switch (msgbuf[0]) {
        !           109:        case MN_SELECTED:
        !           110:                /* handle menu entry */
        !           111:                do_menu (msgbuf[4]);
        !           112:                /* de-invert menu title */
        !           113:                menu_tnormal (tree_menu, msgbuf[3], 1);
        !           114:                break;
        !           115:        }
        !           116: }
        !           117: 
        !           118: /* ------------------------------------
        !           119:  * Selection handling functions.
        !           120:  */
        !           121: static void do_menu (short entry)
        !           122: {
        !           123:        switch (entry) {
        !           124:        case MENUINFO:
        !           125:                form_alert (1, "[1][|Show keycodes and status|  of shift/alt/ctrl as|returned by evnt_multi()][ OK ]");
        !           126:                break;
        !           127: 
        !           128:        case MENUTABL:
        !           129:                ascii_table ();
        !           130:                break;
        !           131:                
        !           132:        case MENUQUIT:
        !           133:                prg_exit ();
        !           134:        }
        !           135: }
        !           136: 
        !           137: static void ascii_table (void)
        !           138: {
        !           139:        int x, y;
        !           140:        Cconws ("\33Y#  . | 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f \15\12");
        !           141:        Cconws ("----------------------------------------------------\15\12");
        !           142: 
        !           143:        for (y = 2; y < 16; y ++) {
        !           144:                Cconout(' ');
        !           145:                Cconout('0' + y);
        !           146:                Cconout(' ');
        !           147:                Cconout('|');
        !           148:                
        !           149:                for (x = 0; x < 16; x ++) {
        !           150:                        Cconout(' ');
        !           151:                        Cconout(x + y * 0x10);
        !           152:                        Cconout(' ');
        !           153:                }
        !           154:                Cconws("\15\12");
        !           155:        }
        !           156: }
        !           157: 
        !           158: void show_key (short key, short state)
        !           159: {
        !           160:        char  buf[128];
        !           161: 
        !           162:        sprintf (buf, "[1][Mod state:  $%02x (%d)|Scan code:  $%02x (%d)|ASCII code: $%02x (%d)][ OK ]",
        !           163:                 state, state, key>>8, key>>8, key&0xff, key&0xff);
        !           164:        form_alert (1, buf);
        !           165: 
        !           166:        if ((key & 0xFF) == 27)
        !           167:                prg_exit ();
        !           168: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.