|
|
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 <stdio.h> ! 11: #include <assert.h> ! 12: ! 13: #include "config.h" ! 14: #include "amiga.h" ! 15: #include "options.h" ! 16: #include "keybuf.h" ! 17: ! 18: static int kpb_first, kpb_last; ! 19: ! 20: static int keybuf[256]; ! 21: ! 22: bool keys_available (void) ! 23: { ! 24: return kpb_first != kpb_last; ! 25: } ! 26: ! 27: int get_next_key (void) ! 28: { ! 29: int key; ! 30: ! 31: assert (kpb_first != kpb_last); ! 32: ! 33: key = keybuf[kpb_last]; ! 34: if (++kpb_last == 256) ! 35: kpb_last = 0; ! 36: return key; ! 37: } ! 38: ! 39: void record_key (int kc) ! 40: { ! 41: int kpb_next = kpb_first + 1; ! 42: ! 43: if (kpb_next == 256) ! 44: kpb_next = 0; ! 45: if (kpb_next == kpb_last) { ! 46: fprintf(stderr, "Keyboard buffer overrun. Congratulations.\n"); ! 47: return; ! 48: } ! 49: keybuf[kpb_first] = kc; ! 50: kpb_first = kpb_next; ! 51: } ! 52: ! 53: void keybuf_init (void) ! 54: { ! 55: kpb_first = kpb_last = 0; ! 56: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.