diff options
Diffstat (limited to 'src/glut/dos/PC_HW')
-rw-r--r-- | src/glut/dos/PC_HW/pc_timer.c | 208 |
1 files changed, 106 insertions, 102 deletions
diff --git a/src/glut/dos/PC_HW/pc_timer.c b/src/glut/dos/PC_HW/pc_timer.c index f11917db1aa..530ed72a493 100644 --- a/src/glut/dos/PC_HW/pc_timer.c +++ b/src/glut/dos/PC_HW/pc_timer.c @@ -1,5 +1,5 @@ /* - * PC/HW routine collection v1.4 for DOS/DJGPP + * PC/HW routine collection v1.5 for DOS/DJGPP * * Copyright (C) 2002 - Borca Daniel * Email : [email protected] @@ -93,106 +93,6 @@ void pc_remove_timer (void) -/* Desc: install timer engine - * - * In : - - * Out : 0 for success - * - * Note: initial frequency is 18.2 Hz - */ -static int install_timer (void) -{ - if (timer_installed || pc_install_irq(TIMER_IRQ, timer)) { - return -1; - } else { - memset(timer_func, 0, sizeof(timer_func)); - - LOCKDATA(timer_func); - LOCKDATA(timer_main); - LOCKFUNC(timer); - - timer_main.counter = 0x10000; - - DISABLE(); - outportb(0x43, 0x34); - outportb(0x40, 0); - outportb(0x40, 0); - timer_main.clock_ticks = 0; - ENABLE(); - - pc_atexit(pc_remove_timer); - timer_installed = TRUE; - return 0; - } -} - - - -/* Desc: install timerfunc - * - * In : callback function, opaque pointer to be passed to callee, freq (Hz) - * Out : timerfunc id (0 .. MAX_TIMERS-1) - * - * Note: returns -1 if error - */ -int pc_install_int (PFUNC func, void *parm, unsigned int freq) -{ - int i; - TIMER *t = NULL; - - /* ensure the timer engine is set up */ - if (!timer_installed) { - if (install_timer()) { - return -1; - } - } - - /* find an empty slot */ - for (i = 0; i < MAX_TIMERS; i++) { - if (!timer_func[i].func) { - t = &timer_func[i]; - break; - } - } - if (t == NULL) { - return -1; - } - - DISABLE(); - - t->func = func; - t->parm = parm; - t->freq = freq; - t->clock_ticks = 0; - - /* update main timer / sons to match highest frequency */ - if (freq > timer_main.freq) { - unsigned int new_counter = PIT_FREQ / freq; - - for (i = 0; i < MAX_TIMERS; i++) { - if (timer_func[i].func) { - ADJUST(timer_func[i], freq); - } - } - - outportb(0x43, 0x34); - outportb(0x40, (unsigned char)new_counter); - outportb(0x40, (unsigned char)(new_counter>>8)); - timer_main.clock_ticks = 0; - timer_main.counter = new_counter; - timer_main.freq = freq; - } else { - /* t == &timer_func[i] */ - ADJUST(timer_func[i], timer_main.freq); - } - - ENABLE(); - - return t - timer_func; -} - - - /* Desc: remove timerfunc * * In : timerfunc id @@ -255,7 +155,7 @@ int pc_remove_int (int fid) } return 0; -} +} ENDOFUNC(pc_remove_int) @@ -320,4 +220,108 @@ int pc_adjust_int (int fid, unsigned int freq) ENABLE(); return 0; +} ENDOFUNC(pc_adjust_int) + + + +/* Desc: install timer engine + * + * In : - + * Out : 0 for success + * + * Note: initial frequency is 18.2 Hz + */ +static int install_timer (void) +{ + if (timer_installed || pc_install_irq(TIMER_IRQ, timer)) { + return -1; + } else { + memset(timer_func, 0, sizeof(timer_func)); + + LOCKDATA(timer_func); + LOCKDATA(timer_main); + LOCKFUNC(timer); + LOCKFUNC(pc_adjust_int); + LOCKFUNC(pc_remove_int); + + timer_main.counter = 0x10000; + + DISABLE(); + outportb(0x43, 0x34); + outportb(0x40, 0); + outportb(0x40, 0); + timer_main.clock_ticks = 0; + ENABLE(); + + pc_atexit(pc_remove_timer); + timer_installed = TRUE; + return 0; + } +} + + + +/* Desc: install timerfunc + * + * In : callback function, opaque pointer to be passed to callee, freq (Hz) + * Out : timerfunc id (0 .. MAX_TIMERS-1) + * + * Note: returns -1 if error + */ +int pc_install_int (PFUNC func, void *parm, unsigned int freq) +{ + int i; + TIMER *t = NULL; + + /* ensure the timer engine is set up */ + if (!timer_installed) { + if (install_timer()) { + return -1; + } + } + + /* find an empty slot */ + for (i = 0; i < MAX_TIMERS; i++) { + if (!timer_func[i].func) { + t = &timer_func[i]; + break; + } + } + if (t == NULL) { + return -1; + } + + DISABLE(); + + t->func = func; + t->parm = parm; + t->freq = freq; + t->clock_ticks = 0; + + /* update main timer / sons to match highest frequency */ + if (freq > timer_main.freq) { + unsigned int new_counter = PIT_FREQ / freq; + + for (i = 0; i < MAX_TIMERS; i++) { + if (timer_func[i].func) { + ADJUST(timer_func[i], freq); + } + } + + outportb(0x43, 0x34); + outportb(0x40, (unsigned char)new_counter); + outportb(0x40, (unsigned char)(new_counter>>8)); + timer_main.clock_ticks = 0; + timer_main.counter = new_counter; + timer_main.freq = freq; + } else { + /* t == &timer_func[i] */ + ADJUST(timer_func[i], timer_main.freq); + } + + i = t - timer_func; + + ENABLE(); + + return i; } |