From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
Laurent Vivier <laurent@vivier.eu>
Subject: [PULL 6/7] mac_via: fix 60Hz VIA1 timer interval
Date: Tue, 16 Mar 2021 22:16:30 +0100 [thread overview]
Message-ID: <20210316211631.107417-7-laurent@vivier.eu> (raw)
In-Reply-To: <20210316211631.107417-1-laurent@vivier.eu>
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
The 60Hz timer is initialised using timer_new_ns() meaning that the timer
interval should be measured in ns, and therefore its period is a thousand
times too short.
Use a define for the 60Hz timer period taking the more precise value as
documented in the Guide To The Macintosh Family Hardware.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: BALATON Zoltan <balaton@eik.bme.hu>
Message-Id: <20210311100505.22596-7-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
hw/misc/mac_via.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
index 9617e04f02ef..36e70674feda 100644
--- a/hw/misc/mac_via.c
+++ b/hw/misc/mac_via.c
@@ -279,6 +279,12 @@
#define VIA_TIMER_FREQ (783360)
#define VIA_ADB_POLL_FREQ 50 /* XXX: not real */
+/*
+ * Guide to the Macintosh Family Hardware ch. 12 "Displays" p. 401 gives the
+ * precise 60Hz interrupt frequency as ~60.15Hz with a period of 16625.8 us
+ */
+#define VIA_60HZ_TIMER_PERIOD_NS 16625800
+
/* VIA returns time offset from Jan 1, 1904, not 1970 */
#define RTC_OFFSET 2082844800
@@ -302,8 +308,9 @@ static void via1_sixty_hz_update(MOS6522Q800VIA1State *v1s)
MOS6522State *s = MOS6522(v1s);
/* 60 Hz irq */
- v1s->next_sixty_hz = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 16630) /
- 16630 * 16630;
+ v1s->next_sixty_hz = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
+ VIA_60HZ_TIMER_PERIOD_NS) /
+ VIA_60HZ_TIMER_PERIOD_NS * VIA_60HZ_TIMER_PERIOD_NS;
if (s->ier & VIA1_IRQ_60HZ) {
timer_mod(v1s->sixty_hz_timer, v1s->next_sixty_hz);
--
2.30.2
next prev parent reply other threads:[~2021-03-16 21:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 21:16 [PULL 0/7] Q800 for 6.0 patches Laurent Vivier
2021-03-16 21:16 ` [PULL 1/7] mac_via: switch rtc pram trace-events to use hex rather than decimal for addresses Laurent Vivier
2021-03-16 21:16 ` [PULL 2/7] mac_via: fix up adb_via_receive() trace events Laurent Vivier
2021-03-16 21:16 ` [PULL 3/7] mac_via: allow long accesses to VIA registers Laurent Vivier
2021-03-16 21:16 ` [PULL 4/7] mac_via: don't re-inject ADB response when switching to IDLE state Laurent Vivier
2021-03-16 21:16 ` [PULL 5/7] mac_via: rename VBL timer to 60Hz timer Laurent Vivier
2021-03-16 21:16 ` Laurent Vivier [this message]
2021-03-16 21:16 ` [PULL 7/7] mac_via: remove VIA1 timer optimisations Laurent Vivier
2021-03-18 11:13 ` [PULL 0/7] Q800 for 6.0 patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210316211631.107417-7-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).