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 1,699 of 2,978    |
|    =?ISO-8859-1?Q?Bj=F6rn_Felten?= to All    |
|    Re: Simple chrono    |
|    02 Jun 05 15:08:05    |
   
   From: abuse@telia.com   
      
   > There is no standard function to this in pascal, but there is an interrupt   
   > that does so.   
      
    And this is of course one of the major reasons to use INTR calls,   
   that there is no other way to do it.   
      
    Another reason is for speed. But even then the REGS/INTR version   
   adds a lot of overhead to the finished code. A better way then, is to   
   make use of a powerful TP/BP thing called inline macros. Those are   
   inserted exactly as they are written into the code, with no overhead at all.   
      
    During my years I've collected quite a few inline macros into a   
   single unit. One good thing about TP/BP (as opposed to e.g. C) is that   
   it only includes the parts of a unit that is actually used, so you can   
   put as many macros in the unit as you like, without making the final   
   code bigger.   
      
    Here's my MACRO.PAS, in case anyone is interested. Feel free to use   
   it in any way you like; no stupid US copyright strings attached. :)   
      
   unit Macro;   
   {$g+}   
   { -=:*:=- macros -=:*:=- }   
      
   { various inline macros collected/rewritten/written by   
    Björn Felten @ 2:203/208 July 1994 }   
      
   { -- Public Domain -- }   
      
   interface   
      
   function readKey:char;inline   
   ($B4/$07/ { mov ah,7 }   
    $CD/$21); { int $21 }   
      
   function xreadKey:char;inline   
   ($B4/$10/ { mov ah,10h }   
    $CD/$16); { int 16h }   
      
   function keyPressed:boolean;inline   
   ($B4/$0B/ { mov ah,$B }   
    $CD/$21/ { int $21 }   
    $24/$FE); { and al,$FE }   
      
   { fast sqrt -- returns int part in hi word and fract part in low}   
   function iSqrt(x:longint):longint;   
   inline   
    ($66/$33/$c0 { xor eax,eax}   
    /$66/$33/$d2 { xor edx,edx}   
    /$66/$5f { pop edi}   
    /$b9/$20/$00 { mov cx,32}   
    {@L:}   
    /$66/$d1/$e7 { shl edi,1}   
    /$66/$d1/$d2 { rcl edx,1}   
    /$66/$d1/$e7 { shl edi,1}   
    /$66/$d1/$d2 { rcl edx,1}   
    /$66/$d1/$e0 { shl eax,1}   
    /$66/$8b/$d8 { mov ebx,eax}   
    /$66/$d1/$e3 { shl ebx,1}   
    /$66/$43 { inc ebx}   
    /$66/$3b/$d3 { cmp edx,ebx}   
    /$7c/$05 { jl @S}   
    /$66/$2b/$d3 { sub edx,ebx}   
    /$66/$40 { inc eax}   
    {@S:}   
    /$e2/$dd { loop @L}   
    /$66/$8b/$d0 { mov edx,eax}   
    /$66/$c1/$ea/$10); { shr edx,16}   
      
   function swapLong(l:longint):longint;   
   inline   
    ($5a { pop dx }   
    /$58); { pop ax }   
      
   function swapWords(x,y:word):longint;   
   inline   
    ($58 { pop ax }   
    /$5a); { pop dx }   
      
   function Mul32(a,b:longint):longint;   
   inline($fa/$66/$59/$66/$58/$66/$f7/$e9/$66/$0f/$a4/$c2/$10/$fb);   
      
   function Div32(a,b:longint):longint;   
   inline($fa/$66/$59/$66/$58/$66/$99/$66/$f7/$f9/$66/$0f/$a4/$c2/$10/$fb);   
      
   function Shl32(a:longint;b:word):longint;   
   inline($fa/$59/$66/$58/$66/$d3/$e0/$66/$0f/$a4/$c2/$10/$fb);   
      
   function Shr32(a:longint;b:word):longint;   
   inline($fa/$59/$66/$58/$66/$d3/$e8/$66/$0f/$a4/$c2/$10/$fb);   
      
   function Sar32(a:longint;b:word):longint;   
   inline($fa/$59/$66/$58/$66/$d3/$f8/$66/$0f/$a4/$c2/$10/$fb);   
      
   function Rol32(a:longint;b:word):longint;   
   inline($fa/$59/$66/$58/$66/$d3/$c0/$66/$0f/$a4/$c2/$10/$fb);   
      
   function Ror32(a:longint;b:word):longint;   
   inline($fa/$59/$66/$58/$66/$d3/$c8/$66/$0f/$a4/$c2/$10/$fb);   
      
   function Long2Hex(L: longint): string;   
   inline(   
    $66/$5b { pop ebx ; ebx = L }   
    /$16 { push ss }   
    /$07 { pop es ; es = ss }   
    /$b8/$08/$00 { mov ax,8 }   
    /$aa { stosb }   
    /$89/$c1 { mov cx,ax }   
    {@@loo: }   
    /$66/$c1/$c3/$04 { rol ebx,4 }   
    /$88/$d8 { mov al,bl }   
    /$24/$0f { and al,15 }   
    /$04/$90 { add al,90h }   
    /$27 { daa }   
    /$14/$40 { adc al,40h }   
    /$27 { daa }   
    /$0c/$20 { or al,20h }   
    /$aa { stosb }   
    /$e2/$ed); { loop @loo }   
      
   function Word2Hex(L: word): string;   
   inline(   
    $5b { pop bx ; bx = L }   
    /$16 { push ss }   
    /$07 { pop es ; es = ss }   
    /$b8/$04/$00 { mov ax,4 }   
    /$aa { stosb }   
    /$89/$c1 { mov cx,ax }   
    {@@loo: }   
    /$c1/$c3/$04 { rol bx,4 }   
    /$88/$d8 { mov al,bl }   
    /$24/$0f { and al,15 }   
    /$04/$90 { add al,90h }   
    /$27 { daa }   
    /$14/$40 { adc al,40h }   
    /$27 { daa }   
    /$0c/$20 { or al,20h }   
    /$aa { stosb }   
    /$e2/$ee); { loop @loo }   
      
   implementation   
      
   end.   
      
      
      
   --   
    FidoNet in your news reader: news://felten.yi.org   
    For full access, register at: http://felten.yi.org/join.html   
      
   --- 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