diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-03-02 23:49:38 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-03-02 23:49:38 +0000 |
commit | 384de102469fee4e0792df8fe38586d3206774ed (patch) | |
tree | ee5342103e17738acfb8421328ea7c57433f55e6 /apps/plugins/rockboy/rtc.c | |
parent | 48dad47df98bdec632e8930b6a97359dc2c428f5 (diff) | |
download | rockbox-384de102469fee4e0792df8fe38586d3206774ed.tar.gz rockbox-384de102469fee4e0792df8fe38586d3206774ed.zip |
Rockboy - gameboy emulation for rockbox, based on gnuboy. Still a bit early, but already playable on iRiver H1xx and the simulators. The archos recorder version is currently rather slow...
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6104 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/rockboy/rtc.c')
-rw-r--r-- | apps/plugins/rockboy/rtc.c | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/apps/plugins/rockboy/rtc.c b/apps/plugins/rockboy/rtc.c new file mode 100644 index 0000000000..99e71dcfae --- /dev/null +++ b/apps/plugins/rockboy/rtc.c | |||
@@ -0,0 +1,135 @@ | |||
1 | |||
2 | |||
3 | |||
4 | #include "rockmacros.h" | ||
5 | #include <stdio.h> | ||
6 | |||
7 | #include "defs.h" | ||
8 | #include "mem.h" | ||
9 | #include "rtc.h" | ||
10 | #include "rc.h" | ||
11 | |||
12 | struct rtc rtc; | ||
13 | |||
14 | static int syncrtc = 1; | ||
15 | |||
16 | rcvar_t rtc_exports[] = | ||
17 | { | ||
18 | RCV_BOOL("syncrtc", &syncrtc), | ||
19 | RCV_END | ||
20 | }; | ||
21 | |||
22 | |||
23 | void rtc_latch(byte b) | ||
24 | { | ||
25 | if ((rtc.latch ^ b) & b & 1) | ||
26 | { | ||
27 | rtc.regs[0] = rtc.s; | ||
28 | rtc.regs[1] = rtc.m; | ||
29 | rtc.regs[2] = rtc.h; | ||
30 | rtc.regs[3] = rtc.d; | ||
31 | rtc.regs[4] = (rtc.d>>9) | (rtc.stop<<6) | (rtc.carry<<7); | ||
32 | rtc.regs[5] = 0xff; | ||
33 | rtc.regs[6] = 0xff; | ||
34 | rtc.regs[7] = 0xff; | ||
35 | } | ||
36 | rtc.latch = b; | ||
37 | } | ||
38 | |||
39 | void rtc_write(byte b) | ||
40 | { | ||
41 | /* printf("write %02X: %02X (%d)\n", rtc.sel, b, b); */ | ||
42 | if (!(rtc.sel & 8)) return; | ||
43 | switch (rtc.sel & 7) | ||
44 | { | ||
45 | case 0: | ||
46 | rtc.s = rtc.regs[0] = b; | ||
47 | while (rtc.s >= 60) rtc.s -= 60; | ||
48 | break; | ||
49 | case 1: | ||
50 | rtc.m = rtc.regs[1] = b; | ||
51 | while (rtc.m >= 60) rtc.m -= 60; | ||
52 | break; | ||
53 | case 2: | ||
54 | rtc.h = rtc.regs[2] = b; | ||
55 | while (rtc.h >= 24) rtc.h -= 24; | ||
56 | break; | ||
57 | case 3: | ||
58 | rtc.regs[3] = b; | ||
59 | rtc.d = (rtc.d & 0x100) | b; | ||
60 | break; | ||
61 | case 4: | ||
62 | rtc.regs[4] = b; | ||
63 | rtc.d = (rtc.d & 0xff) | ((b&1)<<9); | ||
64 | rtc.stop = (b>>6)&1; | ||
65 | rtc.carry = (b>>7)&1; | ||
66 | break; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | void rtc_tick() | ||
71 | { | ||
72 | if (rtc.stop) return; | ||
73 | if (++rtc.t == 60) | ||
74 | { | ||
75 | if (++rtc.s == 60) | ||
76 | { | ||
77 | if (++rtc.m == 60) | ||
78 | { | ||
79 | if (++rtc.h == 24) | ||
80 | { | ||
81 | if (++rtc.d == 365) | ||
82 | { | ||
83 | rtc.d = 0; | ||
84 | rtc.carry = 1; | ||
85 | } | ||
86 | rtc.h = 0; | ||
87 | } | ||
88 | rtc.m = 0; | ||
89 | } | ||
90 | rtc.s = 0; | ||
91 | } | ||
92 | rtc.t = 0; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | void rtc_save_internal(int fd) | ||
97 | { | ||
98 | (void)fd; // stop compiler complaining | ||
99 | // TODO | ||
100 | // fprintf(f, "%d %d %d %02d %02d %02d %02d\n%d\n", | ||
101 | // rtc.carry, rtc.stop, rtc.d, rtc.h, rtc.m, rtc.s, rtc.t, | ||
102 | // time(0)); | ||
103 | } | ||
104 | |||
105 | void rtc_load_internal(int fd) | ||
106 | { | ||
107 | //int rt = 0; | ||
108 | (void)fd; // stop compiler complaining | ||
109 | // TODO | ||
110 | /* fscanf( | ||
111 | f, "%d %d %d %02d %02d %02d %02d\n%d\n", | ||
112 | &rtc.carry, &rtc.stop, &rtc.d, | ||
113 | &rtc.h, &rtc.m, &rtc.s, &rtc.t, &rt); | ||
114 | while (rtc.t >= 60) rtc.t -= 60; | ||
115 | while (rtc.s >= 60) rtc.s -= 60; | ||
116 | while (rtc.m >= 60) rtc.m -= 60; | ||
117 | while (rtc.h >= 24) rtc.h -= 24; | ||
118 | while (rtc.d >= 365) rtc.d -= 365; | ||
119 | rtc.stop &= 1; | ||
120 | rtc.carry &= 1; | ||
121 | if (rt) rt = (time(0) - rt) * 60; | ||
122 | if (syncrtc) while (rt-- > 0) rtc_tick(); */ | ||
123 | } | ||
124 | |||
125 | |||
126 | |||
127 | |||
128 | |||
129 | |||
130 | |||
131 | |||
132 | |||
133 | |||
134 | |||
135 | |||