src/mess/video/coco6847.c
| r7249 | r7250 | |
| 1988 | 1988 | * |
| 1989 | 1989 | *************************************/ |
| 1990 | 1990 | |
| 1991 | | static UINT64 divide_mame_time(attotime dividend, attotime divisor) |
| 1992 | | { |
| 1993 | | /* TODO: it should not be necessary to use floating point here */ |
| 1994 | | double dividend_dbl = attotime_to_double(dividend); |
| 1995 | | double divisor_dbl = attotime_to_double(divisor); |
| 1996 | | return (UINT64) (dividend_dbl / divisor_dbl); |
| 1997 | | } |
| 1998 | | |
| 1999 | | |
| 2000 | | |
| 2001 | 1991 | static attotime interval(m6847_timing_type timing) |
| 2002 | 1992 | { |
| 2003 | 1993 | attotime result; |
| r7249 | r7250 | |
| 2019 | 2009 | |
| 2020 | 2010 | |
| 2021 | 2011 | |
| 2022 | | UINT64 coco6847_time(running_machine *machine, m6847_timing_type timing) |
| 2012 | attotime coco6847_time_delay(running_machine *machine, m6847_timing_type timing, UINT64 time_delay) |
| 2023 | 2013 | { |
| 2024 | | attotime current_time = timer_get_time(machine); |
| 2025 | | attotime divisor = interval(timing); |
| 2026 | | return divide_mame_time(current_time, divisor); |
| 2014 | return attotime_mul(interval(timing), time_delay); |
| 2027 | 2015 | } |
| 2028 | 2016 | |
| 2029 | 2017 | |
| 2030 | 2018 | |
| 2031 | | attotime coco6847_time_until(running_machine *machine, m6847_timing_type timing, UINT64 target_time) |
| 2032 | | { |
| 2033 | | attotime target_mame_time, current_time; |
| 2034 | | target_mame_time = attotime_mul(interval(timing), target_time); |
| 2035 | | current_time = timer_get_time(machine); |
| 2036 | | |
| 2037 | | if (attotime_compare(target_mame_time, current_time) < 0) |
| 2038 | | fatalerror("coco6847_time_until(): cannot target past times"); |
| 2039 | | |
| 2040 | | return attotime_sub(target_mame_time, current_time); |
| 2041 | | } |
| 2042 | | |
| 2043 | | |
| 2044 | | |
| 2045 | 2019 | attotime coco6847_scanline_time(int scanline) |
| 2046 | 2020 | { |
| 2047 | 2021 | return attotime_make(0, m6847->scanline_period * |
src/mess/video/m6847.c
| r7249 | r7250 | |
| 2195 | 2195 | return rc; |
| 2196 | 2196 | } |
| 2197 | 2197 | |
| 2198 | | |
| 2199 | | |
| 2200 | | /************************************* |
| 2201 | | * |
| 2202 | | * Timing calculations |
| 2203 | | * |
| 2204 | | *************************************/ |
| 2205 | | |
| 2206 | | static UINT64 divide_mame_time(attotime dividend, attotime divisor) |
| 2207 | | { |
| 2208 | | /* TODO: it should not be necessary to use floating point here */ |
| 2209 | | double dividend_dbl = attotime_to_double(dividend); |
| 2210 | | double divisor_dbl = attotime_to_double(divisor); |
| 2211 | | return (UINT64) (dividend_dbl / divisor_dbl); |
| 2212 | | } |
| 2213 | | |
| 2214 | | |
| 2215 | | |
| 2216 | | static attotime interval(running_device *device, m6847_timing_type timing) |
| 2217 | | { |
| 2218 | | mc6847_state *mc6847 = get_safe_token(device); |
| 2219 | | attotime result; |
| 2220 | | |
| 2221 | | switch(timing) |
| 2222 | | { |
| 2223 | | case M6847_CLOCK: |
| 2224 | | result = attotime_make(0, mc6847->clock_period); |
| 2225 | | break; |
| 2226 | | case M6847_HSYNC: |
| 2227 | | result = attotime_make(0, mc6847->scanline_period); |
| 2228 | | break; |
| 2229 | | default: |
| 2230 | | fatalerror("invalid timing type"); |
| 2231 | | break; |
| 2232 | | } |
| 2233 | | return result; |
| 2234 | | } |
| 2235 | | |
| 2236 | | |
| 2237 | | |
| 2238 | | UINT64 m6847_time(running_device *device, m6847_timing_type timing) |
| 2239 | | { |
| 2240 | | attotime current_time = timer_get_time(device->machine); |
| 2241 | | attotime divisor = interval(device, timing); |
| 2242 | | return divide_mame_time(current_time, divisor); |
| 2243 | | } |
| 2244 | | |
| 2245 | | |
| 2246 | | |
| 2247 | | attotime m6847_time_until(running_device *device, m6847_timing_type timing, UINT64 target_time) |
| 2248 | | { |
| 2249 | | attotime target_mame_time, current_time; |
| 2250 | | target_mame_time = attotime_mul(interval(device, timing), target_time); |
| 2251 | | current_time = timer_get_time(device->machine); |
| 2252 | | |
| 2253 | | if (attotime_compare(target_mame_time, current_time) < 0) |
| 2254 | | fatalerror("m6847_time_until(): cannot target past times"); |
| 2255 | | |
| 2256 | | return attotime_sub(target_mame_time, current_time); |
| 2257 | | } |
| 2258 | | |
| 2259 | | |
| 2260 | | |
| 2261 | | attotime m6847_scanline_time(running_device *device, int scanline) |
| 2262 | | { |
| 2263 | | mc6847_state *mc6847 = get_safe_token(device); |
| 2264 | | |
| 2265 | | return attotime_make(0, mc6847->scanline_period * |
| 2266 | | (13 /* FIXME */ + scanline)); |
| 2267 | | } |
| 2268 | | |
| 2269 | | |
| 2270 | | |
| 2271 | | /************************************* |
| 2272 | | * |
| 2273 | | * Hacks |
| 2274 | | * |
| 2275 | | *************************************/ |
| 2276 | | |
| 2277 | | #ifdef UNUSED_FUNCTION |
| 2278 | | void m6847_set_dirty(void) { set_dirty(); } |
| 2279 | | int m6847_get_scanline(void) { return get_scanline(); } |
| 2280 | | #endif |
| 2281 | | |
| 2282 | | int mc6847_get_scanline(running_device *device) |
| 2283 | | { |
| 2284 | | mc6847_state *mc6847 = get_safe_token(device); |
| 2285 | | return get_scanline(mc6847) - mc6847->top_border_scanlines; |
| 2286 | | } |
src/mess/video/m6847.h
| r7249 | r7250 | |
| 142 | 142 | |
| 143 | 143 | void mc6847_set_palette(running_device *device, UINT32 *palette); |
| 144 | 144 | |
| 145 | | /* hack for the coco until the 6883sam can be updated */ |
| 146 | | int mc6847_get_scanline(running_device *device); |
| 147 | | |
| 148 | | |
| 149 | 145 | void m6847_video_changed(void); |
| 150 | 146 | |
| 151 | | /* timing functions */ |
| 152 | | UINT64 m6847_time(running_device *device, m6847_timing_type timing); |
| 153 | | attotime m6847_time_until(running_device *device, m6847_timing_type timing, UINT64 target_time); |
| 154 | | |
| 155 | | /* CoCo 3 hooks */ |
| 156 | | attotime m6847_scanline_time(running_device *device, int scanline); |
| 157 | | |
| 158 | 147 | INPUT_PORTS_EXTERN( m6847_artifacting ); |
| 159 | 148 | |
| 160 | 149 | |
src/mess/machine/coco.c
| r7249 | r7250 | |
| 2183 | 2183 | static void coco3_timer_reset(running_machine *machine) |
| 2184 | 2184 | { |
| 2185 | 2185 | /* reset the timer; take the value stored in $FF94-5 and start the timer ticking */ |
| 2186 | | UINT64 current_time; |
| 2187 | 2186 | UINT16 timer_value; |
| 2188 | 2187 | m6847_timing_type timing; |
| 2189 | | attotime target_time; |
| 2188 | attotime delay_time; |
| 2190 | 2189 | |
| 2191 | 2190 | /* value is from 0-4095 */ |
| 2192 | 2191 | timer_value = ((coco3_gimereg[4] & 0x0F) * 0x100) | coco3_gimereg[5]; |
| r7249 | r7250 | |
| 2202 | 2201 | /* choose which timing clock source */ |
| 2203 | 2202 | timing = (coco3_gimereg[1] & 0x20) ? M6847_CLOCK : M6847_HSYNC; |
| 2204 | 2203 | |
| 2205 | | /* determine the current time */ |
| 2206 | | current_time = coco6847_time(machine, timing); |
| 2207 | | |
| 2208 | | /* calculate the time */ |
| 2209 | | target_time = coco6847_time_until(machine, timing, current_time + timer_value); |
| 2204 | /* determine the delay time */ |
| 2205 | delay_time = coco6847_time_delay(machine, timing, timer_value); |
| 2210 | 2206 | if (LOG_TIMER) |
| 2211 | | logerror("coco3_reset_timer(): target_time=%g\n", attotime_to_double(target_time)); |
| 2207 | logerror("coco3_reset_timer(): delay_time=%g\n", attotime_to_double(delay_time)); |
| 2212 | 2208 | |
| 2213 | 2209 | /* and adjust the timer */ |
| 2214 | | timer_adjust_oneshot(coco3_gime_timer, target_time, 0); |
| 2210 | timer_adjust_oneshot(coco3_gime_timer, delay_time, 0); |
| 2215 | 2211 | } |
| 2216 | 2212 | else |
| 2217 | 2213 | { |