home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol242 / setclock.asm < prev    next >
Encoding:
Assembly Source File  |  1986-12-01  |  4.3 KB  |  109 lines

  1. ;*************************************************************************
  2.  
  3. CODE_SEG      SEGMENT PUBLIC
  4.               ORG     100H
  5.               ASSUME  CS:CODE_SEG,DS:CODE_SEG
  6.  
  7. SETCLOCK      PROC    FAR
  8.               JMP     START             ;JUMP OVER DATA DECLARATIONS
  9.  
  10. ;-------------------------------------------------------------------------
  11.  
  12. ;  This program can be used by AT&T PC6300 users running IBM PC-DOS
  13. ;  to set the DOS clock from the 6300s on-board clock/calendar chip
  14.  
  15. ;  Program Notes:
  16. ;
  17. ;  For the IBM PC, a timer tick is generated approximately 18.21 times
  18. ;  per second.  The AT&T 6300 generates exactly 18.75 timer ticks per
  19. ;  second.
  20.  
  21. ;  Access to the 6300s on-board clock/calendar chip (set and read time and
  22. ;  date) can be accomplished through calls to the ROM BIOS interrupt
  23. ;  number 1A (hex).  On an IBM PC, this call supports 2 functions:
  24. ;      GET TIMER COUNT ===> AH=0
  25. ;      SET TIMER COUNT ===> AH=1
  26. ;          For both functions, CX = high word of timer count
  27. ;                              DX = low word of timer count
  28. ;  On a 6300, this BIOS call supports 2 additional functions as follows:
  29. ;      SET REAL TIME CLOCK/CALENDAR
  30. ;            AH = 0FFh
  31. ;            BX = Days from 1/1/84
  32. ;            CH = Hours
  33. ;            CL = Minutes
  34. ;      READ REAL TIME CLOCK/CALENDAR
  35. ;            AH = 0FEh
  36. ;            BX = same as function 0FFh
  37. ;            CH = ditto
  38. ;            CL = ditto
  39. ;            DH = Seconds
  40. ;            DL = Hundreths of seconds
  41. ;
  42. ;  For all interrupt 1Ah functions, AH serves as the error flag for the
  43. ;  call (ie. if AH=0 on return, all is well)
  44. ;
  45. ;  The 6300 System Programmer's Guide contains a listing of the ROM BIOS
  46. ;  code for this interrupt.  This listing contains a comment explaining
  47. ;  the usage of the BX register as day "from 1-1 of leap year up to
  48. ;  12-31 of leap year+7 (0 - B69h)".  While I'm not sure exactly what
  49. ;  this means, setting BX to zero sets the date to 1/1/84 and setting BX
  50. ;  to 0B69h sets the date to 12/31/91.  Setting BX to a value greater
  51. ;  than 0B69h results in an error.  I suppose this means that a new
  52. ;  clock/calendar chip will have to be installed sometime in 1991!
  53.  
  54. ;-------------------------------------------------------------------------
  55.  
  56. ;---- IBM PC-DOS Timer Tick equivalents --------------------------------
  57. ;---- Note that since the 6300 generates 18.75 ticks per second (as
  58. ;---- opposed to the IBM PC which generates only 18.21 per second),
  59. ;---- the PC-DOS clock will seem to run a bit fast
  60. ;-----------------------------------------------------------------------
  61. TICKS_PER_HOUR DD     65543
  62. TICKS_PER_MIN  DW     1092
  63.  
  64. TIMER_TICKS   DD      0
  65.  
  66. CURR_HOUR     DB      ?
  67. CURR_MIN      DB      ?
  68.  
  69. ;-------------------------------------------------------------------------
  70.  
  71. START:        MOV     AH,0FEH           ;BIOS INTERRUPT 1A FUNCTION
  72.               INT     1AH               ; TO READ THE 6300s ON-BOARD
  73.               MOV     CURR_HOUR,CH      ; CLOCK CALENDAR CHIP
  74.               MOV     CURR_MIN,CL       ; RETURNS HOURS IN CH, MINUTES IN CL
  75.  
  76. ; Given the "real" time from the on-board clock, we can convert to BIOS
  77. ; timer ticks so that PC-DOS will know what time it is
  78.  
  79. HOURLY_TICKS: MOV     AX,WORD PTR TICKS_PER_HOUR[2]
  80.               MOV     BX,WORD PTR TICKS_PER_HOUR
  81.               XOR     CH,CH
  82.               MOV     CL,CURR_HOUR
  83.               JCXZ    MINUTE_TICKS      ;skip hours if zero
  84. ADD_LOOP:     ADD     WORD PTR TIMER_TICKS,BX
  85.               ADC     WORD PTR TIMER_TICKS[2],AX
  86.               LOOP    ADD_LOOP
  87.  
  88. MINUTE_TICKS: MOV     CX,TICKS_PER_MIN
  89.               MOV     AL,CURR_MIN
  90.               XOR     AH,AH
  91.               MUL     CX
  92.               ADD     WORD PTR TIMER_TICKS,AX
  93.               ADC     WORD PTR TIMER_TICKS[2],DX
  94.  
  95. ; We now know what time it is in terms of PC-DOS timer ticks.  We will
  96. ; use the ROM BIOS function 1A to set the timer tick value in the
  97. ; BIOS data segment to this calculated value
  98.  
  99. SET_TIMER:    MOV     CX,WORD PTR TIMER_TICKS[2]
  100.               MOV     DX,WORD PTR TIMER_TICKS
  101.               MOV     AH,1              ;SET BIOS TIMER TICK FUNCTION
  102.               INT     1AH               ;CALL BIOS
  103.  
  104.               INT     20H               ;EXIT
  105.  
  106. SETCLOCK      ENDP
  107. CODE_SEG      ENDS
  108.               END     SETCLOCK
  109.