|
|
| version 1.3, 2003/10/23 12:58:44 | version 1.7, 2004/02/09 20:39:39 |
|---|---|
| Line 5 | Line 5 |
| #include "timing.h" | #include "timing.h" |
| static UINT timercnt = 0; | #define MSSHIFT 16 |
| static UINT32 tick = 0; | |
| static UINT32 cnt = 0; | typedef struct { |
| UINT32 tick; | |
| UINT32 msstep; | |
| UINT cnt; | |
| UINT32 fraction; | |
| } TIMING; | |
| static TIMING timing; | |
| void timing_reset(void) { | void timing_reset(void) { |
| cnt = 0; | timing.tick = GETTICK(); |
| timercnt = 0; | timing.cnt = 0; |
| tick = GETTICK(); | timing.fraction = 0; |
| } | |
| void timing_setrate(UINT lines, UINT crthz) { | |
| timing.msstep = (crthz << (MSSHIFT - 3)) / lines / (1000 >> 3); | |
| } | } |
| void timing_setcount(UINT value) { | void timing_setcount(UINT value) { |
| timercnt = value; | timing.cnt = value; |
| } | } |
| UINT timing_getcount(void) { // ver0.12 60.0Hz вк 56.4Hz | UINT timing_getcount(void) { |
| UINT32 ticknow; | UINT32 ticknow; |
| UINT32 span; | UINT32 span; |
| UINT steps; | UINT32 fraction; |
| ticknow = GETTICK(); | ticknow = GETTICK(); |
| span = ticknow - tick; | span = ticknow - timing.tick; |
| if (span) { | if (span) { |
| timing.tick = ticknow; | |
| fddmtr_callback(ticknow); | fddmtr_callback(ticknow); |
| tick = ticknow; | if (span >= 1000) { |
| if (span < 1000) { | span = 1000; |
| cnt += (span * 388); | |
| steps = cnt / 6875; | |
| timercnt += steps; | |
| cnt -= (steps * 6875); | |
| } | |
| else { | |
| cnt = 0; | |
| timercnt += 56; | |
| } | } |
| fraction = timing.fraction + (span * timing.msstep); | |
| timing.cnt += fraction >> MSSHIFT; | |
| timing.fraction = fraction & ((1 << MSSHIFT) - 1); | |
| } | } |
| return(timercnt); | return(timing.cnt); |
| } | } |
| void timing_term(void) { | void timing_term(void) { |