1 //============================================================================
2 //
3 //   SSSS    tt          lll  lll
4 //  SS  SS   tt           ll   ll
5 //  SS     tttttt  eeee   ll   ll   aaaa
6 //   SSSS    tt   ee  ee  ll   ll      aa
7 //      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
8 //  SS  SS   tt   ee      ll   ll  aa  aa
9 //   SSSS     ttt  eeeee llll llll  aaaaa
10 //
11 // Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony
12 // and the Stella Team
13 //
14 // See the file "License.txt" for information on usage and redistribution of
15 // this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 //============================================================================
17 
18 #ifndef TIA_CONSTANTS_HXX
19 #define TIA_CONSTANTS_HXX
20 
21 #include "bspf.hxx"
22 
23 namespace TIAConstants {
24 
25   static constexpr uInt32 frameBufferWidth = 160;
26   static constexpr uInt32 frameBufferHeight = 320;
27   static constexpr Int32 minVcenter = -20; // limit to reasonable values
28   static constexpr Int32 maxVcenter = 20; // limit to reasonable values
29   static constexpr uInt32 viewableWidth = 320;
30   static constexpr uInt32 viewableHeight = 240;
31   static constexpr uInt32 initialGarbageFrames = 10;
32 
33   static constexpr uInt16
34     H_PIXEL = 160, H_CYCLES = 76, CYCLE_CLOCKS = 3,
35     H_CLOCKS = H_CYCLES * CYCLE_CLOCKS,   // = 228
36     H_BLANK_CLOCKS = H_CLOCKS - H_PIXEL;  // = 68
37 }
38 
39 enum TIABit {
40   P0Bit       = 0x01,  // Bit for Player 0
41   M0Bit       = 0x02,  // Bit for Missle 0
42   P1Bit       = 0x04,  // Bit for Player 1
43   M1Bit       = 0x08,  // Bit for Missle 1
44   BLBit       = 0x10,  // Bit for Ball
45   PFBit       = 0x20,  // Bit for Playfield
46   ScoreBit    = 0x40,  // Bit for Playfield score mode
47   PriorityBit = 0x80   // Bit for Playfield priority
48 };
49 
50 enum TIAColor {
51   BKColor     = 0,  // Color index for Background
52   PFColor     = 1,  // Color index for Playfield
53   P0Color     = 2,  // Color index for Player 0
54   P1Color     = 3,  // Color index for Player 1
55   M0Color     = 4,  // Color index for Missle 0
56   M1Color     = 5,  // Color index for Missle 1
57   BLColor     = 6,  // Color index for Ball
58   HBLANKColor = 7   // Color index for HMove blank area
59 };
60 
61 enum class CollisionBit
62 {
63   M0P1 = 1 << 0,   // Missle0 - Player1   collision
64   M0P0 = 1 << 1,   // Missle0 - Player0   collision
65   M1P0 = 1 << 2,   // Missle1 - Player0   collision
66   M1P1 = 1 << 3,   // Missle1 - Player1   collision
67   P0PF = 1 << 4,   // Player0 - Playfield collision
68   P0BL = 1 << 5,   // Player0 - Ball      collision
69   P1PF = 1 << 6,   // Player1 - Playfield collision
70   P1BL = 1 << 7,   // Player1 - Ball      collision
71   M0PF = 1 << 8,   // Missle0 - Playfield collision
72   M0BL = 1 << 9,   // Missle0 - Ball      collision
73   M1PF = 1 << 10,  // Missle1 - Playfield collision
74   M1BL = 1 << 11,  // Missle1 - Ball      collision
75   BLPF = 1 << 12,  // Ball - Playfield    collision
76   P0P1 = 1 << 13,  // Player0 - Player1   collision
77   M0M1 = 1 << 14   // Missle0 - Missle1   collision
78 };
79 
80 // TIA Write/Read register names
81 enum TIARegister {
82   VSYNC   = 0x00,  // Write: vertical sync set-clear (D1)
83   VBLANK  = 0x01,  // Write: vertical blank set-clear (D7-6,D1)
84   WSYNC   = 0x02,  // Write: wait for leading edge of hrz. blank (strobe)
85   RSYNC   = 0x03,  // Write: reset hrz. sync counter (strobe)
86   NUSIZ0  = 0x04,  // Write: number-size player-missle 0 (D5-0)
87   NUSIZ1  = 0x05,  // Write: number-size player-missle 1 (D5-0)
88   COLUP0  = 0x06,  // Write: color-lum player 0 (D7-1)
89   COLUP1  = 0x07,  // Write: color-lum player 1 (D7-1)
90   COLUPF  = 0x08,  // Write: color-lum playfield (D7-1)
91   COLUBK  = 0x09,  // Write: color-lum background (D7-1)
92   CTRLPF  = 0x0a,  // Write: cntrl playfield ballsize & coll. (D5-4,D2-0)
93   REFP0   = 0x0b,  // Write: reflect player 0 (D3)
94   REFP1   = 0x0c,  // Write: reflect player 1 (D3)
95   PF0     = 0x0d,  // Write: playfield register byte 0 (D7-4)
96   PF1     = 0x0e,  // Write: playfield register byte 1 (D7-0)
97   PF2     = 0x0f,  // Write: playfield register byte 2 (D7-0)
98   RESP0   = 0x10,  // Write: reset player 0 (strobe)
99   RESP1   = 0x11,  // Write: reset player 1 (strobe)
100   RESM0   = 0x12,  // Write: reset missle 0 (strobe)
101   RESM1   = 0x13,  // Write: reset missle 1 (strobe)
102   RESBL   = 0x14,  // Write: reset ball (strobe)
103   AUDC0   = 0x15,  // Write: audio control 0 (D3-0)
104   AUDC1   = 0x16,  // Write: audio control 1 (D4-0)
105   AUDF0   = 0x17,  // Write: audio frequency 0 (D4-0)
106   AUDF1   = 0x18,  // Write: audio frequency 1 (D3-0)
107   AUDV0   = 0x19,  // Write: audio volume 0 (D3-0)
108   AUDV1   = 0x1a,  // Write: audio volume 1 (D3-0)
109   GRP0    = 0x1b,  // Write: graphics player 0 (D7-0)
110   GRP1    = 0x1c,  // Write: graphics player 1 (D7-0)
111   ENAM0   = 0x1d,  // Write: graphics (enable) missle 0 (D1)
112   ENAM1   = 0x1e,  // Write: graphics (enable) missle 1 (D1)
113   ENABL   = 0x1f,  // Write: graphics (enable) ball (D1)
114   HMP0    = 0x20,  // Write: horizontal motion player 0 (D7-4)
115   HMP1    = 0x21,  // Write: horizontal motion player 1 (D7-4)
116   HMM0    = 0x22,  // Write: horizontal motion missle 0 (D7-4)
117   HMM1    = 0x23,  // Write: horizontal motion missle 1 (D7-4)
118   HMBL    = 0x24,  // Write: horizontal motion ball (D7-4)
119   VDELP0  = 0x25,  // Write: vertical delay player 0 (D0)
120   VDELP1  = 0x26,  // Write: vertical delay player 1 (D0)
121   VDELBL  = 0x27,  // Write: vertical delay ball (D0)
122   RESMP0  = 0x28,  // Write: reset missle 0 to player 0 (D1)
123   RESMP1  = 0x29,  // Write: reset missle 1 to player 1 (D1)
124   HMOVE   = 0x2a,  // Write: apply horizontal motion (strobe)
125   HMCLR   = 0x2b,  // Write: clear horizontal motion registers (strobe)
126   CXCLR   = 0x2c,  // Write: clear collision latches (strobe)
127 
128   CXM0P   = 0x00,  // Read collision: D7=(M0,P1); D6=(M0,P0)
129   CXM1P   = 0x01,  // Read collision: D7=(M1,P0); D6=(M1,P1)
130   CXP0FB  = 0x02,  // Read collision: D7=(P0,PF); D6=(P0,BL)
131   CXP1FB  = 0x03,  // Read collision: D7=(P1,PF); D6=(P1,BL)
132   CXM0FB  = 0x04,  // Read collision: D7=(M0,PF); D6=(M0,BL)
133   CXM1FB  = 0x05,  // Read collision: D7=(M1,PF); D6=(M1,BL)
134   CXBLPF  = 0x06,  // Read collision: D7=(BL,PF); D6=(unused)
135   CXPPMM  = 0x07,  // Read collision: D7=(P0,P1); D6=(M0,M1)
136   INPT0   = 0x08,  // Read pot port: D7
137   INPT1   = 0x09,  // Read pot port: D7
138   INPT2   = 0x0a,  // Read pot port: D7
139   INPT3   = 0x0b,  // Read pot port: D7
140   INPT4   = 0x0c,  // Read P1 joystick trigger: D7
141   INPT5   = 0x0d   // Read P2 joystick trigger: D7
142 };
143 
144 #endif // TIA_CONSTANTS_HXX
145