flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Video Mode Switch

Author
Thread Post new topic Reply to topic
Opcode



Joined: 07 Jan 2005
Posts: 12
Opcode 13 Jun 2005, 15:21
Hi,

Do someone know how to change the video mode from
Graphic mode to Text mode by using the video
registers directly?

What register I need to change?

Thanks for any help.

Regards,
Opc0de
Post 13 Jun 2005, 15:21
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 13 Jun 2005, 15:41
The info you want is available on bubach's site here: http://bos.asmhackers.net/docs/vga_without_bios/
Post 13 Jun 2005, 15:41
View user's profile Send private message Reply with quote
Opcode



Joined: 07 Jan 2005
Posts: 12
Opcode 16 Jun 2005, 12:01
Well, I read all documentation that I found by Google including the bubach's docs.

But I'm still not able to switch my video card mode to text mode again.
This is a experimental project.
I'm running a device drivers inside the kernel of Windows XP, that is running at the resolution 1152x864x32bits and I want to switch it to
text mode 80x25.

Take a look:

( I know that this is a C code, but I will translate it to ASM as soon it works!)

Code:
VOID
VgaSetContext(PVGA_CONTEXT VgaCtx)
{

        unsigned int i;

        //
        // Reset flip-flop by reading the Input Status #1 Register
        //
        PORTINB(VGA_MISC_READ_INPUT_STATUS_1);
        // Disable video
        PORTOUTB(VGA_AC_IO_REG, 0x00);

        

        //
        // Set the Misc register
        //
        PORTOUTB(VGA_MISC_WRITE_OUTPUT_REG, VgaCtx->Misc[0]);


        // synchronous reset on
        PORTOUTB(VGA_SC_INDEX_REG, 0x0);
        PORTOUTB(VGA_SC_DATA_REG, 0x1);


        //
        // Set the SC registers
        //
        for ( i = 1; i < VGA_SC_REGS; i++)
        {
                PORTOUTB(VGA_SC_INDEX_REG, i);
                PORTOUTB(VGA_SC_DATA_REG, VgaCtx->Sc[i]);
        }

        // synchronous reset off
        PORTOUTB(VGA_SC_INDEX_REG, 0x0);
        PORTOUTB(VGA_SC_DATA_REG, 0x3);




        //
        // Unprotect the CRTC registers 0-7
        //
        PORTOUTB(VGA_CRTC_INDEX_REG, CRTC_VERTICAL_RETRACE_END);
        PORTOUTB(VGA_CRTC_DATA_REG, (PORTINB(VGA_CRTC_DATA_REG)&~0x80));

        //
        // Set the CRTC registers
        //
        for ( i = 0; i < VGA_CRTC_REGS; i++)
        {
                PORTOUTB(VGA_CRTC_INDEX_REG, i);  // (<- THE MONITOR SHUTDOWN ITSELF RIGHT HERE!!!)
                PORTOUTB(VGA_CRTC_DATA_REG, VgaCtx->Crtc[i]);
        }
    
       ... The are more code

    


The VGA_CONTEXT structure:
Code:
typedef struct tagVGA_CONTEXT
{

        UCHAR   Misc[VGA_MISC_REGS];                    // Miscellaneous registers
        UCHAR   Sc[VGA_SC_REGS];                        // SC registers
        UCHAR   Crtc[VGA_CRTC_REGS];                    // CRTC registers
        UCHAR   Gc[VGA_GC_REGS];                        // GC registers
        UCHAR   Ac[VGA_AC_REGS];                        // AC registers

} VGA_CONTEXT, *PVGA_CONTEXT;
    


PORT definitions:
Code:

//
// VGA Registers
//

#define         VGA_AC_IO_REG                           0x3c0   // AC Index/Output Register
#define         VGA_AC_DATA_REG                         0x3c1   // AC Data Read Register

#define         VGA_MISC_READ_INPUT_STATUS_0            0x3c2   // Input Status #0 Register
#define         VGA_MISC_WRITE_OUTPUT_REG               0x3c2   // Miscellaneous Output Register (WRITE)

#define         VGA_SC_INDEX_REG                        0x3c4   // Sequencer Index Register
#define         VGA_SC_DATA_REG                         0x3c5   // Sequencer Data Register

#define         VGA_MISC_READ_FEATURE_CONTROL           0x3ca   // Feature Control Register (READ)

#define         VGA_MISC_READ_OUTPUT_REG                0x3cc   // Miscellaneous Output Register (READ)

#define         VGA_GC_INDEX_REG                        0x3ce   // Graphics Controller Index Register
#define         VGA_GC_DATA_REG                         0x3cf   // Graphics Controller Data Register

#define         VGA_CRTC_INDEX_REG                      0x3d4   // CRT Controller Index Register (color)
#define         VGA_CRTC_DATA_REG                       0x3d5   // CRT Controller Data Register (color)

#define         VGA_MISC_READ_INPUT_STATUS_1            0x3da   // Input Status #1 Register (READ)
#define         VGA_MISC_WRITE_FEATURE_CONTROL_REG      0x3da   // Feature Control Register (WRITE)


//
// VGA Registers Total Indexes
//

#define         VGA_AC_REGS                             0x15
#define         VGA_SC_REGS                             0x05
#define         VGA_GC_REGS                             0x09
#define         VGA_CRTC_REGS                           0x19
#define         VGA_MISC_REGS                           0x01
    


Please, I really need to understand why my monitor is shutdown itself
when I access the CRT controler registers at ports 0x3d4 and 0x3d5.

The are more registers that I need to configure before?

If someone can post some code, rather in ASM I apreciate Very Happy

Thanks for any help

Regards,
Opc0de


Last edited by Opcode on 16 Jun 2005, 13:42; edited 1 time in total
Post 16 Jun 2005, 12:01
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 16 Jun 2005, 12:11
have you been looking at BIOS's code for this? I recall i found something totally undescribed anywhere with EGA palette this way long time ago.
Post 16 Jun 2005, 12:11
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Opcode



Joined: 07 Jan 2005
Posts: 12
Opcode 16 Jun 2005, 12:17
Hi vid,

No, I don't have BIOS code.
Do you have some code to help me?

Thanks.
Post 16 Jun 2005, 12:17
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 16 Jun 2005, 15:20
If your running your code from a device driver inside XP kernel, would it not be better to ask in the windows part ?.
Post 16 Jun 2005, 15:20
View user's profile Send private message Reply with quote
Opcode



Joined: 07 Jan 2005
Posts: 12
Opcode 16 Jun 2005, 18:21
The kernel don't have API to do what I want specifically.
It is not possible to do what I want only with the VGA registers?
Post 16 Jun 2005, 18:21
View user's profile Send private message Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias 16 Jun 2005, 18:43
Opcode wrote:
The kernel don't have API to do what I want specifically.
It is not possible to do what I want only with the VGA registers?

I may be completely in error here, sorry not to have a specific reference, but, in my opinion, what you seek to accomplish is quite difficult WITHIN windows, because of ring zero requirement to access the video control registers directly, and windows insistence that you NOT access ring zero. May I suggest menuet or sol as alternative operating systems.....
Once you are able to work at ring zero, i.e. user access to all components on the motherboard, then, you can access the video control registers. Perhaps my opinion is incorrect.
Post 16 Jun 2005, 18:43
View user's profile Send private message Reply with quote
Opcode



Joined: 07 Jan 2005
Posts: 12
Opcode 16 Jun 2005, 23:39
tom tobias wrote:

I may be completely in error here, sorry not to have a specific reference, but, in my opinion, what you seek to accomplish is quite difficult WITHIN windows, because of ring zero requirement to access the video control registers directly, and windows insistence that you NOT access ring zero.


Hi tom,

I can assure you that I have complete access to ring 0.
BTW, to create device drivers for Windows in assembly is a very fun task Razz
And unfortunatelly, this project is Windows specific, I can't use another OS.

My fear is the lack of documentation about these new video modes and the
registers configuration. Is very strange the fact that my monitor is shutdown
itself just because I'm writing in the CRTC_HORIZONTAL_TOTAL register
(Index 0) at port 0x3d5. I really don't understand this Crying or Very sad

Regards,
Opc0de
Post 16 Jun 2005, 23:39
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 17 Jun 2005, 04:13
Another useful VGA Programming page is http://www.osdever.net/FreeVGA/home.htm - check it out. It isn't complete (apparently the project was halted) so it only has VGA programming info. (sorry, no SVGA) but it does have VGA documentation. One of bubach's pages is actually one of these documents.

For SVGA and XGA programming info., search for VGADOC and WHATVGA.
They aren't very helpful, but you might be able to use them.
Post 17 Jun 2005, 04:13
View user's profile Send private message AIM Address Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Jun 2005, 08:57
opcode: use debugger to "walk into" interrupt int 10h / al=3, until it reches BIOS's are. It is probably somewhere at the top of 1Mb, segments 0D000h to 0FFFFh. Then look at segment in CS, and use utility to grab memory range from CS:0 to CS:FFFF (i mean CS when you was in that BIOS routine). Then use some disassembler (i suggest IDA for such "special" causes), and look what it does.

PS: first thing you will see will be checking for value of AL
Post 17 Jun 2005, 08:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu 17 Jun 2005, 10:15
I think he wants to do this setup directly from Windows driver/ring-0 without BIOS help (talking directly to VGA ports/registers)

However this is also very dificult ... mainly because windows will interfere with this ... and the video driver etc. You must understand the windows kernel internals and the relation between kernel modules IRQ virtualization etc.

It is normal for the monitor to shut down (it can be even damaged) if you write wrong values into VGA registers Very Happy. You must setup only values that are acceptable for that video card and video mode and monitor... this is error prone and it might damage some hardware while working ok with other hardware.

Take care, because you can permanently damage hardware by writting wrong values into hardware registers Very Happy
Post 17 Jun 2005, 10:15
View user's profile Send private message Visit poster's website Reply with quote
Opcode



Joined: 07 Jan 2005
Posts: 12
Opcode 17 Jun 2005, 14:06
Unfortunatelly appears that I will need to find another way.
I don't know how but I will keep my research.
Windows internals programming is not a problem to me, I'm doing
programming in the kernel for 3 years.
I will try to find out how the Windows XP clone( the Open Source ReactOS project) manages the video card.

Thanks for the answers! Cool
Post 17 Jun 2005, 14:06
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius 17 Jun 2005, 16:51
In Windows? Why do that in Windows? I don't think you'll be able to, as Windows is very picky about these things.

BTW vid, if you're willing to do some dirty work (debugging BIOS) then why not use some BIOS source code? I have found some in several places online. It might be illegal, but you can learn a lot from it, and learning isn't illegal.
Post 17 Jun 2005, 16:51
View user's profile Send private message AIM Address Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 19 Jun 2005, 12:22
Quote:

I will try to find out how the Windows XP clone( the Open Source ReactOS project) manages the video card.

AFAIK by using windows drivers Smile

Opcode, are you trying to write a kernel-mode debugger? If you don't specifically need textmode, you could try going the SoftICE way of "universal video driver", by hooking DirectDraw or whatever it is they do...
Post 19 Jun 2005, 12:22
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 23 Jun 2005, 14:41
found this MASM code


Description:
Download
Filename: MODES.ZIP
Filesize: 6.47 KB
Downloaded: 507 Time(s)

Post 23 Jun 2005, 14:41
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Opcode



Joined: 07 Jan 2005
Posts: 12
Opcode 23 Jun 2005, 17:47
To f0dder:

Its is not exactly a kernel-mode debugger, but it have some functions
in common. Thanks for the DirectDraw hint.

To vid:

Thanks for the modes.zip.
I will try run it from inside the kernel.

Regards,
Opc0de
Post 23 Jun 2005, 17:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 23 Jun 2005, 19:33
Opcode: rather try to understand it and rewrite it yoursef
Post 23 Jun 2005, 19:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Opcode



Joined: 07 Jan 2005
Posts: 12
Opcode 23 Jun 2005, 23:10
vid wrote:
Opcode: rather try to understand it and rewrite it yoursef

Of course. This is exactly what I'm doing Wink
Post 23 Jun 2005, 23:10
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.