]> Shamusworld >> Repos - virtualjaguar/blob - src/anajoy.cpp
Virtual Jaguar GCC/SDL v1.0.3 import.
[virtualjaguar] / src / anajoy.cpp
1 //
2 // Analog joystick handler
3 //
4 // by cal2
5 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
6 // Cleanups by James L. Hammons
7 //
8
9 #include "jaguar.h"
10
11 static uint8 anajoy_ram[2];
12 static uint8 analog_x, analog_y;
13
14
15 void anajoy_init(void)
16 {
17         anajoy_reset();
18 }
19
20 void anajoy_reset(void)
21 {
22         memset(anajoy_ram,0x00,2);
23         analog_x=128;
24         analog_y=128;
25 }
26
27 void anajoy_done(void)
28 {
29 }
30
31 void anajoy_byte_write(uint32 offset, uint8 data)
32 {
33         anajoy_ram[offset&0x01]=data;
34 }
35
36 void anajoy_word_write(uint32 offset, uint16 data)
37 {
38         offset&=0x01;
39         anajoy_ram[offset+0]=(data>>8)&0xff;
40         anajoy_ram[offset+1]=data&0xff;
41 }
42
43 uint8 anajoy_byte_read(uint32 offset)
44 {
45         if (anajoy_ram[1]&0x01)
46                 return(analog_y);
47         else
48                 return(analog_x);
49 }
50
51 uint16 anajoy_word_read(uint32 offset)
52 {
53         uint16 data=anajoy_byte_read((offset+0)&0x01);
54         data<<=8;
55         data|=anajoy_byte_read((offset+1)&0x01);
56         return(data);
57 }