Click to See Complete Forum and Search --> : clear screen


lurner
January 26th, 2005, 02:34 AM
hello I am trying to clear the screen after the user has selected a menu option but when it clears the data and prints the new menu the new menu is placed where it would be as if the old menu was still there for example:

Main Menu

1. Start
2. End

Make a menu selection:

If users selects 1 the output is:

................................
................................
................................ New Menu

1. Continue
2. End

Make a menu selection:

The (...) represent a blank line, which is where the old menu was.

I just want to clear the screen and replace the old text with the new menu text, without having the extra line feeds, here is my code:


.model small
.stack
.data
sMOTD db "Start Menu",13,10,13,10
db "1. Start",13,10
db "2. End",13,10,13,10
db "Make a menu selection:","$"

sENUM db "New Menu",13,10,13,10
db "1. Continue",13,10
db "2. End",13,10,13,10
db "Make a menu selection:","$"

cls macro ;start macro - (clear screen)
push ax
push bx
push cx
push dx
mov ah,7 ;scroll down function
mov al,0 ;0 = entire window
mov cx,0 ;0,0 as upper left corner.
mov dx,184fh ;24,79 as lower right corner.
mov bh,7 ;normal attribute
int 10h ;call bios
pop dx ;restore scratch registers
pop cx
pop bx
pop ax
endm ;end macro - (clear screen)

.code

main proc
mov ax,seg sMOTD ;get bytes from sMOTD segMENT
mov ds,ax ;store pointer in dATA sEGMENT
mov ah,09h ;function 09h - (print string)
lea dx,sMOTD ;store offset in dx
int 21h ;intERRUPT - (DOS Service)

start: ;start loop
mov ah,00h ;BIOS scan keycode
int 16h ;intERRUPT - (keyboard)
cmp al,31h ;cOmpARE aCCUMULATOR lOW to 1
jne exit ;jUmp (to exit:) if nOT eQUAL to 1
cls ;clear screen
mov ax,seg sENUM ;get bytes from sENUM segMENT
mov ds,ax ;store pointer in dATA sEGMENT
mov ah,09h ;function 09h - (print string)
lea dx,sENUM ;store offset in dx
int 21h ;intERRUPT - (DOS Service)

exit: ;exit loop
mov ah,00h ;BIOS scan keycode
int 16h ;intERRUPT - (Keyboard)
cmp al,32h ;cOmpARE aCCUMULATOR lOW to 2
jne start ;jUmp - (back to start:) - if nOT eQUAL to 2

mov ax,4c00h ;end clean
int 21h ;intERRUPT - (DOS Service)
main endp ;end main procedure
end main ;exit application


What am I leaving out that will accomplish this very simple request? I am writing for the 8086 processor and assembling with TASM 5.0.. on Windows XP.

regards

Lican
January 26th, 2005, 04:23 PM
Hm... I think 3 things can be done. I'm not sure but what you want to do is to delete the old text above the caret and write something... so:

1) try:

xor dx,dx
xor bh,bh
mov ax,200h
int 10h

the 2 function in the 10h interrupt sets the cursor pos to the x,y specified in the dh,dl. Then you can write on the old menu

2) do, you have it so...

xor cx,cx
mov dh,width of screen in characters
mov dl,height of screen in characters
mov bh,7
mov ax,700h
int 10h

this scrolls the window down to the end ( so just clears it :)

3) or just clear the video buffer :)

push 0b800h
pop ds
xor di,di
xor al,al
mov ah,7
mov cx,width*height
shl cx,2
clear:
stosw
dec cx
jnz clear


I hope this is what you wanted :) If not, my mistake :P I left asm some time ago so I don't know it this would work, but worth trying. If any more questions about that feel free to ask.

lurner
January 27th, 2005, 01:47 AM
i tried using the first example and it only over writes the bits that are already existant in the registers.. for example:

If the bytes were: "Hello World!"

and you run the first example and then mov more bytes which do not exceed the present bytes, the output is:

The Endorld!

I tried clearing the video buffer with the third example but tasm keep rejecting the code, is width*height valid? what should I replace that with, and how would I know where to look?

thanks

