home *** CD-ROM | disk | FTP | other *** search
- PAGE 57,132
- TITLE SNAP -- Screen Snapshot Program.
- NAME SNAP
- ;
- ; This program takes a "snapshot" of the current screen display
- ; and writes it to SNAP.0nn, where "SNAP.0nn" is the next avail-
- ; able file in the series SNAP.001, SNAP.002, . . . SNAP.099.
- ;
- ; If there are more than 99 SNAP files, the program aborts.
- ;
- ; Program by Harry M. Murphy, 29 December 1986.
- ; Version: 10 January 1988.
- ;
- .RADIX 10
- BEL EQU 07H ;ASCII bell code.
- CR EQU 0DH ;Carriage Return code.
- CTLZ EQU 1AH ;Control-Z code.
- DOS EQU 21H ;DOS interrupt.
- LF EQU 0AH ;Line Feed code.
- VIDEO EQU 0B800H ;Start of video memory.
- ;
- SNAP SEGMENT 'CODE'
- ORG 100H
- ASSUME CS:SNAP,DS:SNAP,ES:SNAP
- ;
- START: JMP BEGIN
- ;
- FHANDLE DW 0
- VERNUM DW 0
- ENDMSG DB '>>>>>>>>>> Screen snapshot written to '
- FNAME DB 'SNAP.000',0,CR,LF,'$'
- VERERR DB 'Too many SNAP outputs! (SNAP.001 ==> SNAP.099!)'
- DB CR,LF,BEL,'$'
- OPNERR DB 'OPEN ERROR!',CR,LF,'$'
- WRTERR DB 'WRITE ERROR!',CR,LF,'$'
- CLSERR DB 'CLOSE ERROR!',CR,LF,'$'
- EVEN
- ;
- BEGIN: MOV BX,25 ;BX counts the 25 rows.
- MOV AX,VIDEO ;ES points to
- MOV ES,AX ; the video buffer segment.
- XOR AX,AX ;SI indexes the
- MOV SI,AX ; video buffer and
- MOV DI,AX ; DI indexes the output buffer.
- ;
- L1: MOV CX,80 ;Main loop starts here.
- ; ;Initialize CX for 80 columns.
- L2: MOV AL,BYTE PTR ES:[SI] ;Copy byte from video buffer
- MOV BUFFER[DI],AL ; to output buffer via AL.
- INC SI ;Video buffer consists of double
- INC SI ; bytes; increment twice.
- INC DI ;Increment output buffer
- LOOP L2 ; and loop for 80 columns.
- ;
- L3: DEC DI ;Scan the output
- CMP BUFFER[DI],' ' ; buffer for last non-blank
- JE L3 ; character.
- ;
- INC DI ;Append
- MOV BUFFER[DI],CR ; CR
- INC DI ; and
- MOV BUFFER[DI],LF ; LF.
- INC DI ;Increment index,
- DEC BX ; decrement row count and
- JNZ L1 ; loop for next row.
- ;
- MOV BUFFER[DI],CTLZ ;Append final Control-Z.
- INC DI ;DI = final byte count.
- ;
- OPEN: INC VERNUM ;Increment the file version
- MOV AX,VERNUM ; number and copy to AX.
- MOV DX,OFFSET VERERR ;If more than
- CMP AX,99 ; 99 versions,
- JA EXIT ; abort with an error message.
- ;
- MOV BL,10 ;Load BL with decimal divisor.
- DIV BL ;Translate the
- ADD AH,'0' ; file
- MOV FNAME+7,AH ; version
- XOR AH,AH ; number
- DIV BL ; into the
- ADD AH,'0' ; file
- MOV FNAME+6,AH ; extension.
- MOV AX,4300H ;Use "get file attribute"
- MOV DX,OFFSET FNAME ; to ensure that the
- INT DOS ; file doesn't already
- JNC OPEN ; exist.
- ;
- MOV AH,3CH ;Open
- XOR CX,CX ; output
- MOV DX,OFFSET FNAME ; file,
- INT DOS ; SNAP.0nn.
- MOV DX,OFFSET OPNERR ;If error, exit with
- JC EXIT ; error message.
- ;
- MOV FHANDLE,AX ;Save the file handle.
- ;
- WRITE: MOV AH,40H ;Write
- MOV BX,FHANDLE ; output
- MOV CX,DI ; buffer
- MOV DX,OFFSET BUFFER ; to output
- INT DOS ; file.
- JNC CLOSE ;If OK, skip to close.
- ;
- MOV DX,OFFSET WRTERR ;If not,
- MOV AH,09H ; output an
- INT DOS ; error message.
- ;
- CLOSE: MOV AH,3EH ;Close
- MOV BX,FHANDLE ; the output
- INT DOS ; file.
- MOV DX,OFFSET CLSERR ;If error, exit
- JC EXIT ; with error message.
- ;
- DONE: MOV FNAME+8,'.' ;Replace zero byte with ".".
- MOV DX,OFFSET ENDMSG ;"Snapshot written" message.
- ;
- EXIT: MOV AH,09H ;Display
- INT DOS ; message and
- MOV AX,4C00H ; terminate
- INT DOS ; this process.
- ;
- BUFFER0 DB 0 ;BUFFER MUST be preceded by a zero byte and
- BUFFER DB 0 ; MUST be the last data block in SNAP.
- SNAP ENDS
- END START