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 >
Wrap
Assembly Source File
|
1992-11-12
|
10KB
|
253 lines
TITLE TIMER.ASM
;Author: Charles R. Grosvenor Jr.
;Date Written: Novemeber 11-12, 1992
;Purpose: Utility for BBS
; This allows me to break out of the autoexec.bat loop file
; before the stupid thing loads the BBS, helpful if the modem
; is having problems or if I want to run a program other than
; the BBS
;Why Assembly: C and Pascal created huge, psycho hose beast programs of
; about 30K (ok, it's miniscule anyways) but this is a little
; over 2K, think of ALL that SPACE I save... >grin<
; it does seem to exit it out of the loop quicker and it
; also is in 40 column mode so it'll stand out, someday
; I'll have color
;Inputs: string of numbers, i.e. timer 10
; where the number (here 10) would count down to 1
;Outputs: MS-DOS ErrorLevel=0 if timeout occurs,
; MS-DOS ErrorLevel=(ascii code of key hit) if it's aborted
; Timer to count from 5 to 1 is default
; 32767 is the maximum, strange I know, probably cause it's signed
; that's about 9 hours, which is too long to leave the thing waiting anyways
; This is my FIRST program that I have written with a purpose, granted,
; it has taken me 10 hours or so, so the code at this point is anything
; but neat. Two days in the making, and I only lifted ONE procedure
; from somewhere else, that was the bin16asc, it's a it tough for me
; right now. Hopefully not at the end of the month
INCLUDE timer.mac
DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
keyHit EQU 255
cr EQU 0dh
lf EQU 0ah
eos EQU 0
blanks DB " ",eos
prompt DB "Count down from ",eos
prompt2 DB "Press any key to stop.",cr,lf,cr,eos
intStr DB 10(?)
.CODE
main proc near
; The following code is very inefficent and should be replaced
readPSP:
mov bx,80h ; charcater count of command tail
cmp BYTE PTR [bx],0
jne strip
mov dx,5
jmp start
strip: inc bx ; find the start of the numbers
cmp BYTE PTR [bx], ' '
je strip
mov ax,00ffh ; place 255 on for the search
push ax ; place the sentinal value on
popCorn: ; now we pop all NUMBERS on to the
; stack!
mov al,BYTE PTR [bx]; take the first non-white space char
mov ah,00h ; have to keep this thing a byte
cmp al,0dh ; make sure end isn't here
je next
sub ax,0030h ; make it a number, or try
cmp ax,0009h ; see if this sucker is bigger than 9
jg next ; too big don't push it, not a number
push ax ; place it on the stack
inc bx
jmp popCorn ; repeat it!
next: ; ok, now we reverse the order,
; we know that the first number is
; the least significant number in
; the sequence, all after raise a
; power of ten, 10, 100, 1000
mov ax,00h ; start count at zero
mov dx,0 ; initalize the destination
mov bx,01h ; first place is the ones
mov cx,01h ; this needs to be done too!
jmp nextPart ; next part is for successive loops
beginNext:
mov al,0ah ; start it at ten
mov cx,00h ; start at ten
adding: cmp al,0 ; this makes the loop add up to
; the next power of ten (hard
; to believe it'll work)
je nextPart
add cx,bx
dec al
jmp adding
nextPart:
mov bx,cx
pop ax ; get the number
cmp ax,00ffh ; make sure there's a number
je preStart ; if there's no numbers, then
; we need to give it the default
loopStart:
cmp al,0 ; make sure we need to add still
je beginNext ; done with this place
add dx,bx ; add them
dec al ; make it one less
jmp loopStart ; get back!
preStart: cmp dx,0000h ; make sure we got something
jg start ; we did!
mov dx,05h ; we didn't!
start:
mov cx,dx
initRegs
mov ah,00h
mov al,00h
int 10h
push ax
mov ax,OFFSET prompt2 ; place the offset in the stack
push ax
call showStr
pop ax
push cx
push dx
mov ah, 2ch
int 21h
mov bh, dh ; store starting seconds in bh
pop dx
pop cx
main endp
EnterLoop:
push cx
push dx
mov ah,2ch
int 21h
cmp bh, dh
je pastInc ; time hasn't changed
backup 5
mov ax,OFFSET blanks
push ax
call showStr
backup 25
mov bh,dh ; time has changed, store new time
pop dx
pop cx
dec cx ; subtract one from amount of seconds to go
push ax ; save ax
mov ax,OFFSET prompt
push ax
call showStr
pop ax ; restore ax
; print out the number
push ax
mov ax, cx
inc ax
push ax
lea ax, intStr
push ax
call bin16Asc
pop ax
push ax
mov ax, OFFSET intStr
push ax
call showStr
pop ax
jmp keyPress
pastInc:
pop dx
pop cx
keyPress:
mov AH,0Bh ; Check Keyboard Stats
int 21h
cmp al, keyHit ; if there's been a keypress
je EndZero ; Exit with a zero if keypressed
cmp cx, 0
jl EndOne
jmp EnterLoop
EndZero:
mov ah,00h
mov al,02h
int 10h
mov ah,08h ; Read in keyboard
int 21h ; input goes into al, which is error code!
mov AH,4Ch ; Terminate
int 21h ; We're history!
EndOne:
mov ah,00h
mov al,02h
int 10h
mov AH,4Ch ; Terminate
mov AL,01 ; DOS exit code = 1
int 21h ; Cya L8r!
;******************************** PROCEDURES ********************************
showStr proc near ; procedure to display a string
push bp
mov bp,sp ; bp will point to last value of
; the item pushed onto stack
; before procedure call
push ax
push bx
push dx ; store the original value of dx
mov bx, [bp + 4] ; bx will now point to the string on
; the stack
mov ah,02h ; print one char at a time to screen
whileC: mov dl,[bx] ; move the address of the in buffer
; into the dl register
cmp dl,eos ; if the current character referenced is
; 0, then it's the end of line
je endWhile ; if it is equal to zero then
; jump end while
int 21h ; execute the character display int.
inc bx ; increment the counter
jmp whileC ; repeat the loop
endWhile:
pop dx ; reinstate the value of dx from before
; the display procedure
pop bx
pop ax
pop bp
ret 2 ; return out of the procedure and kill
; last byte pushed onto stack,
; this gets rid of the item passed to
; the procedure
showStr endp
INCLUDE bin16asc.asm ; Needed for the time to be displayed!
END main