Skip to content

Commit bbcaced

Browse files
mcaylandhuth
authored andcommitted
next-cube: always use retval to return rtc read values
Instead of shifting out rtc read values from individual rtc registers, change the logic so that rtc read commands are executed when the last bit of the rtc command is received and the result stored in retval. This simplifies the rtc read logic such that the shift out logic can be consolidated for rtc phases between 8 and 16. Signed-off-by: Mark Cave-Ayland <[email protected]> Message-ID: <[email protected]> Signed-off-by: Thomas Huth <[email protected]>
1 parent b37da8b commit bbcaced

File tree

1 file changed

+40
-59
lines changed

1 file changed

+40
-59
lines changed

hw/m68k/next-cube.c

Lines changed: 40 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -190,93 +190,74 @@ static void next_scr2_rtc_update(NeXTPC *s)
190190
if (rtc->phase < 8) {
191191
rtc->command = (rtc->command << 1) |
192192
((scr2_2 & SCR2_RTDATA) ? 1 : 0);
193-
}
194-
if (rtc->phase >= 8 && rtc->phase < 16) {
195-
if (next_rtc_cmd_is_write(rtc->command)) {
196-
/* Shift in value to write */
197-
rtc->value = (rtc->value << 1) |
198-
((scr2_2 & SCR2_RTDATA) ? 1 : 0);
199-
} else {
200-
/* Shift out value to read */
201193

202-
/* if we read RAM register, output RT_DATA bit */
203-
if (rtc->command <= 0x1F) {
204-
scr2_2 = scr2_2 & (~SCR2_RTDATA);
205-
if (rtc->ram[rtc->command] &
206-
(0x80 >> (rtc->phase - 8))) {
207-
scr2_2 |= SCR2_RTDATA;
208-
}
209-
210-
rtc->retval = (rtc->retval << 1) |
211-
((scr2_2 & SCR2_RTDATA) ? 1 : 0);
212-
}
213-
/* read the status 0x30 */
214-
if (rtc->command == 0x30) {
215-
scr2_2 = scr2_2 & (~SCR2_RTDATA);
216-
/* for now status = 0x98 (new rtc + FTU) */
217-
if (rtc->status & (0x80 >> (rtc->phase - 8))) {
218-
scr2_2 |= SCR2_RTDATA;
219-
}
220-
221-
rtc->retval = (rtc->retval << 1) |
222-
((scr2_2 & SCR2_RTDATA) ? 1 : 0);
223-
}
224-
/* read the status 0x31 */
225-
if (rtc->command == 0x31) {
226-
scr2_2 = scr2_2 & (~SCR2_RTDATA);
227-
if (rtc->control & (0x80 >> (rtc->phase - 8))) {
228-
scr2_2 |= SCR2_RTDATA;
229-
}
230-
rtc->retval = (rtc->retval << 1) |
231-
((scr2_2 & SCR2_RTDATA) ? 1 : 0);
194+
if (rtc->phase == 7 && !next_rtc_cmd_is_write(rtc->command)) {
195+
if (rtc->command <= 0x1f) {
196+
/* RAM registers */
197+
rtc->retval = rtc->ram[rtc->command];
232198
}
233-
234199
if ((rtc->command >= 0x20) && (rtc->command <= 0x2F)) {
235-
scr2_2 = scr2_2 & (~SCR2_RTDATA);
236-
/* for now 0x00 */
200+
/* RTC */
237201
time_t time_h = time(NULL);
238202
struct tm *info = localtime(&time_h);
239-
int ret = 0;
203+
rtc->retval = 0;
240204

241205
switch (rtc->command) {
242206
case 0x20:
243-
ret = SCR2_TOBCD(info->tm_sec);
207+
rtc->retval = SCR2_TOBCD(info->tm_sec);
244208
break;
245209
case 0x21:
246-
ret = SCR2_TOBCD(info->tm_min);
210+
rtc->retval = SCR2_TOBCD(info->tm_min);
247211
break;
248212
case 0x22:
249-
ret = SCR2_TOBCD(info->tm_hour);
213+
rtc->retval = SCR2_TOBCD(info->tm_hour);
250214
break;
251215
case 0x24:
252-
ret = SCR2_TOBCD(info->tm_mday);
216+
rtc->retval = SCR2_TOBCD(info->tm_mday);
253217
break;
254218
case 0x25:
255-
ret = SCR2_TOBCD((info->tm_mon + 1));
219+
rtc->retval = SCR2_TOBCD((info->tm_mon + 1));
256220
break;
257221
case 0x26:
258-
ret = SCR2_TOBCD((info->tm_year - 100));
222+
rtc->retval = SCR2_TOBCD((info->tm_year - 100));
259223
break;
260224
}
261-
262-
if (ret & (0x80 >> (rtc->phase - 8))) {
263-
scr2_2 |= SCR2_RTDATA;
264-
}
265-
rtc->retval = (rtc->retval << 1) |
266-
((scr2_2 & SCR2_RTDATA) ? 1 : 0);
225+
}
226+
if (rtc->command == 0x30) {
227+
/* read the status 0x30 */
228+
rtc->retval = rtc->status;
229+
}
230+
if (rtc->command == 0x31) {
231+
/* read the control 0x31 */
232+
rtc->retval = rtc->control;
233+
}
234+
}
235+
}
236+
if (rtc->phase >= 8 && rtc->phase < 16) {
237+
if (next_rtc_cmd_is_write(rtc->command)) {
238+
/* Shift in value to write */
239+
rtc->value = (rtc->value << 1) |
240+
((scr2_2 & SCR2_RTDATA) ? 1 : 0);
241+
} else {
242+
/* Shift out value to read */
243+
if (rtc->retval & (0x80 >> (rtc->phase - 8))) {
244+
scr2_2 |= SCR2_RTDATA;
245+
} else {
246+
scr2_2 &= ~SCR2_RTDATA;
267247
}
268248
}
269249
}
270250

271251
rtc->phase++;
272-
if (rtc->phase == 16) {
273-
if (rtc->command >= 0x80 && rtc->command <= 0x9F) {
252+
if (rtc->phase == 16 && next_rtc_cmd_is_write(rtc->command)) {
253+
if (rtc->command >= 0x80 && rtc->command <= 0x9f) {
254+
/* RAM registers */
274255
rtc->ram[rtc->command - 0x80] = rtc->value;
275256
}
276-
/* write to x30 register */
277-
if (rtc->command == 0xB1) {
278-
/* clear FTU */
257+
if (rtc->command == 0xb1) {
258+
/* write to 0x30 register */
279259
if (rtc->value & 0x04) {
260+
/* clear FTU */
280261
rtc->status = rtc->status & (~0x18);
281262
qemu_irq_lower(s->rtc_power_irq);
282263
}

0 commit comments

Comments
 (0)