
#ifndef JOYSWIS_H_INCLUDED
#define JOYSWIS_H_INCLUDED


// The SWI configuration is set up to match the Acorn standard
#define USBJoystickSWI_Base  0x43F40
#define USBJoystickSWI_Name  Joystick

#define MODULE_SWI(name) (name - USBJoystickSWI_Base)


// this is only needed to work around CMHG not defining it
// because the standard RISC OS headers define Joystick_Read (base)
#define Joystick_Status                 0x043f43


// This is what we will also trap for Serial Port interface compatibility
#define USBJoystickSerialPortSWI  0x81540

// This is what we will also trap for Joy interface conpatibility
#define JoySWI_Read0      0xCFFC0
#define JoySWI_Read1      0xCFFC1
#define JoySWI_Test       0xCFFC2
#define JoySWI_ReadPipe   0xCFFC3



#define ACORN_SWI_READ_REASON_8            0
#define ACORN_SWI_READ_REASON_16           1
#define ACORN_SWI_READ_REASON_DEV_INFO     2
#define ACORN_SWI_READ_REASON_AXES_INFO    3
#define ACORN_SWI_READ_REASON_AXES_VALUES  4

#define ACORN_AXIS_VALUES_8             255
#define ACORN_AXIS_MIN_VALUE_8         -127
#define ACORN_AXIS_MAX_VALUE_8          127
#define ACORN_AXIS_HAT_SCALE_8           64
#define ACORN_REST_8                      0

#define ACORN_BUTTONS   32

#define ACORN_AXIS_VALUES_16            65536
#define ACORN_AXIS_MIN_VALUE_16             0
#define ACORN_AXIS_MAX_VALUE_16         65535
#define ACORN_AXIS_HAT_MIN_16           12288
#define ACORN_AXIS_HAT_MID_16           32768
#define ACORN_AXIS_HAT_MAX_16           53247
#define ACORN_AXES_REST_16              (int)0x80008000
#define ACORN_BUTTONS_REST_16           0




_kernel_oserror* swi_joystick_read(_kernel_swi_regs *r);
_kernel_oserror* joystick_read_acorn_8(_kernel_swi_regs *r, uint32_t i);
_kernel_oserror* joystick_read_acorn_16(_kernel_swi_regs *r, uint32_t i);
_kernel_oserror* joystick_read_acorn_dev_info(_kernel_swi_regs *r, uint32_t i);
_kernel_oserror* joystick_read_acorn_axes_info(_kernel_swi_regs *r, uint32_t i);
_kernel_oserror* joystick_read_acorn_axes_values(_kernel_swi_regs *r, uint32_t i);

int32_t scaled_value_8(struct axisdata_struct *a);
int32_t scaled_value_16(struct axisdata_struct *a);
int32_t scaled_value_pc(struct axisdata_struct *a);


extern void ukswiv_pre_hook(void*);
_kernel_oserror* ukswiv_hook_handler(_kernel_swi_regs *r, void *pw);


_kernel_oserror* swi_joystick_status(_kernel_swi_regs *r);
uint32_t encode_stick_serial_port(int32_t i);


_kernel_oserror* swi_joy_read(_kernel_swi_regs *r, int32_t n);
_kernel_oserror* swi_joy_test(_kernel_swi_regs *r);
_kernel_oserror* swi_joy_readpipe(_kernel_swi_regs *r);



#endif
