home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / UTILITY / TIMERS.ZIP / TIMER2.ASM < prev    next >
Assembly Source File  |  1993-03-02  |  12KB  |  325 lines

  1.                 TITLE TIMER.ASM
  2.  
  3. ;Author:        Charles R. Grosvenor Jr.
  4. ;Date Written:  Novemeber 11-12, 1992
  5. ;Purpose:       Utility for BBS
  6. ;               This allows me to break out of the autoexec.bat loop file
  7. ;               before the stupid thing loads the BBS, helpful if the modem
  8. ;               is having problems or if I want to run a program other than
  9. ;               the BBS
  10.  
  11. ;Why Assembly:  C and Pascal created huge, psycho hose beast programs of
  12. ;               about 30K (ok, it's miniscule anyways) but this is a little
  13. ;               over 2K, think of ALL that SPACE I save... >grin<
  14. ;               it does seem to exit it out of the loop quicker.
  15.  
  16. ;Inputs:        string of numbers, i.e.  timer 10
  17. ;               where the number (here 10) would count down to 1
  18. ;Outputs:       MS-DOS ErrorLevel=0 if timeout occurs,
  19. ;               MS-DOS ErrorLevel=(ascii code of key hit) if it's aborted
  20.  
  21. ;  Timer to count from 5 to 1 is default
  22. ;  32767 is the maximum, strange I know, probably cause it's signed
  23. ;  that's about 9 hours, which is too long to leave the thing waiting anyways
  24.  
  25. ;  This is my FIRST program that I have written with a purpose, granted,
  26. ;       it has taken me 10 hours or so, so the code at this point is anything
  27. ;       but neat.  Two days in the making, and I only lifted ONE procedure
  28. ;       from somewhere else, that was the bin16asc, it's a it tough for me
  29. ;       right now.  Hopefully not at the end of the month
  30.  
  31.                 INCLUDE timer.mac
  32.  
  33.                 DOSSEG
  34.                 .MODEL SMALL
  35.                 .STACK 10h
  36.                 .DATA
  37.  
  38. keyHit          EQU     255
  39. cr              EQU     0dh
  40. lf              EQU     0ah
  41. eos             EQU     0
  42. blanks          DB      "     ",eos
  43. prompt          DB      "Count down from ",eos
  44. intStr          DB      10(?)
  45.  
  46.                 .CODE
  47.  
  48. main            proc    near
  49.  
  50. readPSP:
  51.                 call    _CUROFF
  52.                 mov     cx,05h
  53.                 mov     bx,80h          ; charcater count of command tail
  54.                 xor     dh,dh
  55.                 mov     dl,BYTE PTR [bx]
  56.                 and     dx,dx
  57.                 jne     strip
  58.                 mov     cx,05h          ; we didn't get a parameter, default
  59.                 jmp     start
  60.                 inc     dx
  61.  
  62. strip:          inc     bx              ; find the start of the numbers
  63.                 dec     dx
  64.                 and     dx,dx           ; make sure we haven't searched the
  65.                                         ; whole command line
  66.                 je      start
  67.                 cmp     BYTE PTR [bx], 30h
  68.                 jl      strip
  69.                 cmp     BYTE PTR [bx], 39h
  70.                 jg      strip
  71.                 push    bx              
  72.                 call    getDec          ; let's see what we can get
  73.                 mov     cx,ax           ; converted number goes into dx
  74.                 and     cx,cx           ; make sure we got something
  75.                 jg      start           ; we did!
  76.                 mov     cx,05h          ; we didn't!
  77.  
  78. start:
  79.                 initRegs
  80. ;                xor     ax,ax
  81. ;                int     10h
  82.                 push    cx
  83.                 push    dx
  84.                 mov     ah, 2ch
  85.                 int     21h
  86.                 mov     bh, dh     ; store starting seconds in bh
  87.                 pop     dx
  88.                 pop     cx
  89.                 
  90. main            endp
  91.  
  92. EnterLoop:
  93.                 push    cx
  94.                 push    dx
  95.                 mov     ah,2ch
  96.                 int     21h
  97.                 cmp     bh, dh
  98.                 je      pastInc    ; time hasn't changed
  99.  
  100. ;                backup  5
  101.  
  102.                 backup  25
  103.                 mov     bh,dh      ; time has changed, store new time
  104.                 pop     dx
  105.                 pop     cx
  106.                 dec     cx         ; subtract one from amount of seconds to go
  107.                 push    ax         ; save ax
  108.                 mov     ax,OFFSET prompt
  109.                 push    ax
  110.                 call    showStr
  111.                 pop     ax         ; restore ax
  112.  
  113. ; print out the number
  114.                 push    bx
  115.                 lea     bx, intStr
  116.                 push    ax
  117.                 push    ax
  118.                 mov     ax, cx
  119.                 inc     ax
  120.                 push    ax
  121.                 call    putDec
  122.                 call    showStr
  123.  
  124.                 mov     ax,OFFSET blanks
  125.                 push    ax
  126.                 call    showStr
  127.  
  128.                 pop     bx
  129.                 jmp     keyPress
  130.  
  131. pastInc:
  132.                 pop     dx
  133.                 pop     cx
  134.  
  135. keyPress:
  136.                 mov     AH,0Bh     ; Check Keyboard Stats
  137.                 int     21h
  138.                 cmp     al, keyHit ; if there's been a keypress
  139.                 je      EndZero    ; Exit with a zero if keypressed
  140.  
  141.                 cmp     cx, 0
  142.                 jl      EndOne
  143.                 jmp     EnterLoop
  144.  
  145. EndZero:
  146. ;                mov     ah,00h
  147. ;                mov     al,02h
  148. ;                int     10h
  149.                 call    _CURON
  150.                 mov     ah,08h     ; Read in keyboard
  151.                 int     21h        ; input goes into al, which is error code!
  152.  
  153.                 mov     AH,4Ch     ; Terminate
  154.                 int     21h        ; We're history!
  155. EndOne:
  156. ;                mov     ah,00h
  157. ;                mov     al,02h
  158. ;                int     10h
  159.                 call    _CURON
  160.                 mov     AH,4Ch     ; Terminate
  161.                 mov     AL,01      ; DOS exit code = 1
  162.                 int     21h        ; Cya L8r!
  163.  
  164.  
  165. ;******************************** PROCEDURES ********************************
  166.  
  167. showStr         proc    near            ; procedure to display a string
  168.                 push    bp
  169.                 mov     bp,sp           ; bp will point to last value of
  170.                                         ; the item pushed onto stack
  171.                                         ; before procedure call
  172.                 push    ax
  173.                 push    bx
  174.                 push    cx
  175.                 push    dx
  176.                 mov     bx, [bp + 4]    ; bx will now point to the string on
  177.                                         ; the stack
  178.                 xor     cx,cx           ; need to determine length of string
  179. startCount:     mov     dl,[bx]         ; move current character position into
  180.                                         ; dl
  181.                 and     dl,dl           ; compare dl to zero
  182.                 je      endLoop         ; if the zero is found, jump out of the
  183.                                         ; loop
  184.                 inc     bx              ; not zero, add one to the count
  185.                 inc     cx
  186.                 jmp     startCount      ; continue the count!
  187.  
  188. endLoop:        mov     dx, [bp + 4]    ; bx will now point to the string on
  189.                                         ; the stack
  190.  
  191.                 mov     ah,40h          ; print string
  192.                 mov     bx,0001h        ; display to the screen
  193.                 int     21h             ; execute the character display int.
  194.  
  195.                 pop     dx              ; reinstate the value of dx from before
  196.                                         ; the display procedure
  197.                 pop     cx
  198.                 pop     bx
  199.                 pop     ax
  200.                 pop     bp
  201.  
  202.                 ret     2               ; return out of the procedure and kill
  203.                                         ; last byte pushed onto stack
  204. showStr         endp
  205.  
  206. getDec          proc    near            ; procedure to get a hex number
  207.                                         ; from a string
  208.                 push    bp
  209.                 mov     bp,sp           ; bp will point to last value of
  210.                                         ; the item pushed onto stack
  211.                                         ; before procedure call
  212.                 push    bx
  213.                 push    cx              ; we're not going to save ax
  214.                 push    dx              ; becuase we're passing back the
  215.                                         ; value through it
  216.                 push    si
  217.                 mov     bx, [bp + 4]    ; the string
  218.                 xor     ax,ax           ; initalize the total
  219.                 mov     si,10           ; make si the base, this could be
  220.                                         ; changed to say, 2 if we wanted to
  221.                                         ; enter binary numbers
  222. DecLoop:        cmp     BYTE PTR[bx],30h; make sure it's not too low
  223.                 jl      endDecLoop      ; it's too small
  224.                 cmp     BYTE PTR[bx],39h; make sure it's not too big
  225.                 jg      endDecLoop      ; it's too large to be decimal
  226.                 mul     si              ; multiply everything by 10
  227.                 mov     cl,BYTE PTR[bx]
  228.                 sub     cl,30h          ; make it a number 0 - 9
  229.                 xor     ch,ch           ; make the ch zero, not used
  230.                 add     ax,cx           ; add it to the total
  231.                 inc     bx
  232.                 jmp     DecLoop
  233. endDecLoop:
  234.                 pop     si
  235.                 pop     dx
  236.                 pop     cx
  237.                 pop     bx
  238.                 pop     bp
  239.  
  240.                 ret     2               ; return out of the procedure and kill
  241.                                         ; last byte pushed onto stack,
  242.                                         ; this gets rid of the items passed to
  243.                                         ; the procedure
  244. getDec          endp
  245.  
  246. putDec          proc    near            ; procedure to make a string from a
  247.                                         ; binary number
  248.                 push    bp
  249.                 mov     bp,sp           ; bp will point to last value of
  250.                                         ; the item pushed onto stack
  251.                                         ; before procedure call
  252.                 push    ax
  253.                 push    bx
  254.                 push    cx
  255.                 push    dx
  256.                 push    di
  257.  
  258.                 mov     bx, [bp + 6]    ; buffer to store value in
  259.                 mov     ax, [bp + 4]    ; the VALUE
  260.                 xor     cx,cx           ; make cx the counter 0
  261.                 mov     di,0Ah          ; make di the base, this could be
  262.                                         ; changed to say, 2 if we wanted to
  263.                                         ; output binary numbers
  264.                 xor     cx,cx
  265. putLoop:        xor     dx,dx
  266.                 div     di              ; divide everything by 10
  267.                 add     dx,30h          ; make it an ASCII 0 - 9
  268.                 push    dx
  269.                 inc     cx
  270.                 and     ax,ax
  271.                 jne     putLoop         ; if not all numbers converted yet
  272.  
  273. makeString:     pop     dx
  274.                 mov     [bx],dl
  275.                 inc     bx
  276.                 dec     cx
  277.                 and     cx,cx
  278.                 jne     makeString
  279.  
  280.                 mov     [bx],cl         ; terminate the string
  281.                 pop     di
  282.                 pop     dx
  283.                 pop     cx
  284.                 pop     bx
  285.                 pop     ax
  286.                 pop     bp
  287.  
  288.                 ret     4
  289. putDec          endp
  290.  
  291.  
  292. _CURON  PROC    NEAR    ; for small model
  293.     PUSH    BP      ; save stackframe
  294.     MOV    BP,SP
  295.     MOV     AH,3    ; get current cursor
  296.     XOR    BX,BX
  297.     INT     10h
  298.     AND     CH,1fh    ; force to ON condition
  299.     MOV    AH,1    ; set new cursor value
  300.     INT     10h
  301.     POP    BP
  302.     RET
  303. _CURON    ENDP
  304.  
  305. _CUROFF    PROC    NEAR    ; for small model
  306.     PUSH     BP    ; save stackframe
  307.     MOV    BP,SP
  308.     MOV    AH,3    ; get current cursor
  309.     XOR    BX,BX
  310.     INT     10h
  311.     OR    CH,20h    ; force to OFF condition
  312.     MOV    AH,1    ; set new cursor values
  313.     INT     10h
  314.     POP    BP
  315.     RET
  316. _CUROFF    ENDP
  317.  
  318.  
  319.  
  320.  
  321. END             main
  322.  
  323.  
  324. END     main
  325.