Mail Archives: djgpp/1998/04/07/19:46:05
Can anyone help me with the timer interrupt under DOS? I'm trying to
play a sample using the timer interupt on a Sound Blaster, but I have
a problem that I think is caused by my timer interrupt taking too long.
I have a 66Mhz 486, and whenever I reset the timer frequency to more
than about 10Khz it degrades system performance, at about 11KHz
brings the whole thing to a stand still. I'm sure I should be able
to call the timer interrupt at 11KHz, even 44Khz? (neccesary for higher
quality samples)
Here's the code I was using to set it up:
#include <stdio.h>
#include <go32.h>
#include <dpmi.h>
#include <dos.h>
#include <conio.h>
#define TIMERISR 0x1C
#define LOW_BYTE(n) (n & 0x00ff)
#define HIGH_BYTE(n) ((n>>8)&0x00ff)
long counter;
_go32_dpmi_seginfo OldTimer,NewTimer;
Timer_ISR(_go32_dpmi_registers*) {
counter += 1;
}
void SetupTimerISR()
{
// Record old timer interrupt
_go32_dpmi_get_protected_mode_interrupt_vector(TIMERISR,&OldTimer);
// Store new timer interrupt
NewTimer.pm_offset = (int)Timer_ISR;
NewTimer.pm_selector=_go32_my_cs();
// Set new timer interrupt
disable();
_go32_dpmi_allocate_iret_wrapper(&NewTimer);
_go32_dpmi_set_protected_mode_interrupt_vector(TIMERISR,&NewTimer);
enable();
}
void SetTimerFrequency(float hz)
{ //NOTE: Lowest frequency is 18.2 hz
float base=1193180.0;
unsigned byte;
base/=hz;
byte=(unsigned) base;
printf("Value of byte: %d, low: %d, high: %d\n",byte, LOW_BYTE(byte),
HIGH_BYTE(byte));
disable();
outp(0x43,0x3c);
outp(0x40, LOW_BYTE(byte));
outp(0x40,HIGH_BYTE(byte));
enable();
}
void ReturnISR()
{
// Reset interrupt to original value
disable();
_go32_dpmi_set_protected_mode_interrupt_vector(TIMERISR,&OldTimer);
_go32_dpmi_free_iret_wrapper(&NewTimer);
// Reset timer frequency to 18.2Hz
outp(0x43,0x3c);
outp(0x40,LOW_BYTE(0xFFFF));
outp(0x40,HIGH_BYTE(0xFFFF));
enable();
}
void main() {
long f = 100;
printf("Enter frequency (>18.2): ");
scanf("%ld",&f);
printf("Starting\n");
SetupTimerISR();
printf("Set up timer\n");
SetTimerFrequency(f);
printf("Reset timer frequency\n");
counter = 0;
getch();
ReturnISR();
printf("%d clicks counted\n",counter);
getch();
}
Any help with this would be greatly appreciated.
Thanks,
Josh.
- Raw text -