home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / UTILITY / TIMERS.ZIP / TIMER.ASM < prev    next >
Assembly Source File  |  1992-11-12  |  10KB  |  253 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 and it
  15. ;               also is in 40 column mode so it'll stand out, someday
  16. ;               I'll have color
  17.  
  18. ;Inputs:        string of numbers, i.e.  timer 10
  19. ;               where the number (here 10) would count down to 1
  20. ;Outputs:       MS-DOS ErrorLevel=0 if timeout occurs,
  21. ;               MS-DOS ErrorLevel=(ascii code of key hit) if it's aborted
  22.  
  23. ;  Timer to count from 5 to 1 is default
  24. ;  32767 is the maximum, strange I know, probably cause it's signed
  25. ;  that's about 9 hours, which is too long to leave the thing waiting anyways
  26.  
  27. ;  This is my FIRST program that I have written with a purpose, granted,
  28. ;       it has taken me 10 hours or so, so the code at this point is anything
  29. ;       but neat.  Two days in the making, and I only lifted ONE procedure
  30. ;       from somewhere else, that was the bin16asc, it's a it tough for me
  31. ;       right now.  Hopefully not at the end of the month
  32.  
  33.                 INCLUDE timer.mac
  34.  
  35.                 DOSSEG
  36.                 .MODEL SMALL
  37.                 .STACK 100h
  38.                 .DATA
  39.  
  40. keyHit          EQU     255
  41. cr              EQU     0dh
  42. lf              EQU     0ah
  43. eos             EQU     0
  44. blanks          DB      "     ",eos
  45. prompt          DB      "Count down from ",eos
  46. prompt2         DB      "Press any key to stop.",cr,lf,cr,eos
  47. intStr          DB      10(?)
  48.  
  49.                 .CODE
  50.  
  51. main            proc    near
  52.  
  53. ; The following code is very inefficent and should be replaced
  54.  
  55. readPSP:
  56.                 mov     bx,80h          ; charcater count of command tail
  57.                 cmp     BYTE PTR [bx],0
  58.                 jne     strip
  59.                 mov     dx,5
  60.                 jmp     start
  61.  
  62. strip:          inc     bx              ; find the start of the numbers
  63.                 cmp     BYTE PTR [bx], ' '
  64.                 je      strip
  65.                 mov     ax,00ffh        ; place 255 on for the search
  66.                 push    ax              ; place the sentinal value on
  67. popCorn:                                ; now we pop all NUMBERS on to the
  68.                                         ; stack!
  69.                 mov     al,BYTE PTR [bx]; take the first non-white space char
  70.                 mov     ah,00h          ; have to keep this thing a byte
  71.                 cmp     al,0dh          ; make sure end isn't here
  72.                 je      next
  73.                 sub     ax,0030h        ; make it a number, or try
  74.                 cmp     ax,0009h        ; see if this sucker is bigger than 9
  75.                 jg      next            ; too big don't push it, not a number
  76.                 push    ax              ; place it on the stack
  77.                 inc     bx
  78.                 jmp     popCorn         ; repeat it!
  79.  
  80. next:                                   ; ok, now we reverse the order,
  81.                                         ; we know that the first number is
  82.                                         ; the least significant number in
  83.                                         ; the sequence, all after raise a
  84.                                         ; power of ten, 10, 100, 1000
  85.                 mov     ax,00h          ; start count at zero
  86.                 mov     dx,0            ; initalize the destination
  87.                 mov     bx,01h          ; first place is the ones
  88.                 mov     cx,01h          ; this needs to be done too!
  89.                 jmp     nextPart        ; next part is for successive loops
  90. beginNext:
  91.                 mov     al,0ah          ; start it at ten
  92.                 mov     cx,00h          ; start at ten
  93.  
  94. adding:         cmp     al,0            ; this makes the loop add up to
  95.                                         ; the next power of ten (hard
  96.                                         ; to believe it'll work)
  97.                 je      nextPart
  98.                 add     cx,bx
  99.                 dec     al
  100.                 jmp     adding
  101.  
  102. nextPart:
  103.                 mov     bx,cx
  104.                 pop     ax              ; get the number
  105.                 cmp     ax,00ffh         ; make sure there's a number
  106.                 je      preStart        ; if there's no numbers, then
  107.                                         ; we need to give it the default
  108. loopStart:
  109.                 cmp     al,0            ; make sure we need to add still
  110.                 je      beginNext       ; done with this place
  111.                 add     dx,bx           ; add them
  112.                 dec     al              ; make it one less
  113.                 jmp     loopStart       ; get back!
  114.  
  115.  
  116.  
  117. preStart:       cmp     dx,0000h        ; make sure we got something
  118.                 jg      start           ; we did!
  119.                 mov     dx,05h          ; we didn't!
  120.  
  121. start:
  122.                 mov     cx,dx
  123.                 initRegs
  124.                 mov     ah,00h
  125.                 mov     al,00h
  126.                 int     10h
  127.                 push    ax
  128.                 mov     ax,OFFSET prompt2 ; place the offset in the stack
  129.                 push    ax
  130.                 call    showStr
  131.                 pop     ax
  132.                 push    cx
  133.                 push    dx
  134.                 mov     ah, 2ch
  135.                 int     21h
  136.                 mov     bh, dh     ; store starting seconds in bh
  137.                 pop     dx
  138.                 pop     cx
  139.                 
  140. main            endp
  141.  
  142. EnterLoop:
  143.                 push    cx
  144.                 push    dx
  145.                 mov     ah,2ch
  146.                 int     21h
  147.                 cmp     bh, dh
  148.                 je      pastInc    ; time hasn't changed
  149.  
  150.                 backup  5
  151.                 mov     ax,OFFSET blanks
  152.                 push    ax
  153.                 call    showStr
  154.  
  155.                 backup  25
  156.                 mov     bh,dh      ; time has changed, store new time
  157.                 pop     dx
  158.                 pop     cx
  159.                 dec     cx         ; subtract one from amount of seconds to go
  160.                 push    ax         ; save ax
  161.                 mov     ax,OFFSET prompt
  162.                 push    ax
  163.                 call    showStr
  164.                 pop     ax         ; restore ax
  165.  
  166. ; print out the number
  167.                 push    ax
  168.                 mov     ax, cx
  169.                 inc     ax
  170.                 push    ax
  171.                 lea     ax, intStr
  172.                 push    ax
  173.                 call    bin16Asc
  174.                 pop     ax
  175.                 push    ax
  176.                 mov     ax, OFFSET intStr
  177.                 push    ax
  178.                 call    showStr
  179.                 pop     ax
  180.                 jmp     keyPress
  181.  
  182. pastInc:
  183.                 pop     dx
  184.                 pop     cx
  185.  
  186. keyPress:
  187.                 mov     AH,0Bh     ; Check Keyboard Stats
  188.                 int     21h
  189.                 cmp     al, keyHit ; if there's been a keypress
  190.                 je      EndZero    ; Exit with a zero if keypressed
  191.  
  192.                 cmp     cx, 0
  193.                 jl      EndOne
  194.                 jmp     EnterLoop
  195.  
  196. EndZero:
  197.                 mov     ah,00h
  198.                 mov     al,02h
  199.                 int     10h
  200.                 mov     ah,08h     ; Read in keyboard
  201.                 int     21h        ; input goes into al, which is error code!
  202.                 mov     AH,4Ch     ; Terminate
  203.                 int     21h        ; We're history!
  204. EndOne:
  205.                 mov     ah,00h
  206.                 mov     al,02h
  207.                 int     10h
  208.                 mov     AH,4Ch     ; Terminate
  209.                 mov     AL,01      ; DOS exit code = 1
  210.                 int     21h        ; Cya L8r!
  211.  
  212.  
  213. ;******************************** PROCEDURES ********************************
  214.  
  215. showStr         proc    near            ; procedure to display a string
  216.                 push    bp
  217.                 mov     bp,sp           ; bp will point to last value of
  218.                                         ; the item pushed onto stack
  219.                                         ; before procedure call
  220.                 push    ax
  221.                 push    bx
  222.                 push    dx              ; store the original value of dx
  223.                 mov     bx, [bp + 4]    ; bx will now point to the string on
  224.                                         ; the stack
  225.                 mov     ah,02h          ; print one char at a time to screen
  226. whileC:         mov     dl,[bx]         ; move the address of the in buffer
  227.                                         ; into the dl register
  228.                 cmp     dl,eos          ; if the current character referenced is
  229.                                         ; 0, then it's the end of line
  230.                 je      endWhile        ; if it is equal to zero then
  231.                                         ; jump end while
  232.                 int     21h             ; execute the character display int.
  233.                 inc     bx              ; increment the counter
  234.                 jmp     whileC          ; repeat the loop
  235.  
  236. endWhile:
  237.                 pop     dx              ; reinstate the value of dx from before
  238.                                         ; the display procedure
  239.                 pop     bx
  240.                 pop     ax
  241.                 pop     bp
  242.  
  243.                 ret     2               ; return out of the procedure and kill
  244.                                         ; last byte pushed onto stack,
  245.                                         ; this gets rid of the item passed to
  246.                                         ; the procedure
  247. showStr         endp
  248.  
  249.                 INCLUDE bin16asc.asm    ; Needed for the time to be displayed!
  250.  
  251.  
  252. END     main
  253.