|
|
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:
1.1.1.2 ! root 10: #include "sysconfig.h"
! 11: #include "sysdeps.h"
1.1 root 12: #include <assert.h>
13:
14: #include "config.h"
15: #include "options.h"
16: #include "keybuf.h"
1.1.1.2 ! root 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: }
1.1 root 35:
36: static int kpb_first, kpb_last;
37:
38: static int keybuf[256];
39:
1.1.1.2 ! root 40: int keys_available (void)
1.1 root 41: {
42: return kpb_first != kpb_last;
43: }
44:
45: int get_next_key (void)
46: {
47: int key;
48:
49: assert (kpb_first != kpb_last);
50:
51: key = keybuf[kpb_last];
52: if (++kpb_last == 256)
53: kpb_last = 0;
54: return key;
55: }
56:
57: void record_key (int kc)
58: {
59: int kpb_next = kpb_first + 1;
60:
61: if (kpb_next == 256)
62: kpb_next = 0;
63: if (kpb_next == kpb_last) {
64: fprintf(stderr, "Keyboard buffer overrun. Congratulations.\n");
65: return;
66: }
1.1.1.2 ! root 67: if (fake_joystick) {
! 68: switch (kc >> 1) {
! 69: case AK_NP8: fakestate[0] = !(kc & 1); return;
! 70: case AK_NP4: fakestate[1] = !(kc & 1); return;
! 71: case AK_NP6: fakestate[2] = !(kc & 1); return;
! 72: case AK_NP2: fakestate[3] = !(kc & 1); return;
! 73: case AK_NP0: case AK_NP5: fakestate[4] = !(kc & 1); return;
! 74: }
! 75: }
1.1 root 76: keybuf[kpb_first] = kc;
77: kpb_first = kpb_next;
78: }
79:
80: void keybuf_init (void)
81: {
82: kpb_first = kpb_last = 0;
83: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.