I found the closest Turbo C DOS timer source code written by David Oshinsky at:
http://www.bookcase.com/library/soft...s.turbo-c.html (TIMERTST)
Code:
To get my own timer (original Pascal port) I had to comment out asm{ int 1Ch;} & asm{pushf;} in NewInt08() function. Also I had to omit all debugging printfs in the interrupt functions. Afterwards my program doesn't crash anymore.
What am wondering is:
1. In Pascal version it uses inline($CD / $1C); & inline($9C); before the OldInt08() call. I though I could call the equivalent asm{ int 1Ch;} & asm{pushf;} but I guess this was wrong since it crashed my program. Is there an inline assembly call in C?
2. David's initializing the timer code uses
Code:
/* Set up 8259 PIC chip to allow INT0 interrupt. */
outportb(0x21, inportb(0x21) & 0xfe);
/* issue command to 8253: counter 0, binary counter, rate generator */
/* (mode 2), load least significant byte of counter followed by */
/* most significant byte */
outportb(0x43, 0x34);
/* Timer is set for 0x4cd * 813.8 ns = 1 ms (LSB followed by MSB). */
outportb(0x40, 0xcd); /* least significant byte of timer count */
outportb(0x40, 0x04); /* most significant byte of timer count */
But mine uses
Code:
outportb( 0x43, 0xb6);
outportb( 0x40, Count & 255);
outportb( 0x40, Count >> 8);
What is the difference? Even though both works.
3. Same goes for the clean up code:
His is:
Code:
/* restore 8253 to original state set during PC boot */
/* NOTE: this program leaves 8259 mask register with */
/* least significant bit clear (i.e., INT0 enabled). */
outportb(0x43, 0x34);
outportb(0x40, 0);
outportb(0x40, 0);
Mine is:
Code:
outportb( 0x43, 0xb6);
outportb( 0x40, 0xff);
outportb( 0x40, 0xff);
Again both works but I don't understand why different?