flat assembler
Message board for the users of flat assembler.

Index > DOS > Trouble with VGA...Half of screen is Rainbowed. Why?

Author
Thread Post new topic Reply to topic
Kitsune



Joined: 17 Apr 2023
Posts: 18
Kitsune 19 Nov 2023, 23:31
Hi!

I try to make a VGA mode 13h screen and I try to make an half black (blue for now ^^) screen. But I don't know why I have a rainbowed screen after the first half (horizontal of the screen)
Is it a trouble of memory?

Code:
; MCGA mode 13h

format MZ
start:
        ;320x200 256 colors graphics mode
        mov ah,00h
        mov al,13h
        int 10h

        mov ax, 0   ; row
        mov bx, 0   ; column
        mov cx, 320 ;
        mul cx      ; ax = 320*0   
        add ax, bx  ; result
        mov bx, ax  ; copy the result in bx (buffer)
        mov cl,32
X:      
        mov ax,bx
        mov di,ax
        mov ax,0xa000
        mov es,ax
        mov al,cl
        mov [es:di], al
        
        jmp test1 




bxOne:  inc bx  
        jnz X
        
waitkey:
        mov ah,1h    ; Check for Keytroke
        int 16h      ; Keyboard interrupt
        jz waitkey         ; Jump if none pressed
        mov ah,0h    ; Get Keystroke
        int 16h      ; Keyboard interrupt
        cmp al,0x1B  ; Check if "Enter" is pressed
        jne X        ; Jump to X if not egal (to "Enter")
exit: 
        mov ah,00h
        mov al,03h
        int 10h

        mov ah,4ch
        int 21h

test1:  mov ax,bx
        cmp bx,320
         je Rainbow
         jg cl0
         jmp Rainbow

Rainbow:mov ax,bx
        inc cl
        cmp cl,48
         je cl0
       jmp bxOne

cl0:    mov ax,bx
        mov cl,32  ; Set initial colors (black)
        jmp bxOne
    


Description: Half Rainbowed Screen
Filesize: 9.88 KB
Viewed: 1814 Time(s)

Capture d’écran du 2023-11-18 15-59-15.png



_________________
Kitsune
Post 19 Nov 2023, 23:31
View user's profile Send private message Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 346
Location: Poland
macgub 20 Nov 2023, 15:58
Hi !
Keep in mind mode 13h is palette mode. If you put byte into [es:di] you adress an 18 bit pallette register. So I guess in your case byte 32 adress blue color.. But if you dont intialise palette dont rely on this info. Sometimes 32 value will mean blue, sometimes red, black and any other from range 2^18 possible..
At last try always put '32' value in every byte form A0000h to AFA00h - you will get every pixel with same color.
Best wishes to you and your coding work! I hope you get more and more experience and get satisfy your job !
Post 20 Nov 2023, 15:58
View user's profile Send private message Visit poster's website Reply with quote
SeproMan



Joined: 11 Oct 2009
Posts: 70
Location: Belgium
SeproMan 20 Nov 2023, 20:45
Quote:
I don't know why I have a rainbowed screen after the first half (horizontal of the screen)
Is it a trouble of memory?


There's nothing wrong with the video memory, but you have a tiny error in your program.

Code:
test1:  mov ax,bx
        cmp bx,320
         je Rainbow
         jg cl0
         jmp Rainbow

Rainbow:
    


The value that you have in the BX register is an address. Addresses are unsigned quantities and you should use the unsigned versions of the conditional jumps on them. The quick fix is to replace 'jg cl0' by 'ja cl0'.

For unsigned values you need to think in terms of BELOW and ABOVE.
For signed values you need to think in terms of LESS and GREATER.

If the contents of a 16-bit register (like BX) are to be considered unsigned, then the value ranges from 0 to 65535.
On the other hand, if the contents of a 16-bit register are to be considered signed, then the value ranges from -32768 to 32767.

In your program, somewhere in the middle of the screen, the address in BX got incremented from 32767 to 32768, thereby entering the negative range when interpreted as signed which the CPU did because of the 'jg' (JumpIfGreater) instruction. Sadly, being not greater, the wrong execution path was taken.

If you really want to "Set initial colors (black)" then rather use 'mov cl, 0'.
Next is the better way to correct your program:
Code:
test1:  ; I see no need to use 'mov  ax, bx'
        cmp  bx, 320
        jae  .a
        inc  cl           ; Rainbow
        cmp  cl, 48
        jb   bxOne
        mov  cl, 32
        jmp  bxOne
.a:     mov  cl, 0        ; Rest of screen in black
        jmp  bxOne
    

_________________
Real Address Mode.
Post 20 Nov 2023, 20:45
View user's profile Send private message Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 346
Location: Poland
macgub 20 Nov 2023, 21:25
@SeproMan
You go deeper in code - thanks for explanation....
Post 20 Nov 2023, 21:25
View user's profile Send private message Visit poster's website Reply with quote
Kitsune



Joined: 17 Apr 2023
Posts: 18
Kitsune 20 Nov 2023, 21:34
Thanks! You solved the trouble. The program does what I expected now...And I would have had a really hard time finding this because I didn't know these instructions "jae" and "jb". Merci
Post 20 Nov 2023, 21:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.