psx_gpu: change reciprocal table again
[pcsx_rearmed.git] / plugins / dfinput / guncon.c
CommitLineData
4c08b9e7 1/*
2 * (C) GraÅžvydas "notaz" Ignotas, 2011
3 *
4 * This work is licensed under the terms of any of these licenses
5 * (at your option):
6 * - GNU GPL, version 2 or later.
7 * - GNU LGPL, version 2.1 or later.
8 * See the COPYING file in the top-level directory.
9 */
10
11#include <string.h>
12#include "main.h"
13
14static unsigned char buf[8];
15
16unsigned char PADpoll_guncon(unsigned char value)
17{
18 if (CurByte == 0) {
19 CurCmd = value;
20 CurByte++;
21 return 0x63; // regardless of cmd
22 }
23
24 if (CurCmd != 0x42 || CurByte >= 8)
25 return 0xff; // verified
26
27 return buf[CurByte++];
28}
29
30unsigned char PADstartPoll_guncon(int pad)
31{
32 int x, xn = 0, y = 0, in = 0, xres = 256;
33 CurByte = 0;
34
35 buf[2] = buf[3] = 0xff;
36 pl_update_gun(&xn, &xres, &y, &in);
37
38 // while y = const + line counter, what is x?
39 // for 256 mode, hw dumped offsets x, y: 0x5a, 0x20
40 //x = 0x5a + (356 * xn >> 10);
41 x = 0x5a - (xres - 256) / 3 + (((xres - 256) / 3 + 356) * xn >> 10);
42 y = 0x20 + y;
43
44 if (in & GUNIN_TRIGGER)
45 buf[3] &= ~0x20;
46 if (in & GUNIN_BTNA)
47 buf[2] &= ~0x08;
48 if (in & GUNIN_BTNB)
49 buf[3] &= ~0x40;
50 if (in & GUNIN_TRIGGER2) {
51 buf[3] &= ~0x20;
52 x = 1;
53 y = 10;
54 }
55 buf[4] = x;
56 buf[5] = x >> 8;
57 buf[6] = y;
58 buf[7] = y >> 8;
59
60 return 0xff;
61}
62
63void guncon_init(void)
64{
65 memset(buf, 0xff, sizeof(buf));
66 buf[1] = 0x5a;
67}
68