Page 1 of 1

Planes in mode 0x13? (320x200x256 VGA)

Posted: Tue Feb 21, 2012 3:26 pm
by ATXcs1372
I'm moving my bootloader/kernel over to VGA output, however I'm encountering some errors. Whenever I try to plot a pixel, I end up getting four pixels evenly spaced and in the wrong location. I believe this has something to do with plane switching, but from my understanding mode 0x13 uses a consecutive memory for consecutive pixels. I'm sure it's something simple I'm missing, but figured I'd try and get fresh eyes looking at it.

I set the video mode using this:

Code: Select all

mov     ax, 0x0013
int     0x10
and plot a pixel using this:

Code: Select all

;--------------------------------------------------------------
;   plotPixel
;   Prints a pixel to the screen at a given location
;   inputs:
;       RAX: Y location
;       RBX: X location
;--------------------------------------------------------------
plotPixel:
    ; [x + y * width] = color
    push rdi
    mov rdi, VIDEO_COLUMNS
    mul rdi                     ; AX = Y * VIDEO_COLUMNS
    add ax, bx                  ; AX = (Y * VIDEO_COLUMNS) + X
    mov rdi, rax
    add edi, DWORD [videoMemory]
    mov al, BYTE [currentTextColor]
    stosb
    pop rdi
    ret
This is what I get as output for plotting a pixel at (24, 34) which is odd because there should be 200 addressable (Y) pixels, yet there are only 50 available on screen.

Image

EDIT: Forgot to mention I'm using Boch's for emulation

Re: Planes in mode 0x13? (320x200x256 VGA)

Posted: Tue Feb 21, 2012 6:13 pm
by bubach
Hi, we need to see your variables too, just to make sure the values are right. I haven't looked into the plot pixel function much yet, but you seem to do it a bit differently from me so will have to take a closer look to see if it should work. In the meantime, you could check my function (made for 32-bit):

Code: Select all

; input:   bx = x, cx = y, al = color
put_0x13_pixel:
         push    ax bx cx edi

         mov     edi, 0xa0000                        ; directly to mem
         add     di, bx
         mov     bx, cx
         shl     cx, 8
         shl     bx, 6
         add     cx, bx
         add     di, cx
         stosb

         pop     edi cx bx ax
         ret

Re: Planes in mode 0x13? (320x200x256 VGA)

Posted: Wed Feb 22, 2012 12:11 am
by Combuster
Planes have little to do with this, they only affect groups of eight pixels in a line.

From the looks of it you messed up the virtual width register. If that's set to quarter screen width you will see each pixel appear four times (and four times as far down). If that's the only graphics code ever called, this shouldn't be possible though, so probably something else is touching the video as well.

Re: Planes in mode 0x13? (320x200x256 VGA)

Posted: Wed Feb 22, 2012 9:42 am
by ATXcs1372
Combuster wrote:Planes have little to do with this, they only affect groups of eight pixels in a line.

From the looks of it you messed up the virtual width register. If that's set to quarter screen width you will see each pixel appear four times (and four times as far down). If that's the only graphics code ever called, this shouldn't be possible though, so probably something else is touching the video as well.
This seems to be the most likely solution. All my other graphics code has been removed while writing the VGA code, however because I only have 50 addressable Y pixels, this makes sense (50 * 4 = 200!). I'll look into setting of the registers more and hope it isn't just a Bochs issue.

Re: Planes in mode 0x13? (320x200x256 VGA)

Posted: Wed Feb 22, 2012 12:30 pm
by VolTeK
Never assume its the tools fault. Thinking like that will have you searching in the wrong place for the source of your problem.

Re: Planes in mode 0x13? (320x200x256 VGA)

Posted: Wed Feb 22, 2012 7:05 pm
by ATXcs1372
VolTeK wrote:Never assume its the tools fault. Thinking like that will have you searching in the wrong place for the source of your problem.
I didn't assume it was the tool's fault and never claimed to. I didn't even mention bochs until that post and that's only because I've seen other people with graphics issues in bochs. Thanks for the suggestion, but posts like this do nothing but make these forums needlessly hostile.