Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

capturing the screen contents

Status
Not open for further replies.

bigbeebrian

Programmer
Jan 15, 2001
9
US
Can anyone tell me why this program doesn't work. I'm writing a program that captures the screen contents then clear the screen then prompts the user to "press any key". After the user presses a key the original contents should pop back to the screen.

This is what I have so far.

.MODEL SMALL
.386

.STACK 1024


.DATA

Message DB 'Press Any Key$'
videoSeg = 0B800h
scrnStorage DW (25*80*2)
buffer DW 4000 dup(?)

.CODE

main PROC
mov ax,@data ;setup data segment
mov ds,ax

mov si,videoSeg ;point DS:SI to video segment
mov di,si
mov si,0
mov di,seg buffer ;point ES:DI to buffer
mov es,di
mov di,offset buffer
cld ;direction = up
mov cx,scrnStorage ;number of words to copy
rep movsw ;copy DS:SI to ES:DI

;Clear Screen
mov ah,0fh ;function
int 10h ;bios video interrupt
;current video mode returned in AL

mov ah,0 ;function 0 = set current video mode
;al = desired video mode
int 10h ;bios video interrupt


;Wait for Keystroke
mov ah,9 ;display "press any key"
mov dx,offset Message
int 21h

mov ah,010h ;wait for keystroke
int 16h ;call keyboard interrupt




mov ah,4ch ;give control back
mov al,0 ;and end program
int 21h

main ENDP
END main
 
Point #1:
You did not set ds to videoSeg. Look at that point in the code carefully where you're supposed to load it.
Point #2:
If you're going to change ds, you better change it back before you do anything that expects ds to point to the data segment... such as print "press a key"
Point #3:
If my memory serves me right, cx in conjunction with a rep represents the number of elements. Since movsw moves words at a time, you want to copy only 2000 words. Remember that 4000 represents BYTES, not words.
Point #4:
You never put the buffer back.
"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Point #1:
You did not set ds to videoSeg. Look at that point in the code carefully where you're supposed to be loading it.
Point #2:
If you're going to change ds, you better change it back before you do anything that expects ds to point to the data segment... such as print "press a key"
Point #3:
If my memory serves me right, cx in conjunction with a rep represents the number of elements. Since movsw moves words at a time, you want to copy only 2000 words. Remember that 4000 represents BYTES, not words.
Point #4:
You never put the buffer back.
"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
this is my code with corrections. I think my only problem now is , how do I print the buffer back to the screen?

.MODEL SMALL
.386

.STACK 1024


.DATA

Message DB 'Press Any Key$'
videoSeg = 0B800h
scrnStorage = (25*80*2)
buffer DW 4000 dup(?)

.CODE

main PROC



;capture screen
mov si,videoSeg ;point DS:SI to video segment
mov ds,si
mov si,0
mov di,seg buffer ;point ES:DI to buffer
mov es,di
mov di,offset buffer
cld ;direction = up
mov cx,2000 ;number of words to copy
rep movsw ;copy DS:SI to ES:DI

;Clear Screen
mov ah,0fh ;function
int 10h ;bios video interrupt
;current video mode returned in AL

mov ah,0 ;function 0 = set current video mode
;al = desired video mode
int 10h ;bios video interrupt


mov ax,@data ;setup data segment
mov ds,ax

;Wait for Keystroke
mov ah,9 ;display "press any key"
mov dx,offset Message
int 21h




mov ah,010h ;wait for keystroke
int 16h ;call keyboard interrupt




mov ah,4ch ;give control back
mov al,0 ;and end program
int 21h

main ENDP
END main
 
Hi,

to place it back, you do exactly the same, set DS:SI to the source, ES:DI to the target, cx to the number of words, and then repsw. Since you want to place it back now, the source is the buffer, and the target is the screen.

Wouter Dijkslag

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top