-
Notifications
You must be signed in to change notification settings - Fork 0
/
kscan.h
109 lines (78 loc) · 3.55 KB
/
kscan.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// KSCAN definitions for keyboard and joystick
//*********************
// KSCAN related addresses
//*********************
#ifndef KSCAN_H
#define KSCAN_H
#ifdef TI99
// Address to set the scan mode (see KSCAN_MODE_xxx defines)
#define KSCAN_MODE *((volatile unsigned char*)0x8374)
// Address to read back the detected key. 0xFF if no key was pressed.
#define KSCAN_KEY *((volatile unsigned char*)0x8375)
// Address to read back the joystick X axis (scan modes 1 and 2 only)
#define KSCAN_JOYY *((volatile unsigned char*)0x8376)
// Address to read back the joystick Y axis (scan modes 1 and 2 only)
#define KSCAN_JOYX *((volatile unsigned char*)0x8377)
// Address to check the status byte. KSCAN_MASK is set if a key was pressed
#define KSCAN_STATUS *((volatile unsigned char*)0x837c)
#endif
#ifdef COLECO
// Address to set the scan mode (see KSCAN_MODE_xxx defines) (meaningless on Coleco)
#define KSCAN_MODE *((volatile unsigned char*)0)
// Address to read back the detected key. 0xFF if no key was pressed.
extern volatile unsigned char KSCAN_KEY;
// Address to read back the joystick X axis (scan modes 1 and 2 only)
extern volatile unsigned char KSCAN_JOYY;
// Address to read back the joystick Y axis (scan modes 1 and 2 only)
extern volatile unsigned char KSCAN_JOYX;
// Address to check the status byte. KSCAN_MASK is set if a key was pressed
extern volatile unsigned char KSCAN_STATUS;
#endif
#ifdef GBA
// Address to set the scan mode (see KSCAN_MODE_xxx defines) (meaningless on GBA)
#define KSCAN_MODE *((volatile unsigned char*)0)
// Address to read back the detected key. 0xFF if no key was pressed.
extern volatile unsigned char KSCAN_KEY;
// Address to read back the joystick X axis (scan modes 1 and 2 only)
extern volatile unsigned char KSCAN_JOYY;
// Address to read back the joystick Y axis (scan modes 1 and 2 only)
extern volatile unsigned char KSCAN_JOYX;
// Address to check the status byte. KSCAN_MASK is set if a key was pressed
extern volatile unsigned char KSCAN_STATUS;
#endif
#define KSCAN_MASK 0x20
//*********************
// KSCAN modes
//*********************
#define KSCAN_MODE_LAST 0 // last mode scanned
#define KSCAN_MODE_LEFT 1 // left side of keyboard and joystick 1 (fire is a key of 18)
#define KSCAN_MODE_RIGHT 2 // right side of keyboard and joystick 2 (fire is a key of 18)
#define KSCAN_MODE_994 3 // upper-case only, 99/4 compatible results
#define KSCAN_MODE_PASCAL 4 // PASCAL mapping, different control keys
#define KSCAN_MODE_BASIC 5 // Normal 99/4A BASIC mode
//*********************
// Joystick return values
//*********************
#define JOY_LEFT 0xfc
#define JOY_RIGHT 0x04
#define JOY_UP 0x04
#define JOY_DOWN 0xfc
#define JOY_FIRE 18
#define JOY_FIRE2 18
#define JOY_FIRE3 18
// TODO: joystick fire can be split out on Coleco and probably others
//*********************
// Function definitions
//*********************
// call the console SCAN function, supports all the regular keyboard modes, debounce, joysticks, etc.
// requires console ROM and GROM to be present.
unsigned char kscan(unsigned char mode);
// does a simple read of the keyboard with no shifts and no debounce. Mode 0 is keyboard,
// mode 1 is joystick 1 fire button (only!) and mode 2 is joystick 2 fire button (only!)
// Fire buttons are /not/ aliased to 'Q' and 'Y' on the keyboard. Returns key in KSCAN_KEY,
// no status. Key is 0xff if none pressed.
void kscanfast(unsigned char mode);
// read a joystick directly. 'unit' is either 1 or 2 for the joystick desired
// returns data in KSCAN_JOYY and KSCAN_JOYX
void joystfast(unsigned char unit);
#endif /* KSCAN_H */