home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.update.uu.se
/
ftp.update.uu.se.2014.03.zip
/
ftp.update.uu.se
/
pub
/
rainbow
/
msdos
/
misc
/
task.lzh
/
TASK.ASM
next >
Wrap
Assembly Source File
|
1985-12-06
|
11KB
|
306 lines
page 60,132
title TASK - Timed ASK for batch files
subttl (C) Copyright 1985 by System Enhancement Associates
page
;
; This program allows the use of yes-or-no questions in batch
; files, while placing a time limit on how long the user has before
; an answer must be given. Here's an example of how to use it:
;
; task Are you there?
;
; TASK will print the question "Are you there? " and wait up to
; twenty seconds for an answer. You can change the time limit
; by preceeding the question with the number of seconds you wish
; to allow. Here's how to ask a question with a ten second limit:
;
; task 10 Shall we begin?
;
; TASK exits with an error level of zero if a "yes" is given,
; or one if a "no" is given, or two if no answer is given.
; Escape and Enter count as "no answer". Ctrl Break counts as "no".
;
; Most people want to assume a default of either "yes" or "no" when
; the time limit expires. This can be easily done in the batch
; file. Here's a way to make "no" the default:
;
; task Are you sure you want to do this?
; if errorlevel 1 goto dothing
;
; Since "if errorlevel 1" really means "if the error level is 1 or
; higher", then the timeout error level of 2 will also work. Here
; is a way to make "yes" the default:
;
; task Last chance! Are you sure?
; if not errorlevel 2 if errorlevel 1 goto dothing
;
; The DOS manual never really says that you can combine IF
; statements like that, but we've tried it and it works.
;
; You can also leave off the question and use TASK for a timed
; delay. Here's how to get a thirty second delay:
;
; task 30
;
; The delay can be cut short by any of Y, N, Escape, Enter, or
; Ctrl Break.
;
page
code segment
assume ds:code, ss:code, cs:code, es:code
org 100h
task proc near ;simpler for COM file interface
jmp start ;skip over our data
banner db 'TASK; Version '
TED_VERSION DB '1.32, created on '
TED_DATE DB '12/06/85 at '
TED_TIME DB '11:00:00',13,10
db '(C) COPYRIGHT 1985 by System Enhancement Associates;'
db ' ALL RIGHTS RESERVED',13,10,10
db 'Timed ASK for batch files.'
db ' Error level 0=Yes, 1=No, 2=No answer',13,10,10
db 'Usage: task [<n>] [<q>]',13,10
db 'Where: <n> = Time limit in seconds (default 20)',13,10
db ' <q> = Question to ask',13,10,'$'
yorn db '(Y or N) $'
saidno db 'No',13,10,'$'
saidyes db 'Yes',13,10,'$'
unsaid db ' (no answer given)',13,10,'$'
tgtday db 0 ;target time of day
tgthr db 0
tgtmin db 0
tgtsec db 0
tgthun db 0
outyorn db 0 ;true when "Y or N" message displayed
outsec db 0 ;output timer
abstim dw ? ;target time in seconds
timcon proc near ;convert time to number of seconds
mov dl,dh ;save seconds
xor dh,dh
push dx
mov dl,cl ;save minutes
push dx
xor ah,ah ;convert hours to minutes
mov al,ch
mov dx,60
mul dx
pop dx ;add minutes
add ax,dx
mov dx,60 ;convert minutes to seconds
mul dx
pop dx ;add seconds
add ax,dx
ret ;return seconds in ax
timcon endp
count proc near ;show a countdown
cmp dh,outsec ;see if time for a tick
jz countx ;not yet
mov byte ptr outsec,dh
call timcon ;calculate seconds left
mov dx,word ptr abstim
sub dx,ax
cmp dx,9 ;small enough to show?
jg countx ;not yet
cmp dx,0 ;too small to show?
jle countx ;yep
mov ah,2 ;display character
add dx,'0' ;seconds left
int 21h
mov dx,8 ;backspace
int 21h
countx: ret
count endp
noargs: mov dx,offset banner ;point to no args message
mov ah,9 ;print string
int 21h
ret ;exit
start: mov ax,2523h ;take over breaks
mov dx,offset broken ;equivalent to a no
int 21h
mov ah,2ch ;get time of day
int 21h
mov byte ptr tgtday,al ;store it
mov byte ptr tgthr,ch
mov byte ptr tgtmin,cl
mov byte ptr tgtsec,dh
mov byte ptr tgthun,dl
xor ch,ch ;zero out ch
mov cl,ds:80h ;get length of unformatted arguments
cmp cx,1
jle noargs ;no args given!
mov di,81h ;point at unformatted args
cld
mov al,' '
repz scasb ;scan to a non-space
dec di ;back up to start of delay
inc cx
xor ax,ax ;clear out accumulator
digloop: xor bx,bx ;clear out scratch
jcxz digend ;if more args
mov bl,[di] ;get a digit?
cmp bl,'0'
jl digend
cmp bl,'9'
jg digend
sub bl,'0' ;convert to true value
mov dx,10 ;set multiplier
mul dx ;decimal shift
add ax,bx ;add in new digit
dec cx ;one less digit
inc di ;point to next digit
jmp digloop ;go for next digit
digend: push ax ;save the delay time
mov al,' '
repz scasb ;scan to a non-space
mov bx,cx
mov byte ptr [di+bx],'$';terminate the question
dec di ;back up to start of question
pop ax ;get back delay time
cmp ax,0 ;did we get a delay?
jnz gotdel ;yes
mov ax,20 ;no - use default
gotdel: add al,byte ptr tgtsec ;get target time
xor bx,bx
mov bl,byte ptr tgtmin
xor cx,cx
mov cl,byte ptr tgthr
xor dx,dx
mov dl,byte ptr tgtday
secloop: cmp ax,60 ;seconds modulo 60
jl minloop
sub ax,60
inc bx
jmp secloop
minloop: cmp bx,60 ;minutes modulo 60
jl hrloop
sub bx,60
inc cx
jmp minloop
hrloop: cmp cx,24 ;hours modulo 24
jl dayloop
sub cx,24
inc dx
jmp hrloop
dayloop: cmp dx,7 ;days modulo 7
jl tgtfixed
sub dx,7
jmp dayloop
tgtfixed:mov byte ptr tgtsec,al ;store fixed target time
mov byte ptr tgtmin,bl
mov byte ptr tgthr,cl
mov byte ptr tgtday,dl
mov ch,cl ;set up for time conversion
mov cl,bl
mov dh,al ;set up for time conversion
call timcon ;calculate partial answer for timer
mov word ptr abstim,ax
mov dx,di ;point to question
mov ah,9 ;print string
int 21h
mov ah,2 ;display character
mov dl,' '
int 21h
loop: mov ah,0bh ;check input status
int 21h
cmp al,0
jz nogot ;nothing typed yet
mov ah,8 ;input char with no echo
int 21h
cmp al,13
jz timeup ;he refused comment
cmp al,27
jz timeup ;he escaped the question
and al,5fh ;mask to uppercase
cmp al,'Y'
jz gotyes ;he said yes
cmp al,'N'
jz gotno ;he said no
mov dl,7 ;unknown input
mov ah,2 ;beep at him
int 21h
cmp outyorn,0 ;have we said this yet?
jnz nogot ;yes - don't repeat
mov ah,9 ;print string
mov dx,offset yorn
int 21h
mov outyorn,1
nogot: mov ah,2ch ;get time
int 21h
cmp al,byte ptr tgtday ;check time
jg timeup
jl showout
cmp ch,byte ptr tgthr
jg timeup
jl showout
cmp cl,byte ptr tgtmin
jg timeup
jl showout
cmp dh,byte ptr tgtsec
jg timeup
jl showout
cmp dl,byte ptr tgthun
jg timeup
showout: call count ;show a countdown timer
jmp short loop
gotno: mov dx,offset saidno ;point to echo
mov ah,9 ;print string
int 21h
broken: mov ah,4ch ;exit with error level
mov al,1
int 21h
gotyes: mov dx,offset saidyes ;point to echo
mov ah,9 ;print string
int 21h
mov ah,4ch ;exit with error level
mov al,0
int 21h
timeup: mov dx,offset unsaid ;point to echo
mov ah,9 ;print string
int 21h
mov ah,4ch ;exit with error level
mov al,2
int 21h
task endp
code ends
end task