summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/macseconds.cpp
diff options
context:
space:
mode:
author arbee <rb6502@users.noreply.github.com>2025-07-12 22:11:46 -0400
committer arbee <rb6502@users.noreply.github.com>2025-07-12 22:11:46 -0400
commitcc5af07c4cc6ceeb2d87f9a538c63f1f96d38964 (patch)
treea4ce28d1fc083e7d9bd6815586bfbb7b559f01e7 /src/devices/machine/macseconds.cpp
parent7d063545d63b492577eb156dff8b1ff62c249221 (diff)
machine/macseconds.cpp: mix-in to consolidate all of the copy-pastes of the Mac-style time generation. [R. Belmont]
* Also restored the clocks syncing to the local time zone rather than GMT. m6502/m5074x.cpp: Make external IRQs edge-triggered as documented for the M5074x and M5075x. [R. Belmont] apple/macprtb.cpp: Properly ack the VBL interrupt to the microcontroller. Fixes the one-second IRQ. [R. Belmont] * This fixes the Alarm Clock desk accessory so it updates every second on the Portable and PowerBook 100.
Diffstat (limited to 'src/devices/machine/macseconds.cpp')
-rw-r--r--src/devices/machine/macseconds.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/devices/machine/macseconds.cpp b/src/devices/machine/macseconds.cpp
new file mode 100644
index 00000000000..7ed18bc69f4
--- /dev/null
+++ b/src/devices/machine/macseconds.cpp
@@ -0,0 +1,56 @@
+// license:BSD-3-Clause
+// copyright-holders:R. Belmont
+/*
+ Classic Mac time converter mix-in
+ by R. Belmont
+
+ This is a mix-in for anything wanting to convert MAME time to the classic Mac time format
+ (seconds since 1/1/1904 at midnight).
+*/
+
+#include "dirtc.h"
+
+#include "emu.h"
+#include "macseconds.h"
+
+macseconds_interface::macseconds_interface()
+{
+ // Get the current time to get the DST flag and compute the offset from GMT
+ const time_t cur_time_t = time(NULL);
+ struct tm *local_tm = localtime(&cur_time_t);
+ struct tm *gmt_tm = gmtime(&cur_time_t);
+
+ // Sync DST
+ m_is_dst = gmt_tm->tm_isdst = local_tm->tm_isdst;
+
+ // MSYS2 struct tm doesn't have tm_gmtoff, so we calculate the offset the long way
+ m_gmt_offset = mktime(local_tm) - mktime(gmt_tm);
+}
+
+macseconds_interface::~macseconds_interface()
+{
+}
+
+u32 macseconds_interface::get_local_seconds(system_time &systime)
+{
+ const system_time::full_time &time = systime.local_time;
+
+ return get_seconds(time.year - 2000, time.month + 1, time.mday, time.weekday + 1, time.hour,
+ time.minute, time.second);
+}
+
+u32 macseconds_interface::get_seconds(int year, int month, int day, int day_of_week, int hour, int minute, int second)
+{
+ struct tm cur_time;
+
+ cur_time.tm_sec = second;
+ cur_time.tm_min = minute;
+ cur_time.tm_hour = hour;
+ cur_time.tm_mday = day;
+ cur_time.tm_mon = month - 1; // tm_mon is 0-based
+ cur_time.tm_year = year + 100; // tm_year is years since 1900
+ cur_time.tm_isdst = m_is_dst;
+
+ // Add the offset between the Unix epoch and the classic Mac OS epoch (hat tip to https://www.epochconverter.com/mac)
+ return static_cast<u32>(mktime(&cur_time) + (2082844800 + m_gmt_offset));
+}