]> Shamusworld >> Repos - virtualjaguar/blob - src/anajoy.cpp
Source cleanups
[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 // Is it even necessary anymore to have this? According to the JTRM, these ports
9 // aren't even wired up in later models and I can't think of one game that used
10 // them. Maybe it's time to retire this?
11
12 #include "jaguar.h"
13
14 static uint8 anajoy_ram[2];
15 static uint8 analog_x, analog_y;
16
17
18 void anajoy_init(void)
19 {
20         anajoy_reset();
21 }
22
23 void anajoy_reset(void)
24 {
25         memset(anajoy_ram,0x00,2);
26         analog_x=128;
27         analog_y=128;
28 }
29
30 void anajoy_done(void)
31 {
32 }
33
34 void anajoy_byte_write(uint32 offset, uint8 data)
35 {
36         anajoy_ram[offset&0x01]=data;
37 }
38
39 void anajoy_word_write(uint32 offset, uint16 data)
40 {
41         offset&=0x01;
42         anajoy_ram[offset+0]=(data>>8)&0xff;
43         anajoy_ram[offset+1]=data&0xff;
44 }
45
46 uint8 anajoy_byte_read(uint32 offset)
47 {
48         if (anajoy_ram[1]&0x01)
49                 return(analog_y);
50         else
51                 return(analog_x);
52 }
53
54 uint16 anajoy_word_read(uint32 offset)
55 {
56         uint16 data=anajoy_byte_read((offset+0)&0x01);
57         data<<=8;
58         data|=anajoy_byte_read((offset+1)&0x01);
59         return(data);
60 }