trunk/src/osd/modules/lib/osdlib_macosx.c
| r242810 | r242811 | |
| 6 | 6 | |
| 7 | 7 | #include <mach/mach.h> |
| 8 | 8 | #include <mach/mach_time.h> |
| 9 | #include <mach/mach_traps.h> |
| 9 | 10 | #include <Carbon/Carbon.h> |
| 10 | 11 | |
| 11 | 12 | // MAME headers |
| 13 | #include "osdcore.h" |
| 12 | 14 | #include "osdlib.h" |
| 13 | 15 | |
| 16 | // FIXME: We shouldn't use SDL functions in here |
| 17 | |
| 18 | #include "sdlinc.h" |
| 19 | |
| 14 | 20 | //============================================================ |
| 15 | 21 | // osd_process_kill |
| 16 | 22 | //============================================================ |
| r242810 | r242811 | |
| 102 | 108 | { |
| 103 | 109 | return setenv(name, value, overwrite); |
| 104 | 110 | } |
| 111 | |
| 112 | //============================================================ |
| 113 | // PROTOTYPES |
| 114 | //============================================================ |
| 115 | |
| 116 | static osd_ticks_t init_cycle_counter(void); |
| 117 | static osd_ticks_t mach_cycle_counter(void); |
| 118 | |
| 119 | //============================================================ |
| 120 | // STATIC VARIABLES |
| 121 | //============================================================ |
| 122 | |
| 123 | static osd_ticks_t (*cycle_counter)(void) = init_cycle_counter; |
| 124 | static osd_ticks_t (*ticks_counter)(void) = init_cycle_counter; |
| 125 | static osd_ticks_t ticks_per_second; |
| 126 | |
| 127 | //============================================================ |
| 128 | // init_cycle_counter |
| 129 | // |
| 130 | // to avoid total grossness, this function is split by subarch |
| 131 | //============================================================ |
| 132 | |
| 133 | static osd_ticks_t init_cycle_counter(void) |
| 134 | { |
| 135 | osd_ticks_t start, end; |
| 136 | osd_ticks_t a, b; |
| 137 | |
| 138 | cycle_counter = mach_cycle_counter; |
| 139 | ticks_counter = mach_cycle_counter; |
| 140 | |
| 141 | // wait for an edge on the timeGetTime call |
| 142 | a = SDL_GetTicks(); |
| 143 | do |
| 144 | { |
| 145 | b = SDL_GetTicks(); |
| 146 | } while (a == b); |
| 147 | |
| 148 | // get the starting cycle count |
| 149 | start = (*cycle_counter)(); |
| 150 | |
| 151 | // now wait for 1/4 second total |
| 152 | do |
| 153 | { |
| 154 | a = SDL_GetTicks(); |
| 155 | } while (a - b < 250); |
| 156 | |
| 157 | // get the ending cycle count |
| 158 | end = (*cycle_counter)(); |
| 159 | |
| 160 | // compute ticks_per_sec |
| 161 | ticks_per_second = (end - start) * 4; |
| 162 | |
| 163 | // return the current cycle count |
| 164 | return (*cycle_counter)(); |
| 165 | } |
| 166 | |
| 167 | //============================================================ |
| 168 | // performance_cycle_counter |
| 169 | //============================================================ |
| 170 | |
| 171 | //============================================================ |
| 172 | // mach_cycle_counter |
| 173 | //============================================================ |
| 174 | static osd_ticks_t mach_cycle_counter(void) |
| 175 | { |
| 176 | return mach_absolute_time(); |
| 177 | } |
| 178 | |
| 179 | //============================================================ |
| 180 | // osd_cycles |
| 181 | //============================================================ |
| 182 | |
| 183 | osd_ticks_t osd_ticks(void) |
| 184 | { |
| 185 | return (*cycle_counter)(); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | //============================================================ |
| 190 | // osd_ticks_per_second |
| 191 | //============================================================ |
| 192 | |
| 193 | osd_ticks_t osd_ticks_per_second(void) |
| 194 | { |
| 195 | if (ticks_per_second == 0) |
| 196 | { |
| 197 | // if we haven't computed the value yet, there's no time like the present |
| 198 | init_cycle_counter(); |
| 199 | } |
| 200 | return ticks_per_second; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | |
| 205 | //============================================================ |
| 206 | // osd_sleep |
| 207 | //============================================================ |
| 208 | |
| 209 | void osd_sleep(osd_ticks_t duration) |
| 210 | { |
| 211 | UINT32 msec; |
| 212 | |
| 213 | // make sure we've computed ticks_per_second |
| 214 | if (ticks_per_second == 0) |
| 215 | (void)osd_ticks(); |
| 216 | |
| 217 | // convert to milliseconds, rounding down |
| 218 | msec = (UINT32)(duration * 1000 / ticks_per_second); |
| 219 | |
| 220 | // only sleep if at least 2 full milliseconds |
| 221 | if (msec >= 2) |
| 222 | { |
| 223 | // take a couple of msecs off the top for good measure |
| 224 | msec -= 2; |
| 225 | usleep(msec*1000); |
| 226 | } |
| 227 | } |
| 228 | |
trunk/src/osd/sdl/sdlos_macosx.c
| r242810 | r242811 | |
| 22 | 22 | // MAME headers |
| 23 | 23 | #include "osdcore.h" |
| 24 | 24 | |
| 25 | | //============================================================ |
| 26 | | // PROTOTYPES |
| 27 | | //============================================================ |
| 28 | 25 | |
| 29 | | static osd_ticks_t init_cycle_counter(void); |
| 30 | | static osd_ticks_t mach_cycle_counter(void); |
| 31 | | |
| 32 | 26 | //============================================================ |
| 33 | | // STATIC VARIABLES |
| 34 | | //============================================================ |
| 35 | | |
| 36 | | static osd_ticks_t (*cycle_counter)(void) = init_cycle_counter; |
| 37 | | static osd_ticks_t (*ticks_counter)(void) = init_cycle_counter; |
| 38 | | static osd_ticks_t ticks_per_second; |
| 39 | | |
| 40 | | //============================================================ |
| 41 | | // init_cycle_counter |
| 42 | | // |
| 43 | | // to avoid total grossness, this function is split by subarch |
| 44 | | //============================================================ |
| 45 | | |
| 46 | | static osd_ticks_t init_cycle_counter(void) |
| 47 | | { |
| 48 | | osd_ticks_t start, end; |
| 49 | | osd_ticks_t a, b; |
| 50 | | |
| 51 | | cycle_counter = mach_cycle_counter; |
| 52 | | ticks_counter = mach_cycle_counter; |
| 53 | | |
| 54 | | // wait for an edge on the timeGetTime call |
| 55 | | a = SDL_GetTicks(); |
| 56 | | do |
| 57 | | { |
| 58 | | b = SDL_GetTicks(); |
| 59 | | } while (a == b); |
| 60 | | |
| 61 | | // get the starting cycle count |
| 62 | | start = (*cycle_counter)(); |
| 63 | | |
| 64 | | // now wait for 1/4 second total |
| 65 | | do |
| 66 | | { |
| 67 | | a = SDL_GetTicks(); |
| 68 | | } while (a - b < 250); |
| 69 | | |
| 70 | | // get the ending cycle count |
| 71 | | end = (*cycle_counter)(); |
| 72 | | |
| 73 | | // compute ticks_per_sec |
| 74 | | ticks_per_second = (end - start) * 4; |
| 75 | | |
| 76 | | // return the current cycle count |
| 77 | | return (*cycle_counter)(); |
| 78 | | } |
| 79 | | |
| 80 | | //============================================================ |
| 81 | | // performance_cycle_counter |
| 82 | | //============================================================ |
| 83 | | |
| 84 | | //============================================================ |
| 85 | | // mach_cycle_counter |
| 86 | | //============================================================ |
| 87 | | static osd_ticks_t mach_cycle_counter(void) |
| 88 | | { |
| 89 | | return mach_absolute_time(); |
| 90 | | } |
| 91 | | |
| 92 | | //============================================================ |
| 93 | | // osd_cycles |
| 94 | | //============================================================ |
| 95 | | |
| 96 | | osd_ticks_t osd_ticks(void) |
| 97 | | { |
| 98 | | return (*cycle_counter)(); |
| 99 | | } |
| 100 | | |
| 101 | | |
| 102 | | //============================================================ |
| 103 | | // osd_ticks_per_second |
| 104 | | //============================================================ |
| 105 | | |
| 106 | | osd_ticks_t osd_ticks_per_second(void) |
| 107 | | { |
| 108 | | if (ticks_per_second == 0) |
| 109 | | { |
| 110 | | // if we haven't computed the value yet, there's no time like the present |
| 111 | | init_cycle_counter(); |
| 112 | | } |
| 113 | | return ticks_per_second; |
| 114 | | } |
| 115 | | |
| 116 | | |
| 117 | | |
| 118 | | //============================================================ |
| 119 | | // osd_sleep |
| 120 | | //============================================================ |
| 121 | | |
| 122 | | void osd_sleep(osd_ticks_t duration) |
| 123 | | { |
| 124 | | UINT32 msec; |
| 125 | | |
| 126 | | // make sure we've computed ticks_per_second |
| 127 | | if (ticks_per_second == 0) |
| 128 | | (void)osd_ticks(); |
| 129 | | |
| 130 | | // convert to milliseconds, rounding down |
| 131 | | msec = (UINT32)(duration * 1000 / ticks_per_second); |
| 132 | | |
| 133 | | // only sleep if at least 2 full milliseconds |
| 134 | | if (msec >= 2) |
| 135 | | { |
| 136 | | // take a couple of msecs off the top for good measure |
| 137 | | msec -= 2; |
| 138 | | usleep(msec*1000); |
| 139 | | } |
| 140 | | } |
| 141 | | |
| 142 | | |
| 143 | | //============================================================ |
| 144 | 27 | // osd_get_clipboard_text |
| 145 | 28 | //============================================================ |
| 146 | 29 | |