summaryrefslogtreecommitdiff
path: root/emulators/qemu0/patches/patch-ba
blob: da2ac773509775ca01121f13150e3593b5275aea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$NetBSD: patch-ba,v 1.1 2012/06/07 21:35:37 ryoon Exp $

--- hw/pcspk.c.orig	2011-08-08 18:28:42 +0000
+++ hw/pcspk.c
@@ -42,7 +42,6 @@ typedef struct {
     unsigned int samples;
     unsigned int play_pos;
     int data_on;
-    int dummy_refresh_clock;
 } PCSpkState;
 
 static const char *s_spk = "pcspk";
@@ -112,15 +111,31 @@ int pcspk_audio_init(qemu_irq *pic)
     return 0;
 }
 
+/*
+ * Emulate the speaker port's refresh clock bit.  This is supposed
+ * to toggle between 0 and 1<<4 every 15 microseconds.  XXX: We use
+ * gettimeofday() in the real machine instead of a monotonic clock
+ * in the virtual machine, and we are a bit sloppy about the 15
+ * microseconds.  This should be good enough for crude loops that
+ * measure approximate delays by counting how often this line toggles.
+ */
+static uint32_t pcspk_dummy_refresh_clock(void)
+{
+    struct timeval tv;
+
+    gettimeofday(&tv, NULL);
+    return ((tv.tv_sec ^ (tv.tv_usec / 15)) & 1) << 4;
+}
+
 static uint32_t pcspk_ioport_read(void *opaque, uint32_t addr)
 {
     PCSpkState *s = opaque;
     int out;
 
-    s->dummy_refresh_clock ^= (1 << 4);
     out = pit_get_out(s->pit, 2, qemu_get_clock_ns(vm_clock)) << 5;
 
-    return pit_get_gate(s->pit, 2) | (s->data_on << 1) | s->dummy_refresh_clock | out;
+    return pit_get_gate(s->pit, 2) | (s->data_on << 1) |
+	pcspk_dummy_refresh_clock() | out;
 }
 
 static void pcspk_ioport_write(void *opaque, uint32_t addr, uint32_t val)