home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,594 of 2,978   
   Rod Pemberton to All   
   Re: High Speed IRQ Timer/Clock in C (1/2   
   28 Dec 07 13:05:15   
   
   7da373e0   
   XPost: comp.lang.c, comp.lang.c++, openwatcom.users.c_cpp   
   From: do_not_have@nohavenot.cmm   
      
   "Andrew Wan"  wrote in message   
   news:45a18aca-02dc-44ec-b9cc-d6f7b9e90c4c@x69g2000hsx.googlegroups.com...   
      
   Dropped comp.lang.c++, openwatcom.users.c_cpp NG's.  Francis Glassborow   
   posted to   
   comp.lang.learn.c-c++,alt.lang.asm,alt.msdos.programmer,comp.os.msdos.progra   
   mmer NG's, so you may get some responses on those too.   
      
   The code is very close to compiling for OpenWatcom.  Mostly some incorrect   
   keywords, wrong location for keywords, and differently named environment   
   specific functions...  You should replace the "Static", "boolean", "Void"   
   etc. with the correct text instead of using the #define's like I did below.   
   Many of the functions have K&R style void arg's, e.g., the () in "Static   
   Void IrqOn()".  These should be reworked to "Static Void IrqOn(void)".  You   
   should replace the C++ comments // with C comments /* */ or #if 0 #endif.   
   Once you get it compile, if it doesn't work as you expect, you can post to   
   openwatcom.users.c_cpp, alt.os.development, comp.os.msdos.programmer, etc.   
   for IRQ programming.   
      
      
   Rod Pemberton   
      
   > And so we have a translated C code here:   
   > #include "p2c.h"   
   > #include "extra.h"   
   >   
      
   //#include "p2c.h"   
   //#include "extra.h"   
      
   > #define TIMER_G   
   > #include "timer.h"   
      
   //#include "timer.h"   
      
   >   
   >   
   >   
   > #define MaxRate         1193180L   
   >   
      
   #if 1   
   #define Static static   
   #define boolean int   
   #define Void void   
   #define LONGINT long int   
   #define getvect _dos_getvect   
   #define setvect _dos_setvect   
   #if 0   
   #define asm _asm   
   #endif   
   #define outportb outp   
   #include    
   #include    
   #include    
   #define true 1   
   #define false 0   
   unsigned long ClockTicks;   
   #endif   
      
      
   >   
   > void interrupt(__far *OldInt08)();//Static _PROCEDURE OldInt08,   
   > OldInt1C;   
      
   //void interrupt(__far *OldInt08)();//Static _PROCEDURE OldInt08, OldInt1C;   
   void (__interrupt __far *OldInt08)();   
      
   > void interrupt(__far *OldInt1C)();   
      
   //void interrupt(__far *OldInt1C)();   
   void (__interrupt __far *OldInt1C)();   
      
   > Static unsigned short IntCount08, Trigger;   
   > Static boolean TimerAlreadySet;   
   > Static unsigned short Frequency;   
   >   
   > void GetIntVec(int a, void interrupt(__far *b)())   
      
   //void GetIntVec(int a, void interrupt(__far *b)())   
   void GetIntVec(int a, void (__interrupt __far *b)())   
      
   > {   
   >     b = getvect(a);   
   > }   
   >   
   > void SetIntVec(int a, void interrupt(__far *b)())   
      
   //void SetIntVec(int a, void interrupt(__far *b)())   
   void SetIntVec(int a, void (__interrupt __far *b)())   
      
   > {   
   >     setvect(a, b);   
   > }   
   >   
   >   
   > Static Void IrqOn()   
   > {   
   > /* p2c: timer1.pas, line 37:   
   >  * Note: Inline assembly language encountered [254] */   
   >   asm{sti;}//asm(" inline $FB");   
      
   //asm{sti;}//asm(" inline $FB");   
   _asm{sti}   
      
   > }   
   >   
   >   
   > Static Void IrqOff()   
   > {   
   > /* p2c: timer1.pas, line 40:   
   >  * Note: Inline assembly language encountered [254] */   
   >   asm{cli;}//asm(" inline $FA");   
      
   //asm{cli;}//asm(" inline $FA");   
   _asm{cli}   
      
   > }   
   > /* p2c: timer1.pas, line 43: Note: Ignoring INTERRUPT keyword [258] */   
   >   
   >   
   > /*$F+*/   
   > void interrupt NewInt1C()//Static Void NewInt1C()   
   > {printf("\nNewInt1C()");   
   >   ClockTicks++;   
   > }   
   > /* p2c: timer1.pas, line 50: Note: Ignoring INTERRUPT keyword [258] */   
   >   
   >   
   > /*$F-*/   
   >   
   > /*$F+*/   
   > void interrupt NewInt08()//Static Void NewInt08()   
   > {printf("\nNewInt08()");   
   >   IrqOff();   
   > /* p2c: timer1.pas, line 53:   
   >  * Note: Inline assembly language encountered [254] */   
   >   asm{int 1Ch;}//asm(" inline $CD");   
      
   //asm{int 1Ch;}//asm(" inline $CD");   
   _asm{int 1Ch}   
      
   >   //asm(" inline $1C");   /*Generate INT 1Ch instruction to call   
   > interrupt 1Ch*/   
   >   if (IntCount08 == Trigger) {   
   > IntCount08 = 0;   
   > /* p2c: timer1.pas, line 57:   
   >  * Note: Inline assembly language encountered [254] */   
   > asm{pushf;}//asm(" inline $9C");   
      
   //asm{pushf;}//asm(" inline $9C");   
   _asm{pushf}   
      
   > OldInt08();/*if (OldInt08.link != NULL)   
   > (*(Void(*) PP((Anyptr _link)))OldInt08.proc)(OldInt08.link);   
   > else   
   > (*(Void(*) PV())OldInt08.proc)();*/   
   >   } else   
   >     IntCount08++;   
   >   outportb( 0x20, 0x20 );//PORT(0x20) = 0x20;   /*Sends non-specific   
   > EOI to the PIC*/   
   > /* p2c: timer1.pas, line 64: Note: Reference to PORT [191] */   
   > /* p2c: timer1.pas, line 64: Warning: Invalid assignment [168] */   
   >   IrqOn();   
   > }   
   >   
   >   
   > /*$F-*/   
   >   
   > Void TimerOn(Freq)   
   > long Freq;   
   > {   
   >   LONGINT Temp = MaxRate;   
   >   unsigned short Count;   
   >   _PROCEDURE TEMP1;   
      
   // _PROCEDURE TEMP1;   
      
   > printf("\nTimerOn()");   
   >   if (TimerAlreadySet)   
   >     return;   
   >   ClockTicks = 0;   
   >   IntCount08 = 0;   
   >   Frequency = Freq;   
   >   Trigger = (long)(Freq / 18.2);   
   >   Temp = (long)((double)Temp / Freq);   
   >   Count = Temp;   
   >   GetIntVec(0x8, OldInt08);   
   >   TEMP1.proc = (Anyptr)NewInt08;   
   >   TEMP1.link = (Anyptr)NULL;   
      
   //TEMP1.proc = (Anyptr)NewInt08;   
   //TEMP1.link = (Anyptr)NULL;   
      
   > /* p2c: timer1.pas, line 83:   
   >  * Warning: Symbol 'GETINTVEC' is not defined [221] */   
   >   SetIntVec(0x8, NewInt08);//SetIntVec(0x8, TEMP1);   
   > /* p2c: timer1.pas, line 84:   
   >  * Warning: Symbol 'SETINTVEC' is not defined [221] */   
   >   GetIntVec(0x1c, OldInt1C);   
   >   TEMP1.proc = (Anyptr)NewInt1C;   
   >   TEMP1.link = (Anyptr)NULL;   
      
   //TEMP1.proc = (Anyptr)NewInt1C;   
   //TEMP1.link = (Anyptr)NULL;   
      
   > /* p2c: timer1.pas, line 85:   
   >  * Warning: Symbol 'GETINTVEC' is not defined [221] */   
   >   SetIntVec(0x1c, NewInt1C);//SetIntVec(0x1c, TEMP1);   
   > /* p2c: timer1.pas, line 86:   
   >  * Warning: Symbol 'SETINTVEC' is not defined [221] */   
   >   outportb( 0x43, 0xb6);   
   > /* p2c: timer1.pas, line 87: Note: Reference to PORT [191] */   
   > /* p2c: timer1.pas, line 87: Warning: Invalid assignment [168] */   
   >   outportb( 0x40, Count & 255);   
   > /* p2c: timer1.pas, line 88: Note: Reference to PORT [191] */   
   > /* p2c: timer1.pas, line 88: Warning: Invalid assignment [168] */   
   >   outportb( 0x40, Count >> 8);   
   > /* p2c: timer1.pas, line 89: Note: Reference to PORT [191] */   
   > /* p2c: timer1.pas, line 89: Warning: Invalid assignment [168] */   
   >   TimerAlreadySet = true;   
   > }   
   >   
   >   
   > Void TimerOff()   
   > {printf("\nTimerOff()");   
   >   if (!TimerAlreadySet)   
   >     return;   
   >   outportb( 0x43, 0xb6);   
   > /* p2c: timer1.pas, line 98: Note: Reference to PORT [191] */   
   > /* p2c: timer1.pas, line 98: Warning: Invalid assignment [168] */   
   >   outportb( 0x40, 0xff);   
   > /* p2c: timer1.pas, line 99: Note: Reference to PORT [191] */   
   > /* p2c: timer1.pas, line 99: Warning: Invalid assignment [168] */   
   >   outportb( 0x40, 0xff);   
   > /* p2c: timer1.pas, line 100: Note: Reference to PORT [191] */   
   > /* p2c: timer1.pas, line 100: Warning: Invalid assignment [168] */   
   >   SetIntVec(0x8, OldInt08);   
   > /* p2c: timer1.pas, line 101:   
   >  * Warning: Symbol 'SETINTVEC' is not defined [221] */   
   >   SetIntVec(0x1c, OldInt1C);   
   > /* p2c: timer1.pas, line 102:   
   >  * Warning: Symbol 'SETINTVEC' is not defined [221] */   
   >   TimerAlreadySet = false;   
   > }   
   >   
   >   
   > Void ResetTimer()   
   > {   
   >   ClockTicks = 0;   
   > }   
   >   
   >   
   > double TimeElapsed()   
   > {   
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca