home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SYSTEM / CLOCK10.ZIP / CLOCKRES.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-10-18  |  4.5 KB  |  301 lines

  1. ; CLOCKRES.ASM
  2.  
  3. ; TSR or C callable clock routine.
  4. ; For What It's Worth, this thing is FREE.
  5. ; Please keep the original files together and distribute them unchanged!
  6. ; David C. Schooley  (CIS 72571,2543)
  7. ; Birmingham, AL and Stillwater, OK (GO Pokes!!!)
  8. ; October 1990
  9.  
  10. IDEAL
  11.  
  12.  
  13. TSR    EQU 0    ; 1 for TSR, 0 for C callable
  14.  
  15. ATBIOS    EQU 0    ; Smaller code for machines that support function 2
  16.         ;  of INT 1AH will be assembled if ATBIOS is defined
  17.         ;  to be nonzero
  18.  
  19. REFRESH EQU 0    ; Set to 1 to update display during every clock
  20.         ; tick, 0 to update display only when time
  21.         ; changes.
  22.  
  23. IFE TSR
  24. MODEL SMALL    ; Change this to the correct memory model
  25. ENDIF
  26.  
  27.  
  28.  
  29.  
  30. IF TSR
  31. SEGMENT CODE WORD PUBLIC 'CODE'
  32.     ASSUME CS:CODE
  33.         ORG    100H
  34.  
  35. ENDIF
  36. Begin:    
  37.  
  38. IF TSR
  39.     JMP    Init
  40.  
  41.  
  42. ELSE
  43.  
  44. PUBLIC _TimerHit
  45. PUBLIC _oldint1C
  46. PUBLIC _ClockPosition
  47.  
  48. DATASEG
  49.  
  50. ENDIF
  51.  
  52. IFE ATBIOS
  53. ;
  54. ; Lookup table for converting hex values to binary coded decimal.
  55. ; It's only assembled if ATBIOS is defined to be equal to 0.
  56. ;
  57. Tbl        db    0,1,2,3,4,5,6,7,8,9
  58. Tbl2        db    10H,11H,12H,13H,14H,15H,16H,17H,18H,19H
  59. Tbl3        db    20H,21H,22H,23H,24H,25H,26H,27H,28H,29H
  60. Tbl4        db    30H,31H,32H,33H,34H,35H,36H,37H,38H,39H
  61. Tbl5        db    40H,41H,42H,43H,44H,45H,46H,47H,48H,49H
  62. Tbl6        db    50H,51H,52H,53H,54H,55H,56H,57H,58H,59H
  63. ENDIF
  64.  
  65. _ClockPosition        dw    0
  66. LastTime        dw    ?
  67. Hour            dw    ?
  68. Colon        db    ':'
  69. Minutes        dw    ? 
  70. Space        db    ' '
  71. AMPM            db    '     ' ;
  72. Seconds        dw    ?
  73. LastMinutes    db    ? 
  74. PM            db    'p.m.'
  75. AM            db    'a.m.'
  76.  
  77. _oldint1C        dd    ?
  78.  
  79.  
  80. IFE TSR
  81.  
  82. CODESEG
  83.  
  84. ENDIF
  85.  
  86. PROC        ConvertToASCII    ;    Takes value in AL
  87.                 ;    Offset of variable in DI
  88.         ADD    AL,30H        
  89. StoreIt:    STOSB
  90.         RET
  91.  
  92. ENDP    ConvertToASCII
  93.  
  94. PROC    _TimerHit
  95.  
  96. ; Call the old interrupt handler
  97.         PUSHF
  98.         CALL [_oldint1C]
  99.  
  100. IF TSR
  101. ; Let's be nice!
  102.         PUSH    AX
  103.         PUSH    BX
  104.         PUSH    CX
  105.         PUSH    DX
  106.         PUSH    BP
  107.         PUSH    DI
  108.         PUSH    SI
  109.         PUSH    DS
  110.         PUSH    ES
  111.  
  112. ; This part is should not be used when doing using interrupt functions in TC.
  113.         MOV    AX,CS
  114.         MOV    DS,AX
  115.  
  116. ELSE
  117. ; TC sets up DS for us,
  118.         MOV    AX,DS
  119.  
  120. ENDIF
  121. ; This part should always be assembled.
  122.         MOV    ES,AX
  123.         
  124. ; Disable interrupts.
  125.         CLI
  126.  
  127. IF ATBIOS
  128. ; Get the current time.
  129.         MOV    AH,02H
  130.         INT    1AH
  131.         MOV    BX,CX        
  132. ELSE
  133.  
  134. ; Get tick count since midnight
  135.         XOR    AH,AH
  136.         INT    1AH
  137.  
  138. ; The value in the CX register is pretty close to the correct hour.
  139. ; Convert it to BCD.
  140.         XCHG    AL,CL
  141.         MOV    BX,OFFSET Tbl
  142.         XLAT
  143.         MOV    SI,AX    ; Hour is now in low byte of SI
  144.         
  145.         MOV    AX,DX
  146.         XOR    DX,DX
  147.         MOV    CX,445H
  148.         DIV    CX
  149.         XLAT
  150.  
  151.         MOV    BX,SI
  152.         XCHG    BH,BL
  153.  
  154.         MOV    BL,AL    ; Min is now in BL
  155.  
  156.  
  157. ENDIF
  158.  
  159. IFE REFRESH
  160.         CMP    [LastTime],BX
  161.         JNE    Update
  162.         JMP    Finish
  163. ENDIF
  164.  
  165. ; BH - hour, BL - minutes, DH - seconds, all values in binary coded
  166. ; decimal.
  167.  
  168. ; See if it's morning or afternoon.
  169. Update:
  170.  
  171. IFE REFRESH
  172.         MOV    [LastTime],BX
  173. ENDIF
  174.         CMP    BH,12H
  175.         JB    InTheAM
  176.  
  177. ; Set up the p.m.
  178.         MOV    SI,OFFSET PM
  179.         MOV    DI,OFFSET AMPM
  180.         MOV    CX,2
  181.         REP    MOVSW
  182.  
  183.         CMP    BH,12H
  184.         JE    PutInAL
  185.  
  186. ; Subtract 12 in BCD
  187.         MOV    AL,BH
  188.         SUB    AL,12H
  189.         DAS
  190.         MOV    BH,AL    
  191.         JMP SHORT NotMidNight
  192.  
  193. ; Set up the a.m.
  194. InTheAM:        MOV    SI,OFFSET AM
  195.         MOV    DI,OFFSET AMPM
  196.         MOV    CX,2
  197.         REP    MOVSW
  198.  
  199.             TEST    BH,BH ; between midnight and 1.00 a.m.
  200.         JNZ    PutInAL
  201.         MOV    BH,12H
  202. PutInAL:    MOV    AL,BH
  203. NotMidNight:    MOV    CX,4
  204.  
  205. ; Display the hour
  206.         SHR    AL,CL
  207.         MOV    DI,OFFSET Hour
  208.         CALL    ConvertToASCII
  209.  
  210.         MOV    AL,BH
  211.         AND    AL,0FH
  212.         CALL    ConvertToASCII
  213.  
  214.         CMP    BH,10H
  215.         JAE    AfterNine
  216.         MOV    [BYTE Hour],0
  217.  
  218. ; Display the minutes
  219. AfterNine:    MOV    AL,BL
  220.         MOV    DI,OFFSET Minutes
  221.         SHR    AL,CL
  222.         CALL    ConvertToASCII
  223.  
  224.         MOV    AL,BL
  225.         AND    AL,0FH
  226.         CALL     ConvertToASCII
  227.  
  228.         MOV    [Colon],':'
  229.  
  230. ; Get the cursor position.
  231.         MOV    AH,03H            
  232.         XOR    BH,BH
  233.         INT    10H
  234.                 PUSH    DX
  235.  
  236. ; Write the string in the position determined by the contents of DX.
  237.         MOV    AX,1300H        
  238.         MOV    BX,0007H
  239.         MOV    CX,OFFSET LastMinutes - OFFSET Hour
  240.  
  241.         MOV    DX,[_ClockPosition]
  242.         MOV    BP,OFFSET Hour
  243.         INT    10H
  244.  
  245. ; Put the cursor back where you found it!
  246.         MOV    AH,02H
  247.         POP    DX
  248.         INT    10H
  249.  
  250. ; Clean up the mess.        
  251. Finish:    STI
  252.  
  253.  
  254. IF TSR
  255.         POP    ES
  256.         POP    DS
  257.         POP     SI
  258.         POP     DI
  259.         POP  BP
  260.         POP     DX
  261.         POP     CX
  262.         POP     BX
  263.         POP     AX
  264.  
  265.         IRET
  266. ELSE
  267.  
  268.         RET
  269.  
  270. ENDIF
  271.  
  272. ENDP    _TimerHit
  273.  
  274. IF TSR
  275.  
  276. Init:    MOV    BX,2CH
  277.         MOV    ES,[BX]
  278.         MOV    AH,49H
  279.         INT    21H
  280.  
  281.         MOV    AX,351CH
  282.         INT    21H
  283.         MOV    [WORD _oldint1C],BX
  284.         MOV    [WORD _oldint1C+2],ES
  285.         CLI
  286.         MOV    AX,251CH
  287.         MOV    DX,OFFSET _TimerHit
  288.         INT    21H            ;Initialize the timer
  289.         STI
  290.  
  291.         MOV    DX,OFFSET Init
  292.         INT    27H
  293.  
  294.  
  295. ENDS    CODE
  296.  
  297.  
  298. ENDIF
  299.         END Begin