VGA planar mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
johnsa
Member
Member
Posts: 296
Joined: Mon Oct 15, 2007 3:04 pm

VGA planar mode

Post by johnsa »

Hey,

I seem to be having some issues with VGA planar mode (the issue is clearly with me) as it's been such a long time since I last did any h/w level vga programming i seem to have forgotten something. :)
The issue is happening under emulators (bochs/qemu) and on a real machine so I think it must be me. Basically the various steps are as follows (perhaps some-one can immediately see the error):

#1 Set the palette (from my memory 16 colour modes just simply use the first 16 enrties in the VGA palette (there is options to switch between banks of 16 colours out of the full 256) but by default it's 0-15)

Code: Select all

       
       call wait_vblank

        mov dx,03dah
	in al,dx
	mov dx,03c0h
	xor al,al            ;Ensure bit 5 clear to allow host to update palette (in the old days i never bothered with this and never had issues .. but for completeness)
	out dx,al

    mov dx,3c8h                   ;set the palette (first 16 entries) using the fact that the start index can be written and then repeatedly write R,G,B (0-63) and the index will auto-increment.
    xor al,al
    out dx,al
    inc dx
    mov cx,16
palloop:    
    mov al,es:[edi]
    out dx,al
    mov al,es:[edi+1]
    out dx,al
    mov al,es:[edi+2]
    out dx,al
    add edi,3
    dec cx
    jnz short palloop

    mov dx,03dah                  ;ensure 03c0h is in index mode ..
	in al,dx
	mov dx,03c0h
	mov al,20h
	out dx,al                      ;allow VGA to access palette ram again.
Ok so that part seems to all work perfectly.. no problems in 16 col mode.
Next step also seems to work fine

#2 Clear video memory to a known value..

Code: Select all

	mov al,02h
	mov dx,03c4h
	out dx,al
	inc dx
	mov al,00001111b                ; Enable Write to all planes (0,1,2,3)
	out dx,al
	
	mov ax,0a000h
	mov es,ax
	xor edi,edi
	mov ecx,(640*350)/8            ;8 pixels per byte in planar mode
	mov al,11111111b 
dloop:
	mov es:[edi],al
	inc edi
	dec ecx
	jnz short dloop
After this we should have vid-mem filled by colour 15 (max from allowing all 4 planes to be written).
In my case this would be solid blue.

#3 draw something ontop of the background using bit-masking to not alter the background.
I realise that you can use write mode 3 and the ALU's to achieve the same result, but I just wanted to do it this way.
assuming write mode 0 is the default..
(HERE is where the funny happens.. the bitmask register seems to have no effect)

Code: Select all

	mov cx,14
drawcharloop:
	mov al,02h
	mov dx,03c4h
	out dx,al
	inc dx
	mov al,0fh
	out dx,al           ; enable all 4 planes for write
	
	mov dx,03ceh
	mov al,08h
	out dx,al
	inc dx
	mov al,ds:[si]
	out dx,al            ; set bit mask register = the data we're going to draw.. data is bitmap of font char..

	xor al,al
	mov es:[di],al    ; clear the data in vidmem on all 4 planes, this should only affect the bits that are 1 in the font char data.. and then allow us to draw it using the correct masked planes for the colour.

 ; REMOVED code to do the draw as this part is already not working.. it's clearing the whole block and not just the masked bits.

	inc si
	add di,80	
	dec cx
	jnz short drawcharloop

Any ideas as to why the bitmask has no affect?
Thanks!
johnsa
Member
Member
Posts: 296
Joined: Mon Oct 15, 2007 3:04 pm

Re: VGA planar mode

Post by johnsa »

Fixed... doh.. I wasn't loading the latch registers in between to ensure the bitmask set the correct bits and kept the necessary bits (0) from that latch.
Post Reply