EDIT: Well I figured out a way to make it work how I wanted, I just overwrote the last bits with a space and that did the trick.. however, I am still interested in learning how to clear the video buffer.

regards

Lican
January 28th, 2005, 06:00 AM
width*height is not valid, but I wrote that just to know that's going on. I found out clearing the video buffer doesn't work on XP, but works on 98 & 98 SE. I haven't checked if that happens on very NT based system or only XP, but it just doesn't do the trick. I did some testing and you can try reselecting the video mode:

mov ax,3
int 10h

This one set 80x25 text mode. I don't know if you're working i that one and if no, here are some other modes:

0 -> 40x25
1 -> 40x25
2 -> 80x25
3 -> 80x25

well... there is a hole list of other modes so maybe e-mail me if you want more ;)

It looks as if XP is blocking the interrupt call so that any other mode cannot be set. Blocked or not, this method still clears the screen ( on my computer ). Try it out and tell me if it worked. That was the fourth method :P Any other?

Lican
January 28th, 2005, 06:26 AM
And one more thing. The b800h writing in memory thing works under XP too, but first you have to set the text mode, and then every normal command that works in text mode will work. For some reason text mode is, I don't know how to say, I'm not that interested in the subject, it is not set (?). First:

mov ax,3
int 10h

and then:

push 0b800h
pop es <- there was a mistake :)
xor di,di
mov ax,7
mov cx,width*height
shl cx,2
rep stosw

It's obvious that the first one is more simple, but do as you like.

lurner
January 28th, 2005, 07:07 AM
uninitialised I think is the word you were looking for.. I will try it that last way you showed to see if it works, if so then that is the way I rather go, I say it's better to release memory than to simply overwrite it. I am most interested in learning how to push dll address into the bx register as I have posted here:

http://www.codeguru.com/forum/showthread.php?t=326489

if you wouldn't mind taking a look there, perhaps you can help me there when you have the time, for it seems you and I are the only ones posting.. :)

regards

Lican
January 28th, 2005, 01:50 PM
heh... uninitialised, it's a word that is hard to spell for someone not using english in every day life :P but not really that word. That's because I just read about how 16-bit programs are run on XP. The system creates a "virtual machine" which then handles any message from the program. The problem lies in the VM structure. It doesn't allow the program to do some things and others are restricted. So maybe this is the main cause. I know it's much too much you wanted to know, but I always want to know what causes what :)

And about uninitialised :) Well, the text mode is initialsed ( because you are using it ) but you have to initialise it again yourself to use all the features. Very strange... but it works ;)

I'm going to see the second post. Maybe we are the only ones who like to learn after hours...

lurner
January 28th, 2005, 05:19 PM
haha.. well your english is superb, I just noticed your from Poland. Where are you reading about this.. I am the exact same way, I HAVE to know why it does and doesn't work, the more info. the better, I say.

Indeed, we are a dieing breed my friend.. I wish more people felt the same as we do and would start coding in ASM, then maybe we would have some company for when the sun goes down. :)

regards

Lican
January 28th, 2005, 07:28 PM
About the article:

My friend sent me a link ( don't know where it is right now :P ). Try searching on the microsoft.com, something about "nt DOS Virtual Machine" (NTVDM). You should find there what you are looking for.

Second:

I don't know if you ever seen this page: http://webster.cs.ucr.edu/ "The art of assembly". May come in handy. I also have info about the intel 8086 if you want and a quite comprehensive documentation on the dos interrupts from 0 to FF :) If anything else I'll be happy to reply to your e-mail's: Lican@wp.pl

lurner
January 28th, 2005, 10:01 PM
cool just added you to my contact list.. :)

Just finished reading Art of Assembly the other day it's a good book, right now I am reading Shell Coders Handbook.. pretty good so far. Got it off amazon a few months back. Worth every penny, I say.

Here is the bookmarks I have found since I started last week, and they are all really good:

