1 | /*****************************************************************************\ |
---|---|
2 | Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. |
3 | This file is licensed under the Snes9x License. |
4 | For further information, consult the LICENSE file in the root directory. |
5 | \*****************************************************************************/ |
6 | |
7 | /***** |
8 | * S-RTC emulation code |
9 | * Copyright (c) byuu |
10 | *****/ |
11 | |
12 | |
13 | #include <limits> |
14 | |
15 | #include "snes9x.h" |
16 | #include "memmap.h" |
17 | #include "srtc.h" |
18 | #include "display.h" |
19 | |
20 | #define memory_cartrtc_read(a) RTCData.reg[(a)] |
21 | #define memory_cartrtc_write(a, b) { RTCData.reg[(a)] = (b); } |
22 | #define cpu_regs_mdr OpenBus |
23 | |
24 | static inline unsigned max (unsigned a, unsigned b) |
25 | { |
26 | return ((a > b) ? a : b); |
27 | } |
28 | |
29 | static inline unsigned min (unsigned a, unsigned b) |
30 | { |
31 | return ((a < b) ? a : b); |
32 | } |
33 | |
34 | #include "srtcemu.h" |
35 | #include "srtcemu.cpp" |
36 | |
37 | static SRTC srtcemu; |
38 | |
39 | |
40 | void S9xInitSRTC (void) |
41 | { |
42 | srtcemu.power(); |
43 | memset(RTCData.reg, 0, 20); |
44 | } |
45 | |
46 | void S9xResetSRTC (void) |
47 | { |
48 | srtcemu.reset(); |
49 | } |
50 | |
51 | void S9xSetSRTC (uint8 data, uint16 address) |
52 | { |
53 | srtcemu.mmio_write(address, data); |
54 | } |
55 | |
56 | uint8 S9xGetSRTC (uint16 address) |
57 | { |
58 | return (srtcemu.mmio_read(address)); |
59 | } |
60 | |
61 | void S9xSRTCPreSaveState (void) |
62 | { |
63 | srtcsnap.rtc_mode = (int32) srtcemu.rtc_mode; |
64 | srtcsnap.rtc_index = (int32) srtcemu.rtc_index; |
65 | } |
66 | |
67 | void S9xSRTCPostLoadState (int) |
68 | { |
69 | srtcemu.rtc_mode = (SRTC::RTC_Mode) srtcsnap.rtc_mode; |
70 | srtcemu.rtc_index = (signed) srtcsnap.rtc_index; |
71 | |
72 | srtcemu.update_time(); |
73 | } |
74 |