/[gxemul]/upstream/0.4.5.1/src/devices/dev_dreamcast_rtc.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.4.5.1/src/devices/dev_dreamcast_rtc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations)
Mon Oct 8 16:22:20 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 3542 byte(s)
0.4.5.1
1 /*
2 * Copyright (C) 2006-2007 Anders Gavare. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 * $Id: dev_dreamcast_rtc.c,v 1.3 2007/02/03 20:14:23 debug Exp $
29 *
30 * Dreamcast Real-Time Clock.
31 *
32 * Pretty basic; two 32-bit words at physical addresses 0x00710000 and
33 * 0x00710004 hold the high and low 16-bit parts, respectively, of the
34 * system's 32-bit tv_sec value.
35 *
36 * The only difference from the raw Unix concept is that the Dreamcast's
37 * clock is based at 1950 instead of 1970.
38 */
39
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <sys/time.h>
44
45 #include "cpu.h"
46 #include "device.h"
47 #include "machine.h"
48 #include "memory.h"
49 #include "misc.h"
50
51
52 /* #define debug fatal */
53
54 struct dreamcast_rtc_data {
55 int dummy;
56 };
57
58
59 DEVICE_ACCESS(dreamcast_rtc)
60 {
61 /* struct dreamcast_rtc_data *d =
62 (struct dreamcast_rtc_data *) extra; */
63 uint64_t idata = 0, odata = 0;
64 struct timeval tv;
65
66 if (writeflag == MEM_WRITE)
67 idata = memory_readmax64(cpu, data, len);
68
69 switch (relative_addr) {
70
71 case 0:
72 case 4:
73 if (writeflag == MEM_WRITE)
74 debug("[ dreamcast_rtc: Writes are ignored, only "
75 "reads are supported. ]\n");
76
77 gettimeofday(&tv, NULL);
78
79 /* Offset by 20 years: */
80 odata = tv.tv_sec + 631152000;
81
82 if (relative_addr == 0)
83 odata = (odata >> 16) & 0xffff;
84 else
85 odata &= 0xffff;
86 break;
87
88 default:if (writeflag == MEM_READ) {
89 fatal("[ dreamcast_rtc: read from addr 0x%x ]\n",
90 (int)relative_addr);
91 } else {
92 fatal("[ dreamcast_rtc: write to addr 0x%x: 0x%x ]\n",
93 (int)relative_addr, (int)idata);
94 }
95 }
96
97 if (writeflag == MEM_READ)
98 memory_writemax64(cpu, data, len, odata);
99
100 return 1;
101 }
102
103
104 DEVINIT(dreamcast_rtc)
105 {
106 struct machine *machine = devinit->machine;
107 struct dreamcast_rtc_data *d =
108 malloc(sizeof(struct dreamcast_rtc_data));
109 if (d == NULL) {
110 fprintf(stderr, "out of memory\n");
111 exit(1);
112 }
113 memset(d, 0, sizeof(struct dreamcast_rtc_data));
114
115 memory_device_register(machine->memory, devinit->name,
116 0x00710000, 0x100, dev_dreamcast_rtc_access, d, DM_DEFAULT, NULL);
117
118 return 1;
119 }
120

  ViewVC Help
Powered by ViewVC 1.1.26