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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2007 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: AtariVox.cxx,v 1.5 2007/01/01 18:04:44 stephena Exp $
//============================================================================
#ifdef ATARIVOX_SUPPORT
#include "Event.hxx"
#include "AtariVox.hxx"
#include "SpeakJet.hxx"
#include "../common/Log.hpp"
#define DEBUG_ATARIVOX 0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AtariVox::AtariVox(Jack jack, const Event& event)
: Controller(jack, event),
mySpeakJet(0),
mySystem(0),
myPinState(0),
myShiftCount(0),
myShiftRegister(0),
myLastDataWriteCycle(0)
{
myType = Controller::AtariVox;
mySpeakJet = new SpeakJet();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AtariVox::~AtariVox()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AtariVox::setSystem(System *system) {
mySystem = system;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AtariVox::read(DigitalPin pin)
{
// For now, always return true, meaning the device is ready
/*
if(DEBUG_ATARIVOX)
cerr << "AtariVox: read from SWCHA" << endl;
*/
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Int32 AtariVox::read(AnalogPin)
{
// Analog pins are not connected in AtariVox, so we have infinite resistance
return maximumResistance;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AtariVox::clockDataIn(bool value)
{
// bool oldValue = myPinState & 0x01;
myPinState = (myPinState & 0xfe) | value;
uInt32 cycle = mySystem->cycles();
if(DEBUG_ATARIVOX)
ale::Logger::Info << "AtariVox: value "
<< value
<< " written to DATA line at "
<< mySystem->cycles()
<< " (-"
<< myLastDataWriteCycle
<< "=="
<< (mySystem->cycles() - myLastDataWriteCycle)
<< ")"
<< endl;
if(value && (myShiftCount == 0)) {
if(DEBUG_ATARIVOX)
ale::Logger::Info << "value && (myShiftCount == 0), returning" << endl;
return;
}
if(cycle < myLastDataWriteCycle || cycle > myLastDataWriteCycle + 1000) {
// If this is the first write this frame, or if it's been a long time
// since the last write, start a new data byte.
myShiftRegister = 0;
myShiftCount = 0;
}
if(cycle < myLastDataWriteCycle || cycle >= myLastDataWriteCycle + 62) {
// If this is the first write this frame, or if it's been 62 cycles
// since the last write, shift this bit into the current byte.
if(DEBUG_ATARIVOX)
ale::Logger::Info << "cycle >= myLastDataWriteCycle + 62, shiftIn("
<< value << ")" << endl;
shiftIn(value);
}
myLastDataWriteCycle = cycle;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AtariVox::shiftIn(bool value)
{
myShiftRegister >>= 1;
myShiftRegister |= (value << 15);
if(++myShiftCount == 10) {
myShiftCount = 0;
myShiftRegister >>= 6;
if(!(myShiftRegister & (1<<9)))
ale::Logger::Warning << "AtariVox: bad start bit" << endl;
else if((myShiftRegister & 1))
ale::Logger::Warning << "AtariVox: bad stop bit" << endl;
else
{
uInt8 data = ((myShiftRegister >> 1) & 0xff);
ale::Logger::Warning << "AtariVox: output byte " << ((int)(data)) << endl;
mySpeakJet->write(data);
}
myShiftRegister = 0;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AtariVox::write(DigitalPin pin, bool value)
{
if(DEBUG_ATARIVOX)
ale::Logger::Info << "AtariVox: write to SWCHA" << endl;
// Change the pin state based on value
switch(pin)
{
// Pin 1 is the DATA line, used to output serial data to the
// speakjet
case One:
clockDataIn(value);
break;
// Pin 2 is the SDA line, used to output data to the 24LC256
// serial EEPROM, using the I2C protocol.
// I'm not even trying to emulate this right now :(
case Two:
if(DEBUG_ATARIVOX)
ale::Logger::Info << "AtariVox: value "
<< value
<< " written to SDA line at cycle "
<< mySystem->cycles()
<< endl;
break;
// Pin 2 is the SCLK line, used to output clock data to the 24LC256
// serial EEPROM, using the I2C protocol.
// I'm not even trying to emulate this right now :(
case Three:
if(DEBUG_ATARIVOX)
ale::Logger::Info << "AtariVox: value "
<< value
<< " written to SCLK line at cycle "
<< mySystem->cycles()
<< endl;
break;
case Four:
default:
break;
}
}
#endif