viacuda: Fix get/set time and one sec modes.

The first packet the one sec mode should send is a mode 1 real time packet, same as GET_REAL_TIME.
A mode 2 packet is the same but doesn't include the time.
This commit is contained in:
joevt 2024-04-22 06:02:25 -07:00 committed by dingusdev
parent 2b76d8a53a
commit a22bc34816

View File

@ -95,7 +95,7 @@ ViaCuda::ViaCuda() {
.tm_mday = 1,
.tm_mon = 1 - 1,
.tm_year = 1904 - 1900,
.tm_isdst = -1 // Use DST value from local time zone
.tm_isdst = 1 // -1 = Use DST value from local time zone; 0 = not summer; 1 = is summer time
};
mac_epoch = std::chrono::system_clock::from_time_t(std::mktime(&tm));
}
@ -540,24 +540,24 @@ void ViaCuda::autopoll_handler() {
// draw guest system's attention
schedule_sr_int(USECS_TO_NSECS(30));
} else if (this->one_sec_mode == 3) {
} else if (this->one_sec_mode != 0) {
uint32_t this_time = calc_real_time();
if (this_time != this->last_time) {
if ((this->last_time & 15) == 0) {
/*
FIXME: This doesn't do anything in Mac OS 8.6.
A real Mac probably doesn't do this. So why do I?
supermario checks for packets that are not PKT_TICK
to set the time but I don't know which Mac OS versions
have that code and if that code is triggered by this.
*/
response_header(9, 0);
this->out_buf[3] = CUDA_GET_REAL_TIME;
uint32_t real_time = this_time + time_offset;
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
this->out_count = 7;
} else {
/*
We'll send a time packet every 4
seconds just in case we get out of
sync.
*/
bool send_time = !(this->last_time & 3);
if (send_time || this->one_sec_mode < 3) {
response_header(CUDA_PKT_PSEUDO, 0);
this->out_buf[2] = CUDA_GET_REAL_TIME;
if (send_time || this->one_sec_mode == 1) {
uint32_t real_time = this_time + this->time_offset;
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
this->out_count = 7;
}
} else if (this->one_sec_mode == 3) {
response_header(CUDA_PKT_TICK, 0);
this->out_count = 1;
}
@ -610,7 +610,7 @@ void ViaCuda::pseudo_command() {
case CUDA_GET_REAL_TIME: {
response_header(CUDA_PKT_PSEUDO, 0);
uint32_t this_time = this->calc_real_time();
uint32_t real_time = this_time + time_offset;
uint32_t real_time = this_time + this->time_offset;
WRITE_DWORD_BE_U(&this->out_buf[3], real_time);
this->out_count = 7;
break;