home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PARADIS1 / INTERUPT.PAS < prev    next >
Pascal/Delphi Source File  |  1991-01-28  |  3KB  |  114 lines

  1. (10221) Sat 25 Jan 92 20:41
  2. By: Mike Hindle
  3. To: All
  4. Re: Interrupt Handlers
  5. St:
  6. ---------------------------------------------------------------------------
  7. @MSGID: 1:153/722 8676b2f1
  8. @PID: TeleMail 1.49f
  9. Question of the day: How to correctly write an interrupt handler?
  10.  
  11. The following code seems to work ok, but continually does weird things
  12. to my system. It runs for awhile then at random points in time, my system
  13. locks up, reboots, displays garbage on the screen, makes the hard drive go
  14. nuts, and confuses my modem. I'd say the timer doesn't appreciate being
  15. interrupted.
  16.  
  17. Would whoever responds to this message please provide a general background
  18. on interrupt handlers ie: why disable/enable interrupts, whether the saved
  19. interrupt address should be called, whether it is necessary to push the
  20. flags before calling the saved interrupt address, etc. etc.
  21.  
  22. Now of course, I am seeking a cause and/or solution to the problem I am
  23. having with the following TP 5.0 code.
  24.  
  25.  
  26. VAR
  27. TimerCnt        : byte;
  28. OldInt1C        : procedure;
  29. I               : byte;
  30. HStr,
  31. MStr,
  32. SStr,
  33. Temps           : string;
  34. IntTimeRcd      : TimeRec;
  35. ExitSave        : pointer;
  36.  
  37.  
  38. PROCEDURE StartDateTime;
  39. { This procedure sets up the interrupt driven date/time display.        }
  40.   BEGIN
  41.     ExitSave := ExitProc;
  42.     ExitProc := @StopDateTime;
  43.  
  44.     TimerCnt := 0;
  45.  
  46.     GetIntVec($1C,@OldInt1C);
  47.     SetIntVec($1C,@UpdateTime);
  48.   END; { StartDateTime }
  49.  
  50.  
  51. PROCEDURE StopDateTime;
  52.   BEGIN
  53.     Inline($FA);                { CLI - Disable interrupts      }
  54.     ExitProc := ExitSaveDateTime;
  55.  
  56.     SetIntVec($1C,@OldInt1C);   { Restore timer interrupt       }
  57.     Inline($FB);                { STI - Enable interrupts       }
  58.   END; { StopDateTime }
  59.  
  60.  
  61. PROCEDURE UpdateTime; Interrupt;
  62.   BEGIN
  63.     Inline($FA);        { CLI - Disable interrupts      }
  64.  
  65.     Inc(TimerCnt);
  66.  
  67.     IF TimerCnt = 18 THEN WITH IntTimeRcd DO
  68.     BEGIN
  69.         GetTime(Hour,Minute,Second,Sec100);
  70.  
  71.         IF Hour < 12 THEN Temps := ' AM' ELSE Temps := ' PM';
  72.         IF Hour > 12 THEN Dec(Hour,12) ELSE IF Hour = 0 THEN Hour := 12;
  73.  
  74.         Str(Hour:2,HStr);
  75.         Str(Minute,MStr);
  76.         Str(Second,SStr);
  77.  
  78.         IF Minute < 10 THEN MStr := '0' + MStr;
  79.         IF Second < 10 THEN SStr := '0' + SStr;
  80.  
  81.         Temps := HStr + ':' + MStr + ':' + SStr + Temps;
  82.  
  83.         FOR I := 1 TO Length(Temps) DO
  84.                 Monitor^[(2 * I) + 136] := Ord(Temps[I]);
  85.  
  86.         TimerCnt := 0;
  87.     END; { if }
  88.  
  89.     Inline($FB);        { STI - Enable interrupts       }
  90.  
  91.     Inline($9C);        { Push flags                    }
  92.  
  93.     OldInt1C;
  94.   END; { UpdateTime }
  95.  
  96.  
  97. {***************************************************************************}
  98. BEGIN
  99.     StartDateTime;
  100.  
  101.         .
  102.         .
  103.         .
  104.  
  105.     StopDateTime;
  106. END.
  107.  
  108.  
  109. ... Mike
  110. --- Blue Wave/TGp v2.02a Beta
  111.  * Origin: The Welcome Mat - Van, BC - [604-439-6717] (1:153/722.0)
  112.  
  113. @PATH: 153/722 740 752 396/1 170/400 512/0 1007 
  114.