Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!VAX1.CC.UAKRON.EDU!r3jjs From: r3jjs@VAX1.CC.UAKRON.EDU (Jeremy J Starcher) Newsgroups: comp.binaries.ibm.pc.d Subject: Re: Program Usage Program needed Message-ID: <772@VAX1.CC.UAKRON.EDU> Date: 28 Oct 90 18:41:04 GMT References: <43005@eerie.acsu.Buffalo.EDU> Reply-To: r3jjs@VAX1.CC.UAKRON.EDU (Jeremy J Starcher) Distribution: na Organization: U of Akron Computer Center, Ohio Lines: 425 >>I'm looking for a program that will monitor the amount of time that I >>spend in a program. I have written a program for work that I can upload the .ASM source code for that keeps a time log. You need to manually start and stop it, but it works well for us. ; ***** Assemble as a .COM file ***** CR EQU 13 LF EQU 10 W EQU WORD PTR B EQU BYTE PTR page 66,132 page ; X:0 ; ; ; cseg segment para public 'code' zeno proc far assume cs:cseg, ds:cseg, es:cseg, ss:cseg org 100h ; for .COM file ; ; ;------------------------------- ; enter here on initial load ;------------------------------- ; start: ; jmp near ptr load_pgm ; old_key DW 00, 00 ; ;------------------------------- ; enter here from int 10h ;------------------------------- ; ;---------------------- The starting code ------------------ StartTime: DB 'Started ',0 EndTime: DB 'Ended ',0 PrnID DW 0 ;Which printer gets the goods Buffer: DB 10 dup (32) NewLine: DB 13,10,0 ;CR LF,0 ;---------------------- The memory resident code ------------------- ;====================== Subroutines ======================== BIN_ASCII PROC NEAR ;On Entry ---> ; AX = Number to be converted ; BX = Address of Buffer ; ;On Exit ---> ; BX = Address of Buffer ; The buffer contains an ASCIIZ string ; CX = Length of String PUSH DX ;SAVE AFFECTED REGISTERS PUSH SI PUSH AX ;SAVE BINARY VALUE MOV CX,6 ;FILL BUFFER WITH SPACES FILL_BUFFER: MOV BYTE PTR CS:[BX],' ' ;BLANK INC BX LOOP FILL_BUFFER MOV SI,10 ;GET READY TO DIVIDE BY 10 OR AX,AX ;IF VALUE IS NEGITIVE JNS CLR_DVD NEG AX ;MAKE IT POSITIVE CLR_DVD: SUB DX,DX ;CLEAR UPPER HALF OF DIVIDEND DIV SI ;DIVIDE AX BY 10 ADD DX,'0' ;CONVERT REMAINDER TO ASCII DIGIT DEC BX ;BACK UP THROUGH BUFFER MOV CS:[BX],DL ;STORE THIS CHAR IN THE STRING INC CX ;COUNT CONVERTED CHARACTER OR AX,AX ;ALL DONE? JNZ CLR_DVD ;NO. GO GET NEXT DIGIT POP AX ;YES. RETRIEVE ORIGINAL VALUE OR AX,AX ;WAS IT NEGITIVE? JNS NO_MORE DEC BX ;YES. STORE SIGN MOV B CS:[BX],'-' INC CX ;AND INCREASE CHARACTER COUNT NO_MORE: POP SI POP DX ;Turn the number into an ASCIIZ string PUSH BX PUSH CX BA1: INC BX LOOP BA1 MOV W CS:[BX],0 POP CX POP BX RET ;RETURN TO CALLER BIN_ASCII ENDP ;----------------------------------------------------------------------------- DumpString PROC NEAR ;On Entry ---> CS:BX Holds address of ASCIIZ string PUSH AX D1: MOV AL, CS:[BX] ;Get Current Character CMP AL, 0 ;At the end of the line? JE D2 ;Yes - then quit the nonsense CALL DumpChar INC BX ;Go on to next character JMP D1 ;Loop again. D2: ;EnddString: POP AX RET DumpString ENDP ;----------------------------------------------------------------------------- DumpChar PROC NEAR ;On Entry --> Char in AL ; CS:[PrnID] = Printer number (0..1) PUSH AX PUSH DX MOV DX, CS:[PrnID] ;Get the printer ID Number (0 or 1) MOV AH, 0 ;Send One Byte To Printer INT 17h ;GO.. POP DX POP AX RET DumpChar ENDP ;----------------------------------------------------------------------------- DumpTime PROC NEAR PUSH AX PUSH BX PUSH CX PUSH DX MOV AH,02Ch ;Get Time INT 21h ;Get it ;Time Returned in this form ;CH = Hour (0..23) ;CL = Minutes (0..59) ;DH = Seconds (0..59) ;DL = Hundreds (0..99) ; These are not real hundreths of a ; second since the clock cannot ; do any better than 1/20 of a second. ; However, this does return an even ; spread over the number range and is ; OK for a random seed. PUSH CX ;Print the Hour PUSH AX MOV AL,CH MOV AH,0 MOV BX, OFFSET(Buffer) CALL BIN_ASCII CALL DumpString MOV AL,':' CALL DumpChar ;Send the colon seperator POP AX POP CX ;Restore CX PUSH CX ;However, we still need to hang on to it ;Print the Minute PUSH AX MOV AL, CL MOV AH, 0 MOV BX, OFFSET(Buffer) CALL BIN_ASCII CMP CX,1 ;Is our output string only one char? JNE T1 ;No - then just print the minute MOV AL, '0' ;Else - Show a preceding '0' CALL DumpChar T1: CALL DumpString POP AX POP CX POP DX POP CX POP BX POP AX RET DumpTime ENDP ;----------------------------------------------------------------------------- DumpDate PROC NEAR PUSH AX PUSH BX PUSH CX PUSH DX MOV AH,02Ah ;Get Time INT 21h ;Get it ;Date Returned in this form ;DH = Month Number (1..12) ;DL = Day of Month (1..28,29,30,31) ;CX = Year (1980..2099) ;AL = Day of week (0..6) Sun = 0 PUSH CX ;Print the Month PUSH AX MOV AL,DH MOV AH,0 MOV BX, OFFSET(Buffer) CALL BIN_ASCII CALL DumpString MOV AL,'-' CALL DumpChar ;Send the hyphen seperator POP AX POP CX ;Restore CX PUSH CX ;However, we still need to hang on to it ;Print day of month PUSH AX MOV AL,DL MOV AH,0 MOV BX, OFFSET(Buffer) CALL BIN_ASCII CALL DumpString MOV AL,'-' CALL DumpChar ;Send the hyphen seperator POP AX POP CX ;Restore CX PUSH CX ;However, we still need to hang on to it ;Print the Year PUSH AX MOV AX, CX MOV BX, OFFSET(Buffer) CALL BIN_ASCII CALL DumpString POP AX POP CX POP DX POP CX POP BX POP AX RET DumpDate ENDP ;----------------------------------------------------------------------------- keyboard_int: STI CMP AH,0 JE ki0 JMP dword ptr cs:old_key ki0: PUSHF ;Simulate Org INT call call dword ptr cs:old_key PUSH BX ;We modify BX MOV BX, 0 ;Clear it out for out check later CMP AL, 0 ;Check if we have a extended Key JNE kidone ;No- don't bother with the rest CMP AH,078h ;ALT 1? JNE TryAlt2 ;No, try an ALT 2 LEA BX, StartTime JMP SendOut TryAlt2: CMP AH, 079h ;ALT 2? JNE kidone ;No - give up LEA BX, EndTime JMP SendOut SendOut: CALL DumpString ;Print "Start" or "End" CALL DumpTime ;Print the time MOV AL,' ' ;Print a space seperator CALL DumpChar ; " CALL DumpDate ;Print the Date LEA BX, NewLine ;Print a CR/LF CALL DumpString ; " MOV AX, 0000h ;Return NO KEY to the calling prg kidone: POP BX CLI IRET ; end_core: ; ;------ Text needed be 'load_prg' ; install_msg DB 'IMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM;',CR,LF DB ': TIME KEEPER :',CR,LF DB 'GDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD6',CR,LF DB ': ALT 1 Start :',CR,LF DB ': ALT 2 End :',CR,LF DB 'GDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD6',CR,LF DB ': By: Jeremy J Starcher :',CR,LF DB 'HMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM<',CR,LF DB '$' ; finish_msg DB ' .. Installed //',CR,LF,'$' Usage: DB CR,LF,CR,LF,CR,LF DB 'Use the following format:',CR,LF DB CR,LF DB 'timekeep /x',CR,LF DB CR,LF DB 'where x = printer number (1 or 2)',CR,LF,'$' ; retry_msg db 13,10,'No Action: Invalid Command Line',13,10,7,'$' ;------------------------------- ; enter here to load program ;------------------------------- ; load_pgm: ; ; ;--- Print the welcome message lea dx,install_msg ; get message mov ah,9h ; for print fn int 21h ; print message ;Search for command line parameter MOV CL, CS:[80h] ;Parameter length CMP CL, 0 JE NoGood ;Can't use no parameters MOV BX, 81h ;Start of parameters I1: MOV AL, CS:[BX] ;Get a character CMP AL, '/' ;Is it our flag char? JE GetPrnNum ;Yes - get the printer number INC BX ;Advance to the next character LOOP I1 JMP NoGood ;Can't find it, too bad. GetPrnNum: INC BX ;Move onto the the next character MOV AL, CS:[BX] ;Get the ASCII value .. SUB AL, '0' ;..By subtraction MOV AH,0 ;Clear the high order byte CMP AX, 1 JB NoGood ;Reject if below One CMP AX, 2 DEC AX ;Correct AX (Printers start at 0) MOV CS:[PrnID],AX ;Save the printer ID JMP Good NoGood: MOV AH,9 ;Print a string LEA DX, Usage ;Show them the usage INT 21h ;DO IT! MOV AH,0 ;End Normally INT 21h ;NOW! Good: ; set keyboard interrupt ; push es ; save mov ax,3516h ; to get vector int 21h ; get vector mov old_key[0],bx ; store offset mov old_key[2],es ; store segment pop es ; restore mov ax,2516h ; to set keyboard vector lea dx,keyboard_int ; get offset; ds OK int 21h ; set vector ; ; print messages; terminate and stay resident ; lea dx,finish_msg ; get termination mov ah,9h ; for print fn int 21h ; print ternination lea ax,end_core ; last address in core add ax,2Fh ; make bumper mov cl,4 ; for shift shr ax,cl ; convert to paras mov bx,ax ; no. paras to keep mov dx,ax ; same mov ah,4Ah ; for setblock int 21h ; do setblock mov ax,3100h ; for keep; no exit code int 21h ; exit and stay resident ; zeno endp cseg ends end start ----------------------------------------------------------------------------- Please, no major flames about the code. It was written in a hurry (I had only an hour and a half or so). It should assemble under MASM, although I use the A86 assembler myself. -- --------------------------+--------------------------------------------------- Jeremy J Starcher ! No programmer programs in LOGO after reaching r3jjs@vax1.cc.uakron.edu ! age 14... r3jjs@akronvm.bitnet !