1 /*****************************************************************************/
5 /* Internal include file, do not use directly */
7 /* POKEY, Pot Keyboard Integrated Circuit, is a digital I/O chip designed */
8 /* for the Atari 8-bit family of home computers; it combines functions for */
9 /* sampling (ADC) potentiometers (such as game paddles) and scan matrices of */
10 /* switches (such as a computer keyboard) as well as sound generation. */
11 /* It produces four voices of distinctive square wave sound, either as clear */
12 /* tones or modified with a number of distortion settings. - Wikipedia */
13 /* "POKEY" article. */
16 /* (C) 2000 Freddy Offenga <taf_offenga@yahoo.com> */
17 /* 2019-01-13: Bill Kendrick <nbs@sonic.net>: More defines for registers */
20 /* This software is provided 'as-is', without any expressed or implied */
21 /* warranty. In no event will the authors be held liable for any damages */
22 /* arising from the use of this software. */
24 /* Permission is granted to anyone to use this software for any purpose, */
25 /* including commercial applications, and to alter it and redistribute it */
26 /* freely, subject to the following restrictions: */
28 /* 1. The origin of this software must not be misrepresented; you must not */
29 /* claim that you wrote the original software. If you use this software */
30 /* in a product, an acknowledgment in the product documentation would be */
31 /* appreciated but is not required. */
32 /* 2. Altered source versions must be plainly marked as such, and must not */
33 /* be misrepresented as being the original software. */
34 /* 3. This notice may not be removed or altered from any source */
37 /*****************************************************************************/
46 /* Define a structure with the POKEY register offsets for write (W) */
47 struct __pokey_write {
48 unsigned char audf1; /* audio channel #1 frequency */
49 unsigned char audc1; /* audio channel #1 control */
50 unsigned char audf2; /* audio channel #2 frequency */
51 unsigned char audc2; /* audio channel #2 control */
52 unsigned char audf3; /* audio channel #3 frequency */
53 unsigned char audc3; /* audio channel #3 control */
54 unsigned char audf4; /* audio channel #4 frequency */
55 unsigned char audc4; /* audio channel #4 control */
57 /* The values for the distortion bits (AUDCx) are as follows;
58 the first process is to divide the clock value by the frequency,
59 then mask the output using the polys in the order below;
60 finally, the result is divided by two */
61 #define AUDC_POLYS_5_17 0x00
62 #define AUDC_POLYS_5 0x20 /* Same as 0x60 */
63 #define AUDC_POLYS_5_4 0x40
64 #define AUDC_POLYS_17 0x80
65 #define AUDC_POLYS_NONE 0xA0 /* Same as 0xE0 */
66 #define AUDC_POLYS_4 0xC0
68 #define AUDC_VOLUME_ONLY 0x10
71 unsigned char audctl; /* audio control */
73 #define AUDCTL_CLOCKBASE_15HZ 0x01 /* Switch main clock base from 64 KHz to 15 KHz */
74 #define AUDCTL_HIGHPASS_CHAN2 0x02 /* Insert high pass filter into channel two, clocked by channel four */
75 #define AUDCTL_HIGHPASS_CHAN1 0x04 /* Insert high pass filter into channel one, clocked by channel two */
76 #define AUDCTL_JOIN_CHAN34 0x08 /* Join channels four and three (16 bit) */
77 #define AUDCTL_JOIN_CHAN12 0x10 /* Join channels two and one (16 bit) */
78 #define AUDCTL_CLOCK_CHAN3_179MHZ 0x20 /* Clock channel three with 1.79 MHz */
79 #define AUDCTL_CLOCK_CHAN1_179MHZ 0x40 /* Clock channel one with 1.79 MHz */
80 #define AUDCTL_9BIT_POLY 0x80 /* Makes the 17 bit poly counter into nine bit poly (see also: RANDOM) */
82 unsigned char stimer; /* start pokey timers */
84 unsigned char skrest; /* reset serial port status reg.;
85 Reset BITs 5 - 7 of the serial port status register (SKCTL) to "1" */
87 unsigned char potgo; /* start paddle scan sequence (see "ALLPOT") */
88 unsigned char unuse1; /* unused */
89 unsigned char serout; /* serial port data output */
91 unsigned char irqen; /* interrupt request enable */
92 #define POKMSK *(unsigned char *) 0x10 /* POKEY interrupts: the IRQ service uses and alters this location */
93 #define IRQEN_TIMER_1 0x01 /* The POKEY timer one interrupt is enabled */
94 #define IRQEN_TIMER_2 0x02 /* The POKEY timer two interrupt is enabled */
95 #define IRQEN_TIMER_4 0x04 /* The POKEY timer four interrupt is enabled */
96 #define IRQEN_SERIAL_TRANS_FINISHED 0x08 /* The serial out transmission finished interrupt is enabled */
97 #define IRQEN_SERIAL_OUT_DATA_REQUIRED 0x10 /* The serial output data required interrupt is enabled */
98 #define IRQEN_SERIAL_IN_DATA_READY 0x20 /* The serial input data ready interrupt is enabled. */
99 #define IRQEN_OTHER_KEY 0x40 /* The "other key" interrupt is enabled */
100 #define IRQEN_BREAK_KEY 0x80 /* The BREAK key is enabled */
103 unsigned char skctl; /* serial port control */
105 #define SKCTL_KEYBOARD_DEBOUNCE 0x01 /* Enable keyboard debounce circuits */
106 #define SKCTL_KEYBOARD_SCANNING 0x02 /* Enable keyboard scanning circuit */
107 #define SKCTL_FAST_POT_SCAN 0x04 /* Fast pot scan */
108 /* the pot scan counter completes its sequence in two TV line times instead of
109 one frame time (228 scan lines). Not as accurate as the normal pot scan */
110 #define SKCTL_TWO_TONE_MODE 0x08 /* Serial output is transmitted as a two-tone
111 signal rather than a logic true/false. POKEY two-tone mode. */
112 /* Serial port mode control used to set the bi-directional clock lines */
113 #define SKCTL_BIT4 0x10 /* FIXME; more meaningful name */
114 #define SKCTL_BIT5 0x20 /* FIXME; more meaningful name */
115 #define SKCTL_BIT6 0x40 /* FIXME; more meaningful name */
116 #define SKCTL_FORCE_BREAK 0x80 /* Force break (serial output to zero) */
120 /* Define a structure with the POKEY register offsets for read (R) */
121 struct __pokey_read {
122 unsigned char pot0; /* paddle 0 value */
123 unsigned char pot1; /* paddle 1 value */
124 unsigned char pot2; /* paddle 2 value */
125 unsigned char pot3; /* paddle 3 value */
126 unsigned char pot4; /* paddle 4 value */
127 unsigned char pot5; /* paddle 5 value */
128 unsigned char pot6; /* paddle 6 value */
129 unsigned char pot7; /* paddle 7 value */
130 unsigned char allpot; /* eight paddle port status (see "POTGO") */
131 unsigned char kbcode; /* keyboard code */
132 unsigned char random; /* random number generator */
133 unsigned char unuse2; /* unused */
134 unsigned char unuse3; /* unused */
135 unsigned char serin; /* serial port input */
136 unsigned char irqst; /* interrupt request status */
138 unsigned char skstat; /* serial port status */
139 #define SKSTAT_SERIN_SHIFTREG_BUSY 0x02 /* Serial input shift register busy */
140 #define SKSTAT_LASTKEY_PRESSED 0x04 /* the last key is still pressed */
141 #define SKSTAT_SHIFTKEY_PRESSED 0x08 /* the [Shift] key is pressed */
142 #define SKSTAT_DATA_READ_INGORING_SHIFTREG 0x10 /* Data can be read directly from the serial input port, ignoring the shift register. */
143 #define SKSTAT_KEYBOARD_OVERRUN 0x20 /* Keyboard over-run; Reset BITs 7, 6 and 5 (latches) to 1, using SKREST */
144 #define SKSTAT_INPUT_OVERRUN 0x40 /* Serial data input over-run. Reset latches as above. */
145 #define SKSTAT_INPUT_FRAMEERROR 0x80 /* Serial data input frame error caused by missing or extra bits. Reset latches as above. */
149 /* Internal keyboard codes from http://www.atariarchives.org/c3ba/page004.php */
150 /* (Defined below in the order the keys appear on a 1200XL keyboard, from top left to bottom right) */
151 /* (Note: Numerous Shift+Ctrl+key combos are unavailable) */
153 #define KEYCODE_NONE 255 /* 255 = no key pressed (but is also same as Ctrl+Shift+A) */
155 /* Fn (function) keys only available on 1200XL */
158 #define KEYCODE_F3 19
159 #define KEYCODE_F4 20
161 /* HELP key only available on XL/XE series */
162 #define KEYCODE_HELP 17
164 #define KEYCODE_ESC 28
175 #define KEYCODE_LT 54
176 #define KEYCODE_GT 55
177 #define KEYCODE_BKSPC 52
179 #define KEYCODE_TAB 44
190 #define KEYCODE_MINUS 14
191 #define KEYCODE_EQUALS 15
192 #define KEYCODE_RETURN 12
194 #define KEYCODE_CTRL 128 /* binary OR'd */
206 #define KEYCODE_PLUS 6
207 #define KEYCODE_ASTERISK 7
208 #define KEYCODE_CAPS 60
210 #define KEYCODE_SHIFT 64 /* binary OR'd */
219 #define KEYCODE_COMMA 32
220 #define KEYCODE_PERIOD 34
221 #define KEYCODE_SLASH 38
222 #define KEYCODE_FUJI 39 /* (as seen on 400/800) */
223 #define KEYCODE_INVERSE 39 /* (alternative name; as seen on XL/XE) */
225 #define KEYCODE_SPACE 33
228 /* End of _pokey.h */
229 #endif /* #ifndef __POKEY_H */