GETTIME.PAS 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. {* WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  2. In order to use the Intr procedure in Turbo Pascal you
  3. must be familiar with interrupts and have access to a
  4. technical reference manual.
  5. The following program uses the Intr function in Turbo to
  6. get the time. Registers have to be set correctly according
  7. to the DOS technical reference manual before the function
  8. is called.
  9. The program simply returns the time in a string at the top
  10. of the screen.*}
  11. program TimeInterrupt;
  12. type
  13. TimeString = string[8];
  14. function time: TimeString;
  15. type
  16. regpack = record
  17. ax,bx,cx,dx,bp,si,di,ds,es,flags: integer;
  18. end;
  19. var
  20. recpack: regpack; {assign record}
  21. ah,al,ch,cl,dh: byte;
  22. hour,min,sec: string[2];
  23. begin
  24. ah := $2c; {initialize correct registers}
  25. with recpack do
  26. begin
  27. ax := ah shl 8 + al;
  28. end;
  29. intr($21,recpack); {call interrupt}
  30. with recpack do
  31. begin
  32. str(cx shr 8,hour); {convert to string}
  33. str(cx mod 256,min); { " }
  34. str(dx shr 8,sec); { " }
  35. end;
  36. time := hour+':'+min+':'+sec;
  37. end;
  38. begin
  39. writeln(time);
  40. end.