Skip to content

Commit e613cd3

Browse files
committed
ws: fix RTC cartridge protocol emulation
1 parent d8c997c commit e613cd3

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

ares/ws/cartridge/cartridge.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct Cartridge : IO, Thread {
9393

9494
n4 command;
9595
n1 active;
96+
n1 ready;
9697
n4 index;
9798
n8 fetchedData;
9899
n15 counter;

ares/ws/cartridge/rtc.cpp

+11-17
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,11 @@ auto Cartridge::RTC::controlRead() -> n8 {
9595
n8 data = 0;
9696
data.bit(0,3) = command;
9797
data.bit(4) = active;
98-
data.bit(7) = 1; //0 = busy; 1 = ready for command
98+
data.bit(7) = ready;
9999
return data;
100100
}
101101

102102
auto Cartridge::RTC::controlWrite(n5 data) -> void {
103-
// TODO: This probably isn't right, but will do unless someone tries to
104-
// cancel an RTC command mid-execution.
105-
if(active) {
106-
if(!data.bit(4) || command != data.bit(0,3)) {
107-
debug(unimplemented, "[RTC] Port 0xCA write during command processing = ", data);
108-
}
109-
return;
110-
}
111-
112103
command = data.bit(0,3);
113104
active = data.bit(4);
114105

@@ -132,12 +123,11 @@ auto Cartridge::RTC::controlWrite(n5 data) -> void {
132123
case 0x0A: { // no-op
133124
index = 0;
134125
} break;
135-
default: {
136-
active = 0;
137-
} break;
138126
}
139127

140-
if(active && command.bit(0)) fetch();
128+
ready = 1;
129+
if(active && command.bit(0)) fetch();
130+
if(active && !command.bit(0)) write(fetchedData);
141131
}
142132

143133
auto Cartridge::RTC::fetch() -> void {
@@ -181,22 +171,25 @@ auto Cartridge::RTC::fetch() -> void {
181171
data = 0xFF;
182172
if(++index >= 2) active = 0;
183173
} break;
184-
default: {
185-
active = 0;
186-
} break;
187174
}
188175

176+
ready = 1;
189177
fetchedData = data;
190178
}
191179

192180
auto Cartridge::RTC::read() -> n8 {
193181
n8 data = fetchedData;
182+
183+
if(!active) ready = 0;
194184
if(active && command.bit(0)) fetch();
195185

196186
return data;
197187
}
198188

199189
auto Cartridge::RTC::write(n8 data) -> void {
190+
fetchedData = data;
191+
192+
if(!active) ready = 0;
200193
if(active && !command.bit(0)) switch(command & 0x0E) {
201194
case 0x02: { // STATUS
202195
status().bit(6) = data.bit(6);
@@ -259,6 +252,7 @@ auto Cartridge::RTC::power() -> void {
259252

260253
command = 0;
261254
active = 0;
255+
ready = 0;
262256
index = 0;
263257
counter = 0;
264258
fetchedData = 0xFF;

ares/ws/cartridge/serialization.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ auto Cartridge::RTC::serialize(serializer& s) -> void {
4141

4242
s(command);
4343
s(active);
44+
s(ready);
4445
s(index);
4546
s(fetchedData);
4647
s(counter);

ares/ws/system/serialization.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static const string SerializerVersion = "v144.2";
1+
static const string SerializerVersion = "v144.3";
22

33
auto System::serialize(bool synchronize) -> serializer {
44
if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize);

0 commit comments

Comments
 (0)