![]()
|
The PDF Version of this tutorial.
Imagine that when this dot turns red, that a function is being run.
That should give you a pretty good idea of what i'm talking about.

| IO Port | Counter # | Usage |
| 40h | Counter 0 | Timer/Disk |
| 41h | Counter 1 | Memory Refresh |
| 42h | Counter 2 | Tape Drive/Speaker |
| 43h | Control Register | Controlling timer functions |
000 00 000 0
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Function |
| Counting Method | ||||||||
| 0 | Count in binary | |||||||
| 1 | Count in BCD | |||||||
| Counter Mode | ||||||||
| 0 | 0 | 0 | Interrupt on terminal count | |||||
| 0 | 0 | 1 | Hardware retriggerable one-shot | |||||
| - | 1 | 0 | Rate Generator | |||||
| - | 1 | 1 | Square Wave | |||||
| 1 | 0 | 0 | Software retriggerable strobe | |||||
| 1 | 0 | 1 | Hardware retriggerable strobe | |||||
| Read and Write Control | ||||||||
| 1 | 0 | Counter latch operation | ||||||
| 0 | 1 | Read/Write least significant byte of counter | ||||||
| 1 | 0 | Read/Write most significant byte of counter | ||||||
| 1 | 1 | Read/Write least, then most, significant byte | ||||||
| Counter to be accessed for operation | ||||||||
| 0 | 0 | 0 | ||||||
| 0 | 1 | 1 | ||||||
| 1 | 0 | 2 | ||||||
| 1 | 1 | Illegal | ||||||
Located in Header file #define TIMERISR 0x1C #define LOW_BYTE(n) (n & 0x00ff) #define HIGH_BYTE(n) ((n>>8)&0x00ff) extern Timer_ISR(_go32_dpmi_registers*); _go32_dpmi_seginfo OldTimer,NewTimer; _go32_dpmi_registers timerregs; |
void ISRS::SetupTimerISR()
{ SetTimer=1;
_go32_dpmi_get_protected_mode_interrupt_vector(TIMERISR,&OldTimer);
NewTimer.pm_offset = (int)Timer_ISR;
NewTimer.pm_selector=_go32_my_cs();
_go32_dpmi_allocate_iret_wrapper(&NewTimer);
_go32_dpmi_set_protected_mode_interrupt_vector(TIMERISR,&NewTimer);
} |
Located in Header File #define TIMERISR 0x1C #define LOW_BYTE(n) (n & 0x00ff) #define HIGH_BYTE(n) ((n>>8)&0x00ff) extern void interrupt Timer_ISR(__CPPARGS); void interrupt (*Old_TIMERISR)(__CPPARGs); |
void ISRS::SetupTimerISR()
{ SetTimer=1;
Old_TIMERISR = _dos_getvect(TIMERISR);
_dos_setvect(TIMERISR,Timer_ISR);
}
|
void ISRS::SetTimerFrequency(float hz)
{
float base=1193180.0;
unsigned short word;
base/=hz;
byte=(unsigned short)base;
outp(0x43,0x3c);
outp(0x40, LOW_BYTE(word));
outp(0x40,HIGH_BYTE(word));
} |
void ISRS::ReturnISRS()
{
if(SetTimer)
{_go32_dpmi_set_protected_mode_interrupt_vector(TIMERISR,&OldTimer);
_go32_dpmi_free_iret_wrapper(&NewTimer);
outp(0x43,0x3c);
outp(0x40,LOW_BYTE(0xFFFF));
outp(0x40,HIGH_BYTE(0xFFFF));
}
}
|
void ISRS::ReturnISRS()
{
if(SetTimer)
{_dos_setvect(TIMERISR,Old_TIMERISR);
outp(0x43,0x3c);
outp(0x40,LOW_BYTE(0xFFFF));
outp(0x40,HIGH_BYTE(0xFFFF));
}
} |