x86 Video mode Clear Screen

10,361

Solution 1

There are some issues with your code.

First, BIOS mode 13h is not 640x480 at 8 bits/pixel, it's 320x200 at 8 bits/pixel.

B800h is the address of BIOS text modes. BIOS graphics modes use A000h.

So it should be:

mov ax,0A000h
mov es,ax

320x200 at 8 bits consumes 320*200 = 64 000 bytes of video memory. So the value of cx is incorrect. It should be:

mov cx,32000d
cld
rep stosw

Solution 2

for text mode you could use this simple procedure

clrscr proc
    mov ax,0003h
    int 10h 
    ret
endp

and call it in your program by

call clrscr
Share:
10,361
Belbesy
Author by

Belbesy

Updated on June 04, 2022

Comments

  • Belbesy
    Belbesy over 1 year

    Hello I'm trying to clear the screen in DOS video mode with this code.

    But when I run it, the dot is still there!

        org 100h
    
        mov     ah, 0       ; set display mode function.
        mov     al, 13h     ; mode 13h = 640x480 pixels, 256 colors.
        int     10h         ; set it!
    
        mov     cx, 10      ; column
        mov     dx, 10      ; row
        mov     al, 15      ; white
        mov     ah, 0ch     ; put pixel
        int     10h         ; draw pixel
    
        ; -------  clear the screen ----------     
        ; -------  doesn't work! dot is still there
    
        mov ax,0B800h
        mov es,ax
        xor di,di
        xor ax,ax
        mov cx,2000d
        cld
        rep stosw
    
        ; -------------------------------------
    
        ;wait for keypress
        mov ah,00
        int 16h
    
        mov ax, 4c00h ; exit to operating system.
        int 21h
    
        ;======================================================
    

    I tried resetting the video mode with INT 10 but this gives me blinks which is unwanted inside my loop

  • user786653
    user786653 almost 11 years
    s/16000/32000/ otherwise +1
  • nrz
    nrz almost 11 years
    @user786653 Fixed. I was thinking that in 32-bit DOS code I would do it xor eax,eax; mov ecx,16000d; rep stosd and then confused myself...
  • Belbesy
    Belbesy almost 11 years
    That explains a lot, it's so smooth now :D Thank you very much :)
  • Ross Ridge
    Ross Ridge over 8 years
    The problem is that he's not using text mode, and this will change video mode to text mode. He's also tried resetting the video mode to the one he's actually using, but this caused unwanted blinks.
  • Michael Petch
    Michael Petch over 5 years
    You should explain this code, as it is it may not be useful for some to understand why this works. There is a bug in this code though. Your code assumes that the 4 bit planes are currently enabled which may or may not be the case. You really should make sure they are all enabled with MOV DX, 3C4H MOV AX, 0F02H OUT DX, AX
  • Michael Petch
    Michael Petch over 5 years
    As well you do an unusual thing to set CX. You multiply what happens to be in AX with the value 40. If you know the screen size is 640*480 then the number of WORDs needed to clear it will be 640*(480/8)/2 . Rather than do MOV BX, 40 MUL BX MOV CX, AX you could replace it with MOV CX, 640*(480/8)/2 .Your method happens to almost double the number of screen memory addresses that need to be cleared.
  • Brendan
    Brendan almost 5 years
    Note that you can do something like mov cx,320*200/2 to make it easier to read (easier to see where the "magic number" comes from) and less error prone. The assembler will calculate the constant for you.