| 1 | /* Mednafen - Multi-system Emulator |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | */ |
| 17 | |
| 18 | #include "vb.h"cxx . . $ `<file>/mednafen/vb/vb.h`/ |
| 19 | #include "input.h"cxx . . $ `<file>/mednafen/vb/input.h`/ |
| 20 | |
| 21 | static bool InstantReadHackcxx . . $ InstantReadHack.; |
| 22 | |
| 23 | static bool IntPendingcxx . . $ IntPending.; |
| 24 | |
| 25 | static uint8cxx . . $ uint8# *data_ptrcxx . . $ data_ptr.; |
| 26 | |
| 27 | static uint16cxx . . $ uint16# PadDatacxx . . $ PadData.; |
| 28 | static uint16cxx . . $ uint16# PadLatchedcxx . . $ PadLatched.; |
| 29 | |
| 30 | static uint8cxx . . $ uint8# SCRcxx . . $ SCR.; |
| 31 | static uint16cxx . . $ uint16# SDRcxx . . $ SDR.; |
| 32 | |
| 33 | #define SCR_S_ABT_DIScxx . . $ `mednafen/vb/input.cpp:33:9`! 0x01 |
| 34 | #define SCR_SI_STATcxx . . $ `mednafen/vb/input.cpp:34:9`! 0x02 |
| 35 | #define SCR_HW_SIcxx . . $ `mednafen/vb/input.cpp:35:9`! 0x04 |
| 36 | #define SCR_SOFT_CLKcxx . . $ `mednafen/vb/input.cpp:36:9`! 0x10 |
| 37 | |
| 38 | #define SCR_PARA_SIcxx . . $ `mednafen/vb/input.cpp:38:9`! 0x20 |
| 39 | #define SCR_K_INT_INHcxx . . $ `mednafen/vb/input.cpp:39:9`! 0x80 |
| 40 | |
| 41 | static uint32cxx . . $ uint32# ReadBitPoscxx . . $ ReadBitPos.; |
| 42 | static int32cxx . . $ int32# ReadCountercxx . . $ ReadCounter.; |
| 43 | |
| 44 | static v810_timestamp_tcxx . . $ v810_timestamp_t# last_tscxx . . $ last_ts.; |
| 45 | |
| 46 | void VBINPUT_Initcxx . . $ VBINPUT_Init(49f6e7a06ebc5aa8).(void) |
| 47 | { |
| 48 | InstantReadHackcxx . . $ InstantReadHack. = true; |
| 49 | } |
| 50 | |
| 51 | void VBINPUT_SetInstantReadHackcxx . . $ VBINPUT_SetInstantReadHack(b45ddcbc8423892c).(bool enabled) |
| 52 | { |
| 53 | InstantReadHackcxx . . $ InstantReadHack. = enabled; |
| 54 | } |
| 55 | |
| 56 | void VBINPUT_SetInputcxx . . $ VBINPUT_SetInput(d29b3d01ccfd77ca).(int port, const char *type, void *ptr) |
| 57 | { |
| 58 | data_ptrcxx . . $ data_ptr. = (uint8cxx . . $ uint8# *)ptr; |
| 59 | } |
| 60 | |
| 61 | uint8cxx . . $ uint8# VBINPUT_Readcxx . . $ VBINPUT_Read(30bc2cfa027d42f8).(v810_timestamp_tcxx . . $ v810_timestamp_t# ×tamp, uint32cxx . . $ uint32# A) |
| 62 | { |
| 63 | uint8_tcxx . . $ uint8_t# ret = 0; |
| 64 | |
| 65 | VBINPUT_Updatecxx . . $ VBINPUT_Update(7864480464b09eea).(timestamp); |
| 66 | |
| 67 | switch(A & 0xFF) |
| 68 | { |
| 69 | case 0x10: |
| 70 | if(InstantReadHackcxx . . $ InstantReadHack.) |
| 71 | ret = PadDatacxx . . $ PadData.; |
| 72 | else |
| 73 | ret = SDRcxx . . $ SDR. & 0xFF; |
| 74 | break; |
| 75 | case 0x14: |
| 76 | if(InstantReadHackcxx . . $ InstantReadHack.) |
| 77 | ret = PadDatacxx . . $ PadData. >> 8; |
| 78 | else |
| 79 | ret = SDRcxx . . $ SDR. >> 8; |
| 80 | break; |
| 81 | case 0x28: |
| 82 | ret = SCRcxx . . $ SCR. | (0x40 | 0x08 | SCR_HW_SIcxx . . $ `mednafen/vb/input.cpp:35:9`!); |
| 83 | if(ReadCountercxx . . $ ReadCounter. > 0) |
| 84 | ret |= SCR_SI_STATcxx . . $ `mednafen/vb/input.cpp:34:9`!; |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | // printf("Input Read: %08x %02x\n", A, ret); |
| 89 | VB_SetEventcxx . . $ VB_SetEvent(3e454b8ccf442868).(VB_EVENT_INPUTcxx . . $ VB_EVENT_INPUT., (ReadCountercxx . . $ ReadCounter. > 0) ? (timestamp + ReadCountercxx . . $ ReadCounter.) : VB_EVENT_NONONOcxx . . $ `mednafen/vb/vb.h:26:9`!); |
| 90 | |
| 91 | return(ret); |
| 92 | } |
| 93 | |
| 94 | void VBINPUT_Writecxx . . $ VBINPUT_Write(b1c7ce297c54e4c4).(v810_timestamp_tcxx . . $ v810_timestamp_t# ×tamp, uint32cxx . . $ uint32# A, uint8cxx . . $ uint8# V) |
| 95 | { |
| 96 | VBINPUT_Updatecxx . . $ VBINPUT_Update(7864480464b09eea).(timestamp); |
| 97 | |
| 98 | //printf("Input write: %d, %08x %02x\n", timestamp, A, V); |
| 99 | switch(A & 0xFF) |
| 100 | { |
| 101 | case 0x28: |
| 102 | if((V & SCR_HW_SIcxx . . $ `mednafen/vb/input.cpp:35:9`!) && !(SCRcxx . . $ SCR. & SCR_S_ABT_DIScxx . . $ `mednafen/vb/input.cpp:33:9`!) && ReadCountercxx . . $ ReadCounter. <= 0) |
| 103 | { |
| 104 | //printf("Start Read: %d\n", timestamp); |
| 105 | PadLatchedcxx . . $ PadLatched. = PadDatacxx . . $ PadData.; |
| 106 | ReadBitPoscxx . . $ ReadBitPos. = 0; |
| 107 | ReadCountercxx . . $ ReadCounter. = 640; |
| 108 | } |
| 109 | |
| 110 | if(V & SCR_S_ABT_DIScxx . . $ `mednafen/vb/input.cpp:33:9`!) |
| 111 | { |
| 112 | ReadCountercxx . . $ ReadCounter. = 0; |
| 113 | ReadBitPoscxx . . $ ReadBitPos. = 0; |
| 114 | } |
| 115 | |
| 116 | if(V & SCR_K_INT_INHcxx . . $ `mednafen/vb/input.cpp:39:9`!) |
| 117 | { |
| 118 | IntPendingcxx . . $ IntPending. = false; |
| 119 | VBIRQ_Assertcxx . . $ VBIRQ_Assert(918ebd27a9ddbad3).(VBIRQ_SOURCE_INPUTcxx . . $ `mednafen/vb/vb.h:28:9`!, IntPendingcxx . . $ IntPending.); |
| 120 | } |
| 121 | |
| 122 | SCRcxx . . $ SCR. = V & (0x80 | 0x20 | 0x10 | 1); |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | VB_SetEventcxx . . $ VB_SetEvent(3e454b8ccf442868).(VB_EVENT_INPUTcxx . . $ VB_EVENT_INPUT., (ReadCountercxx . . $ ReadCounter. > 0) ? (timestamp + ReadCountercxx . . $ ReadCounter.) : VB_EVENT_NONONOcxx . . $ `mednafen/vb/vb.h:26:9`!); |
| 127 | } |
| 128 | |
| 129 | void VBINPUT_Framecxx . . $ VBINPUT_Frame(49f6e7a06ebc5aa8).(void) |
| 130 | { |
| 131 | PadDatacxx . . $ PadData. = (MDFN_de16lsb(data_ptrcxx . . $ data_ptr.) << 2) | 0x2; |
| 132 | } |
| 133 | |
| 134 | v810_timestamp_tcxx . . $ v810_timestamp_t# VBINPUT_Updatecxx . . $ VBINPUT_Update(7864480464b09eea).(const v810_timestamp_tcxx . . $ v810_timestamp_t# timestamp) |
| 135 | { |
| 136 | int32cxx . . $ int32# clocks = timestamp - last_tscxx . . $ last_ts.; |
| 137 | |
| 138 | if(ReadCountercxx . . $ ReadCounter. > 0) |
| 139 | { |
| 140 | ReadCountercxx . . $ ReadCounter. -= clocks; |
| 141 | |
| 142 | while(ReadCountercxx . . $ ReadCounter. <= 0) |
| 143 | { |
| 144 | SDRcxx . . $ SDR. &= ~(1 << ReadBitPoscxx . . $ ReadBitPos.); |
| 145 | SDRcxx . . $ SDR. |= PadLatchedcxx . . $ PadLatched. & (1 << ReadBitPoscxx . . $ ReadBitPos.); |
| 146 | |
| 147 | ReadBitPoscxx . . $ ReadBitPos.++; |
| 148 | if(ReadBitPoscxx . . $ ReadBitPos. < 16) |
| 149 | ReadCountercxx . . $ ReadCounter. += 640; |
| 150 | else |
| 151 | { |
| 152 | //printf("Read End: %d\n", timestamp); |
| 153 | if(!(SCRcxx . . $ SCR. & SCR_K_INT_INHcxx . . $ `mednafen/vb/input.cpp:39:9`!)) |
| 154 | { |
| 155 | //printf("Input IRQ: %d\n", timestamp); |
| 156 | IntPendingcxx . . $ IntPending. = true; |
| 157 | VBIRQ_Assertcxx . . $ VBIRQ_Assert(918ebd27a9ddbad3).(VBIRQ_SOURCE_INPUTcxx . . $ `mednafen/vb/vb.h:28:9`!, IntPendingcxx . . $ IntPending.); |
| 158 | } |
| 159 | break; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | } |
| 164 | |
| 165 | |
| 166 | last_tscxx . . $ last_ts. = timestamp; |
| 167 | |
| 168 | return((ReadCountercxx . . $ ReadCounter. > 0) ? (timestamp + ReadCountercxx . . $ ReadCounter.) : VB_EVENT_NONONOcxx . . $ `mednafen/vb/vb.h:26:9`!); |
| 169 | } |
| 170 | |
| 171 | void VBINPUT_ResetTScxx . . $ VBINPUT_ResetTS(49f6e7a06ebc5aa8).(void) |
| 172 | { |
| 173 | last_tscxx . . $ last_ts. = 0; |
| 174 | } |
| 175 | |
| 176 | void VBINPUT_Powercxx . . $ VBINPUT_Power(49f6e7a06ebc5aa8).(void) |
| 177 | { |
| 178 | last_tscxx . . $ last_ts. = 0; |
| 179 | PadDatacxx . . $ PadData. = 0; |
| 180 | PadLatchedcxx . . $ PadLatched. = 0; |
| 181 | SDRcxx . . $ SDR. = 0; |
| 182 | SCRcxx . . $ SCR. = 0; |
| 183 | ReadBitPoscxx . . $ ReadBitPos. = 0; |
| 184 | ReadCountercxx . . $ ReadCounter. = 0; |
| 185 | IntPendingcxx . . $ IntPending. = false; |
| 186 | |
| 187 | VBIRQ_Assertcxx . . $ VBIRQ_Assert(918ebd27a9ddbad3).(VBIRQ_SOURCE_INPUTcxx . . $ `mednafen/vb/vb.h:28:9`!, 0); |
| 188 | } |
| 189 | |
| 190 | int VBINPUT_StateActioncxx . . $ VBINPUT_StateAction(a45b884b8cf568d5).(StateMemcxx . . $ StateMem# *sm, int load, int data_only) |
| 191 | { |
| 192 | SFORMATcxx . . $ SFORMAT# StateRegs[] = |
| 193 | { |
| 194 | SFVARcxx . . $ `mednafen/state.h:72:9`!(PadData), |
| 195 | SFVARcxx . . $ `mednafen/state.h:72:9`!(PadLatched), |
| 196 | SFVARcxx . . $ `mednafen/state.h:72:9`!(SCR), |
| 197 | SFVARcxx . . $ `mednafen/state.h:72:9`!(SDR), |
| 198 | SFVARcxx . . $ `mednafen/state.h:72:9`!(ReadBitPos), |
| 199 | SFVARcxx . . $ `mednafen/state.h:72:9`!(ReadCounter), |
| 200 | SFVARcxx . . $ `mednafen/state.h:72:9`!(IntPending), |
| 201 | SFENDcxx . . $ `mednafen/state.h:96:9`! |
| 202 | }; |
| 203 | |
| 204 | int ret = MDFNSS_StateActioncxx . . $ MDFNSS_StateAction(3f628545d3b0df83).(sm, load, data_only, StateRegs, "INPUT"); |
| 205 | |
| 206 | if(load) |
| 207 | { |
| 208 | |
| 209 | } |
| 210 | |
| 211 | return(ret); |
| 212 | } |