| 1 | /* Cygne |
| 2 | * |
| 3 | * Copyright notice for this file: |
| 4 | * Copyright (C) 2002 Dox [email protected] |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <time.h> |
| 22 | |
| 23 | #include "wswan.h"cxx . . $ `<file>/mednafen/wswan/wswan.h`/ |
| 24 | |
| 25 | #include "../state.h"cxx . . $ `<file>/mednafen/state.h`/ |
| 26 | |
| 27 | static uint64cxx . . $ uint64# CurrentTimecxx . . $ CurrentTime.; |
| 28 | static uint32cxx . . $ uint32# ClockCycleCountercxx . . $ ClockCycleCounter.; |
| 29 | static uint8cxx . . $ uint8# wsCA15cxx . . $ wsCA15.; |
| 30 | static uint8cxx . . $ uint8# Commandcxx . . $ Command., Datacxx . . $ Data.; |
| 31 | |
| 32 | void WSwan_RTCWritecxx . . $ WSwan_RTCWrite(cc289a6b3dfc48da).(uint32cxx . . $ uint32# A, uint8cxx . . $ uint8# V) |
| 33 | { |
| 34 | switch(A) |
| 35 | { |
| 36 | case 0xca: |
| 37 | if(V==0x15) |
| 38 | wsCA15cxx . . $ wsCA15.=0; |
| 39 | Commandcxx . . $ Command. = V; |
| 40 | break; |
| 41 | case 0xcb: |
| 42 | Datacxx . . $ Data. = V; |
| 43 | break; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | uint8cxx . . $ uint8# WSwan_RTCReadcxx . . $ WSwan_RTCRead(32407b39b2dfce37).(uint32cxx . . $ uint32# A) |
| 48 | { |
| 49 | time_tcxx . . $ time_t# long_time; |
| 50 | struct tmcxx . . $ tm# *newtime; |
| 51 | |
| 52 | switch(A) |
| 53 | { |
| 54 | case 0xca: |
| 55 | return (Commandcxx . . $ Command.|0x80); |
| 56 | case 0xcb: |
| 57 | if(Commandcxx . . $ Command. != 0x15) |
| 58 | return Datacxx . . $ Data. | 0x80; |
| 59 | |
| 60 | long_time = CurrentTimecxx . . $ CurrentTime.; |
| 61 | newtime = gmtimecxx . . $ gmtime(9477a1348abbbc5).( &long_time ); |
| 62 | |
| 63 | switch(wsCA15cxx . . $ wsCA15.) |
| 64 | { |
| 65 | case 0: |
| 66 | wsCA15cxx . . $ wsCA15.++; |
| 67 | return mBCDcxx . . $ `mednafen/wswan/wswan.h:20:10`!(newtime->tm_year-100); |
| 68 | case 1: |
| 69 | wsCA15cxx . . $ wsCA15.++; |
| 70 | return mBCDcxx . . $ `mednafen/wswan/wswan.h:20:10`!(newtime->tm_mon); |
| 71 | case 2: |
| 72 | wsCA15cxx . . $ wsCA15.++; |
| 73 | return mBCDcxx . . $ `mednafen/wswan/wswan.h:20:10`!(newtime->tm_mday); |
| 74 | case 3: |
| 75 | wsCA15cxx . . $ wsCA15.++; |
| 76 | return mBCDcxx . . $ `mednafen/wswan/wswan.h:20:10`!(newtime->tm_wday); |
| 77 | case 4: |
| 78 | wsCA15cxx . . $ wsCA15.++; |
| 79 | return mBCDcxx . . $ `mednafen/wswan/wswan.h:20:10`!(newtime->tm_hour); |
| 80 | case 5: |
| 81 | wsCA15cxx . . $ wsCA15.++; |
| 82 | return mBCDcxx . . $ `mednafen/wswan/wswan.h:20:10`!(newtime->tm_min); |
| 83 | case 6: |
| 84 | wsCA15cxx . . $ wsCA15.=0; |
| 85 | return mBCDcxx . . $ `mednafen/wswan/wswan.h:20:10`!(newtime->tm_sec); |
| 86 | } |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | void WSwan_RTCResetcxx . . $ WSwan_RTCReset(49f6e7a06ebc5aa8).(void) |
| 94 | { |
| 95 | time_tcxx . . $ time_t# happy_time = timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 96 | |
| 97 | CurrentTimecxx . . $ CurrentTime. = mktimecxx . . $ mktime(237c3516b2cfac2c).(localtimecxx . . $ localtime(9477a1348abbbc5).(&happy_time)); |
| 98 | ClockCycleCountercxx . . $ ClockCycleCounter. = 0; |
| 99 | wsCA15cxx . . $ wsCA15. = 0; |
| 100 | } |
| 101 | |
| 102 | void WSwan_RTCClockcxx . . $ WSwan_RTCClock(cb2f890c2fdad230).(uint32cxx . . $ uint32# cycles) |
| 103 | { |
| 104 | ClockCycleCountercxx . . $ ClockCycleCounter. += cycles; |
| 105 | while(ClockCycleCountercxx . . $ ClockCycleCounter. >= 3072000) |
| 106 | { |
| 107 | ClockCycleCountercxx . . $ ClockCycleCounter. -= 3072000; |
| 108 | CurrentTimecxx . . $ CurrentTime.++; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | int WSwan_RTCStateActioncxx . . $ WSwan_RTCStateAction(a45b884b8cf568d5).(StateMemcxx . . $ StateMem# *sm, int load, int data_only) |
| 113 | { |
| 114 | SFORMATcxx . . $ SFORMAT# StateRegs[] = |
| 115 | { |
| 116 | { &(CurrentTimecxx . . $ CurrentTime.), (uint32_tcxx . . $ uint32_t#)sizeof(CurrentTimecxx . . $ CurrentTime.), MDFNSTATE_RLSBcxx . . $ `mednafen/state.h:26:9`!, "CurrentTime" }, |
| 117 | { &(ClockCycleCountercxx . . $ ClockCycleCounter.), (uint32_tcxx . . $ uint32_t#)sizeof(ClockCycleCountercxx . . $ ClockCycleCounter.), MDFNSTATE_RLSBcxx . . $ `mednafen/state.h:26:9`!, "ClockCycleCounter" }, |
| 118 | { &(wsCA15cxx . . $ wsCA15.), (uint32_tcxx . . $ uint32_t#)sizeof(wsCA15cxx . . $ wsCA15.), MDFNSTATE_RLSBcxx . . $ `mednafen/state.h:26:9`!, "wsCA15" }, |
| 119 | { &(Commandcxx . . $ Command.), (uint32_tcxx . . $ uint32_t#)sizeof(Commandcxx . . $ Command.), MDFNSTATE_RLSBcxx . . $ `mednafen/state.h:26:9`!, "Command" }, |
| 120 | { &(Datacxx . . $ Data.), (uint32_tcxx . . $ uint32_t#)sizeof(Datacxx . . $ Data.), MDFNSTATE_RLSBcxx . . $ `mednafen/state.h:26:9`!, "Data" }, |
| 121 | { 0, 0, 0, 0 } |
| 122 | }; |
| 123 | |
| 124 | if(!MDFNSS_StateActioncxx . . $ MDFNSS_StateAction(3f628545d3b0df83).(sm, load, data_only, StateRegs, "RTC", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!)) |
| 125 | return 0; |
| 126 | return 1; |
| 127 | } |