Annotation of uae/src/keybuf.c, revision 1.1

1.1     ! root        1:  /* 
        !             2:   * UAE - The Un*x Amiga Emulator
        !             3:   * 
        !             4:   * Keyboard buffer. Not really needed for X, but for SVGAlib and possibly
        !             5:   * Mac and DOS ports.
        !             6:   * 
        !             7:   * (c) 1995 Bernd Schmidt
        !             8:   */
        !             9: 
        !            10: #include "sysconfig.h"
        !            11: #include "sysdeps.h"
        !            12: #include <assert.h>
        !            13: 
        !            14: #include "config.h"
        !            15: #include "options.h"
        !            16: #include "keybuf.h"
        !            17: #include "keyboard.h"
        !            18: #include "os.h"
        !            19: 
        !            20: /* This is cryptic, but hey, it works! */
        !            21: int fakestate[5] = { 0, 0, 0, 0, 0 };
        !            22: 
        !            23: void getjoystate(UWORD *st, int *button)
        !            24: {
        !            25:     if (fake_joystick) {
        !            26:        int top = fakestate[0];
        !            27:        int bot = fakestate[3];
        !            28:        if (fakestate[1]) top = !top;
        !            29:        if (fakestate[2]) bot = !bot;
        !            30:        *st = bot | (fakestate[2] << 1) | (top << 8) | (fakestate[1] << 9);
        !            31:        *button = fakestate[4];
        !            32:     } else
        !            33:        read_joystick(st, button);
        !            34: }
        !            35: 
        !            36: /* Not static so the DOS code can mess with them */
        !            37: int kpb_first, kpb_last;
        !            38: 
        !            39: static int keybuf[256];
        !            40: 
        !            41: int keys_available (void)
        !            42: {
        !            43:     return kpb_first != kpb_last;
        !            44: }
        !            45: 
        !            46: int get_next_key (void)
        !            47: {
        !            48:     int key;
        !            49:     
        !            50:     assert (kpb_first != kpb_last);
        !            51:     
        !            52:     key = keybuf[kpb_last];
        !            53:     if (++kpb_last == 256) 
        !            54:        kpb_last = 0;
        !            55:     return key;    
        !            56: }
        !            57: 
        !            58: void record_key (int kc)
        !            59: {
        !            60:     int kpb_next = kpb_first + 1;
        !            61: 
        !            62:     if (kpb_next == 256)
        !            63:        kpb_next = 0;
        !            64:     if (kpb_next == kpb_last) {
        !            65:        fprintf(stderr, "Keyboard buffer overrun. Congratulations.\n");
        !            66:        return;
        !            67:     }
        !            68:     if (fake_joystick) {
        !            69:        switch (kc >> 1) {
        !            70:         case AK_NP8: fakestate[0] = !(kc & 1); return;
        !            71:         case AK_NP4: fakestate[1] = !(kc & 1); return;
        !            72:         case AK_NP6: fakestate[2] = !(kc & 1); return;
        !            73:         case AK_NP2: fakestate[3] = !(kc & 1); return;
        !            74:         case AK_NP0: case AK_NP5: fakestate[4] = !(kc & 1); return;
        !            75:        }
        !            76:     }
        !            77:     keybuf[kpb_first] = kc;
        !            78:     kpb_first = kpb_next;
        !            79: }
        !            80: 
        !            81: void keybuf_init (void)
        !            82: {
        !            83:     kpb_first = kpb_last = 0;
        !            84: }

unix.superglobalmegacorp.com

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