http://grc.com/smgassembly.htm
http://www.xs4all.nl/~smit/asm01001.htm
http://www.xs4all.nl/~smit/docs.htm
http://webster.cs.ucr.edu/AoA/DOS/pdf/0_AoAPDF.html
http://www.technologicalarts.com/myfiles/t4.html
http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixassem/alangref/alangref02.htm#ToC
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=74
http://www.electronics.dit.ie/staff/tscarff/8086_registers/8086_registers.html
http://www.lookuptables.com/
http://www.emu8086.com/vb/index_asm.html
http://www.krify.com/8086/
http://internettrash.com/users/fdb/asm.htm
http://www.geocities.com/SiliconValley/Park/3230/x86asm/asmles01.html
http://www.faqs.org/faqs/assembly-language/x86/general/part2/section-4.html
http://home.earthlink.net/~craie/asm.rsc.html
http://www.programmersheaven.com/zone5/mh1.htm
http://www.clipx.net/ng/asm/
http://burks.brighton.ac.uk/burks/language/asm/asmtut/asm1.htm
http://www.ctyme.com/rbrown.htm
http://win32asm.cjb.net/
http://asmedit.massmind.org/AsmLinks.html

Check some of them out if you want, clipx has a good reference for int and functions for DOS..

I just wrote a Procedure Finder in VB for DLL's just in case you would like to see it and perhaps use it, it comes in handy, except it returns a different address than arwin.c, that some guy wrote for the same reason, it works fine, but I wanted a GUI interface, which is probably the applications down fall, at any rate here is the source: (VB6)


Option Explicit
'
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal _
lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
ByVal lpProcName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) _
As Long
'
Private Sub cmdProceed_Click()
Dim hModule As Long, procAddr As Long
Dim i As String, x As String
i = txtLibrary.Text
x = txtProc.Text
hModule = LoadLibrary(i)
If hModule Then
procAddr = GetProcAddress(hModule, x)
txtProcAdd.Text = procAddr
FreeLibrary hModule
Else
MsgBox "The Library or Procedure does not exist!", vbInformation, "Error!"
End If
End Sub
'
Private Sub Form_Load()
txtLibrary.AddItem "ADVAPI32"
txtLibrary.AddItem "GDI32"
txtLibrary.AddItem "KERNEL32"
txtLibrary.AddItem "MPR"
txtLibrary.AddItem "NETAPI32"
txtLibrary.AddItem "OLE32"
txtLibrary.AddItem "RASAPI32"
txtLibrary.AddItem "SHELL32"
txtLibrary.AddItem "USER32"
txtLibrary.AddItem "VERSION"
txtLibrary.AddItem "WINMM"
txtLibrary.AddItem "WINSPOOL"
txtLibrary.AddItem "WSOCK32"
End Sub


pretty sweet huh? Makes finding the procedures address real easy and fast!

regards

lairusi
July 26th, 2007, 07:47 AM
Hm... I think 3 things can be done. I'm not sure but what you want to do is to delete the old text above the caret and write something... so:

1) try:

xor dx,dx
xor bh,bh
mov ax,200h
int 10h

the 2 function in the 10h interrupt sets the cursor pos to the x,y specified in the dh,dl. Then you can write on the old menu

2) do, you have it so...

xor cx,cx
mov dh,width of screen in characters
mov dl,height of screen in characters
mov bh,7
mov ax,700h
int 10h

this scrolls the window down to the end ( so just clears it :)

3) or just clear the video buffer :)

push 0b800h
pop ds
xor di,di
xor al,al
mov ah,7
mov cx,width*height
shl cx,2
clear:
stosw
dec cx
jnz clear


I hope this is what you wanted :) If not, my mistake :P I left asm some time ago so I don't know it this would work, but worth trying. If any more questions about that feel free to ask.


xor cx,cx
mov dh,width of screen in characters
mov dl,height of screen in characters
mov bh,7
mov ax,700h
int 10h


In this code, what does mov bh, 7 does and what does mov ax, 100h does?

Thanks in advance! =)

Slider7
July 28th, 2007, 04:43 PM
See if this helps.

; clear.asm Clear screen using direct video writes
; MUCH faster than BIOS interrupts(int 10h)

.MODEL SMALL
.stack 200h
.CODE
start:
push ax
push es
mov ax,0b800h ; Start at memory 0b800
mov es,ax
xor di,di
mov cx,2000 ;
mov ax,0720h ; Black bg, white fg, 20h = space char
rep stosw
pop ax
pop es
exit:
mov ax,4c00h ; exit with 0 exit code
int 21h
end start