1 /*
2   Hatari - ikbd.h
3 
4   This file is distributed under the GNU General Public License, version 2
5   or at your option any later version. Read the file gpl.txt for details.
6 */
7 
8 #ifndef HATARI_IKBD_H
9 #define HATARI_IKBD_H
10 
11 /* Keyboard processor details */
12 
13 typedef struct {
14   int X,Y;                        /* Position of mouse */
15   int MaxX,MaxY;                  /* Max limits of mouse */
16   Uint8 PrevReadAbsMouseButtons;  /* Previous button mask for 'IKBD_Cmd_ReadAbsMousePos' */
17 } ABS_MOUSE;
18 
19 typedef struct {
20   int dx, dy;                     /* Mouse delta to be added */
21   int DeltaX,DeltaY;              /* Final XY mouse position delta */
22   int XScale,YScale;              /* Scale of mouse */
23   int XThreshold,YThreshold;      /* Threshold */
24   Uint8 KeyCodeDeltaX,KeyCodeDeltaY;    /* Delta X,Y for mouse keycode mode */
25   int YAxis;                      /* Y-Axis direction */
26   Uint8 Action;                   /* Bit 0-Report abs position of press, Bit 1-Report abs on release */
27 } MOUSE;
28 
29 typedef struct {
30   Uint8 JoyData[2];               /* Joystick details */
31   Uint8 PrevJoyData[2];           /* Previous joystick details, used to check for 'IKBD_SendAutoJoysticks' */
32 } JOY;
33 
34 typedef struct {
35   ABS_MOUSE  Abs;
36   MOUSE    Mouse;
37   JOY      Joy;
38   int MouseMode;                  /* AUTOMODE_xxxx */
39   int JoystickMode;               /* AUTOMODE_xxxx */
40 } KEYBOARD_PROCESSOR;
41 
42 /* Keyboard state */
43 #define KBD_MAX_SCANCODE          0x72
44 #define SIZE_KEYBOARD_BUFFER      1024    /* Allow this many bytes to be stored in buffer (waiting to send to ACIA) */
45 #define KEYBOARD_BUFFER_MASK      (SIZE_KEYBOARD_BUFFER-1)
46 #define SIZE_KEYBOARDINPUT_BUFFER 8
47 typedef struct {
48   Uint8 KeyStates[KBD_MAX_SCANCODE + 1];	/* State of ST keys, TRUE is down */
49 
50   Uint8 Buffer[SIZE_KEYBOARD_BUFFER];		/* Keyboard output buffer */
51   int BufferHead,BufferTail;			/* Pointers into above buffer */
52   int NbBytesInOutputBuffer;			/* Number of bytes in output buffer */
53   bool PauseOutput;				/* If true, don't send bytes anymore (see command 0x13) */
54 
55   Uint8 InputBuffer[SIZE_KEYBOARDINPUT_BUFFER];	/* Buffer for data send from CPU to keyboard processor (commands) */
56   int nBytesInInputBuffer;			/* Number of command bytes in above buffer */
57 
58   int bLButtonDown,bRButtonDown;                /* Mouse states in emulation system, BUTTON_xxxx */
59   int bOldLButtonDown,bOldRButtonDown;
60   int LButtonDblClk,RButtonDblClk;
61   int LButtonHistory,RButtonHistory;
62 
63   int AutoSendCycles;				/* Number of cpu cycles to call INTERRUPT_IKBD_AUTOSEND */
64 } KEYBOARD;
65 
66 /* Button states, a bit mask so can mimick joystick/right mouse button duplication */
67 #define BUTTON_NULL      0x00     /* Button states, so can OR together mouse/joystick buttons */
68 #define BUTTON_MOUSE     0x01
69 #define BUTTON_JOYSTICK  0x02
70 
71 /* Mouse/Joystick modes */
72 #define AUTOMODE_OFF			0
73 #define AUTOMODE_MOUSEREL		1
74 #define AUTOMODE_MOUSEABS		2
75 #define AUTOMODE_MOUSECURSOR		3
76 #define AUTOMODE_JOYSTICK		4
77 #define AUTOMODE_JOYSTICK_MONITORING	5
78 
79 /* 0xfffc00 (read status from ACIA) */
80 #define ACIA_STATUS_REGISTER__RX_BUFFER_FULL  0x01
81 #define ACIA_STATUS_REGISTER__TX_BUFFER_EMPTY  0x02
82 #define ACIA_STATUS_REGISTER__OVERRUN_ERROR    0x20
83 #define ACIA_STATUS_REGISTER__INTERRUPT_REQUEST  0x80
84 
85 extern KEYBOARD_PROCESSOR KeyboardProcessor;
86 extern KEYBOARD Keyboard;
87 
88 extern void IKBD_Init ( void );
89 extern void IKBD_Reset(bool bCold);
90 extern void IKBD_MemorySnapShot_Capture(bool bSave);
91 
92 extern void IKBD_InterruptHandler_ResetTimer(void);
93 extern void IKBD_InterruptHandler_AutoSend(void);
94 
95 extern void IKBD_UpdateClockOnVBL ( void );
96 
97 
98 extern void IKBD_PressSTKey(Uint8 ScanCode, bool bPress);
99 
100 #endif  /* HATARI_IKBD_H */
101