Page 1 of 1

help with mode 3h

Posted: Mon Mar 31, 2008 1:32 pm
by The Doc
hi all...

i got a (working?) method to set up int 3h... but now there's the problem that i can't display text after calling the method. anybody know why?

Code: Select all

void set_3h() {
    char data[18] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, 0x4F, 0x9C, 0x0E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3 };
    
    outportb(0x3C2, 0x67);
    for (int i=0; i<18; i++)
        outportw(0x3D4, (data[i]<<8)+i);
    outportw(0x3C4, 0x0001);
    outportw(0x3C4, 0x0003);
    outportw(0x3C4, 0x0004);
    outportw(0x3CE, 0x1005);
    outportw(0x3CE, 0x0E06);
    outportw(0x3C0, 0x0C10);
    outportw(0x3C0, 0x0813);
}

Posted: Mon Mar 31, 2008 6:13 pm
by Combuster
you are accessing the CRTC registers without unlocking them first. That means the larget part of your register modifications isn't applied.

Besides, after booting you are left in text mode already, if you try this to get out of a VESA mode, then it most likely will mess up the video card as well.

There's a bunch of related information on the wiki: VGA Hardware

Posted: Tue Apr 01, 2008 12:13 pm
by The Doc
hi!

i tried to unlock the registers with outportb(0x3d4, 0x11), but it doesn't make any difference... :(
i know that i'm in text mode after booting the system. what i want to do is to switch back to textmode form vga mode (13h).
but i don't have any idea why it doesn't work!

Posted: Tue Apr 01, 2008 12:41 pm
by Combuster
A byte out to 0x3D4 will only change the register index. It won't change any actual CRTC registers, and hence, the lock bit.

EDIT: you'll need to restore the font as well if you come from graphics mode. otherwise you'll be printing spaces all over the place instead. (try printing white-on-blue to see if that does anything)

Posted: Wed Apr 02, 2008 8:33 am
by The Doc
but why do i have to restore the font even if i haven't been in 320x200-mode? i'm booting in cga-mode an then i'm switching to 3h... now i can see the cursor, but there's still no text.
and btw: how can i restore the font? ^^
in 320x200-mode i'm just drawing some variables directly to the screen without setting a new font.

Posted: Wed Apr 02, 2008 4:32 pm
by Combuster
The Doc wrote:but why do i have to restore the font even if i haven't been in 320x200-mode? i'm booting in cga-mode an then i'm switching to 3h... now i can see the cursor, but there's still no text.
That's what I meant with drawing spaces. The video card has four planes of memory. All four planes are drawn to the screen in a graphics mode, so you will most likely have changed them to get sensible output.

In text mode, each plane serves a specific purpose. planes one and two contain the characters and their attributes, plane 3 contains the font and plane 4 is unused. For each character on the screen, the VGA looks up the 32 bytes corresponding to that character in plane 2, and then emits the foreground for each set bit, and background for each cleared bit. Since you have put something to the screen in graphics mode, plane 2 will contain byte values corresponding to colors, rather than bitfields corresponding to characters. Hence if you cleared the screen before the switch plane 2 will contain only zeroes, and you'll get only the background color when you reuse it in text mode.

To set the font, you'll have to set up at least part of the vga to a planar graphics mode (ega or mode-x), write the bitmap to plane 2, then restore it back to text mode.

Code to do this has been posted very recently on this forum - I honestly think that you should spend more time looking for an answer as I have learned pretty much everything said here from somewhere else too.
http://www.osdev.org/phpBB2/viewtopic.php?t=16594

Try again writing white-on-blue text. If you only see the blue background then you know it's a font problem, otherwise you may have messed up something like the DAC or 16-color palette.

Posted: Thu Apr 03, 2008 2:46 am
by The Doc
ok thanks for ur help :)
ps: as you said it's a font-problem... at least i can see the blue background