×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

capturing the screen contents

capturing the screen contents

capturing the screen contents

(OP)
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

RE: capturing the screen contents

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."

RE: capturing the screen contents

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."

RE: capturing the screen contents

(OP)
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

RE: capturing the screen contents

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
 
http://www.wody.demon.nl
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close