]> git.sur5r.net Git - cc65/blob - include/_pia.h
Relocate register values outside structs, + more
[cc65] / include / _pia.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  _pia.h                                   */
4 /*                                                                           */
5 /*                Internal include file, do not use directly                 */
6 /*                                                                           */
7 /* The Peripheral Interface Adapter (PIA) chip provides parallel I/O         */
8 /* interfacing; it was used in Atari 400/800 and Commodore PET family of     */
9 /* computers, for joystick and interrupts.                                   */
10 /* - Sources; various + Wikpedia article on "Peripheral Interface Adapter"   */
11 /*                                                                           */
12 /*                                                                           */
13 /* (C) 2000 Freddy Offenga <taf_offenga@yahoo.com>                           */
14 /* 2019-01-14: Bill Kendrick <nbs@sonic.net>: Defines for registers          */
15 /*                                                                           */
16 /*                                                                           */
17 /* This software is provided 'as-is', without any expressed or implied       */
18 /* warranty.  In no event will the authors be held liable for any damages    */
19 /* arising from the use of this software.                                    */
20 /*                                                                           */
21 /* Permission is granted to anyone to use this software for any purpose,     */
22 /* including commercial applications, and to alter it and redistribute it    */
23 /* freely, subject to the following restrictions:                            */
24 /*                                                                           */
25 /* 1. The origin of this software must not be misrepresented; you must not   */
26 /*    claim that you wrote the original software. If you use this software   */
27 /*    in a product, an acknowledgment in the product documentation would be  */
28 /*    appreciated but is not required.                                       */
29 /* 2. Altered source versions must be plainly marked as such, and must not   */
30 /*    be misrepresented as being the original software.                      */
31 /* 3. This notice may not be removed or altered from any source              */
32 /*    distribution.                                                          */
33 /*                                                                           */
34 /*****************************************************************************/
35
36
37
38 #ifndef __PIA_H
39 #define __PIA_H
40
41
42 /* Define a structure with the PIA register offsets */
43 struct __pia {
44     unsigned char   porta;  /* port A data r/w */
45     unsigned char   portb;  /* port B data r/w */
46     unsigned char   pactl;  /* port A control */
47     unsigned char   pbctl;  /* port B control */
48 };
49
50
51 /* PORTA and PORTB register bits */
52
53 /* See also: "JOY_xxx_MASK" in "atari.h" */
54
55 /* Paddle 0-3 triggers (per PORTA bits) */
56 #define PORTA_PTRIG3 0x80
57 #define PORTA_PTRIG2 0x40
58 #define PORTA_PTRIG1 0x08
59 #define PORTA_PTRIG0 0x04
60
61
62 /* On the Atari 400/800, PORTB is the same as PORTA, but for controller ports 3 & 4. */
63
64 /* Paddle 4-7 triggers (per PORTB bits); only 400/800 had four controller ports */
65 #define PORTB_PTRIG7 0x80
66 #define PORTB_PTRIG6 0x40
67 #define PORTB_PTRIG5 0x08
68 #define PORTB_PTRIG4 0x04
69
70
71 /* On the XL series of computers, PORTB has been changed to a memory and
72 ** LED control (1200XL model only) register (read/write):
73 */
74
75 #define PORTB_OSROM            0x01
76 /* If set, the built-in OS is enabled, and occupies the address range $C000-$FFFF
77 ** (except that the area $D000-$D7FF will only access the hardware registers.)
78 ** If clear, RAM is enabled in this area (again, save for the hole.)
79 */
80
81 #define PORTB_BASICROM         0x02
82 /* If set, RAM is enabled for the address range $A000-$BFFF.
83 ** If clear, the built-in BASIC ROM is enabled at this address.
84 ** And if there is a cartridge installed in the computer, it makes no difference.
85 */
86
87 #define PORTB_LED1             0x04
88 #define PORTB_LED2             0x08
89 /* If set, the corresponding LED is turned off. If clear, the LED will be on.
90 ** (1200XL only)
91 */
92
93
94 /* On the XE series of computers, PORTB is a bank-selected memory control register (read/write): */
95
96 /* These bits determine which memory bank is visible to the CPU and/or ANTIC chip
97 ** when their Bank Switch bit is set. There are four possible banks of 16KB each.
98 */
99 #define PORTB_BANKSELECT1      0x00
100 #define PORTB_BANKSELECT2      0x04
101 #define PORTB_BANKSELECT3      0x08
102 #define PORTB_BANKSELECT4      0x0C
103
104
105 #define PORTB_BANKSWITCH_CPU   0x10
106 #define PORTB_BANKSWITCH_ANTIC 0x20
107 /* If set, the CPU and/or ANTIC chip will access bank-switched memory mapped to the
108 ** address range $4000-$7FFF.
109 ** If clear, the CPU and/or ANTIC will see normal memory in this region.
110 */
111
112
113 #define PORTB_SELFTEST         0x80
114 /* If set, RAM is enabled for the address range $5000-$57FF.
115 ** If clear, the self-test ROM (physically located at $D000-$D7FF, under the hardware registers)
116 ** is remapped to this memory area.
117 */
118
119
120 /* PACTL and PBCTL register bits */
121
122 #define PxCTL_IRQ_ENABLE       0x01 /* (W) Peripheral A interrupt (IRQ) enable. */
123 /* One equals enable. Set by the OS but available to the user; reset on powerup. */
124
125 #define PxCTL_BIT1             0x02 /* "Set to zero" */
126
127 #define PxCTL_ADDRESSING       0x04 /* (W) Controls PORTA addressing */
128 /* One equals PORTA register; zero equals direction control register */
129
130 #define PxCTL_BIT4             0x10 /* "Set to one" */
131 #define PxCTL_BIT5             0x20 /* "Set to one" */
132 #define PxCTL_BIT6             0x40 /* "Set to zero" */
133 #define PxCTL_IRQ_STATUS       0x80 /* Peripheral interrupt (IRQ) status bit. */
134 /* Set by Peripherals (PORTA / PORTB). Reset by reading PORTA / PORTB. */
135
136
137 /* PACTL-specific register bit */
138
139 #define PACTL_MOTOR_CONTROL    0x08 /* (W) Peripheral motor control line */
140 /* Turn the cassette on or off; zero equals on) */
141
142
143 /* PBCTL-specific register bit */
144
145 #define PBCTL_PERIPH_CMD_IDENT 0x08 /* Peripheral command identification (serial bus command) */
146
147
148
149 /* End of _pia.h */
150 #endif