#### Archived

This topic is now archived and is closed to further replies.

# Mode-changing without BIOS

This topic is 5550 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Does anyone know how to change the screen resolution and plot pixels in protected mode without using the BIOS? I''ve seen several sites say "you can program the VGA registers directly", but nothing that tells *how*.

##### Share on other sites
You can do this by programming the VGA I/O ports.
I haven''t got my old VGA book at hand right now, but if I remember the ports are in the range 0x3C0..0x3DF.
The ports can be programmed by using the inportb/outportb family of functions (inpb/outpb depending on the compiler), or IN/OUT assembler instructions.
I''m afraid I won''t be able to dig up some source at this point, the book is probably somewhere in a dusty corner

##### Share on other sites
If you know Spanish, I can send you a document explaining how to do it. Years ago I did a project for the University called something like "Programming VGA driver for a protected mode operating system".
Basically, all you need to do is to program 60/70 registers of de VGA card.
This document also explain other things like change default VGA card font, different write and read modes of the VGA cards...

##### Share on other sites
Fortunatly, I *do* know a bit of spanish. Not much, but hopefully enough to stumble through the code. Anything helps!

[edited by - Quantum2005 on December 6, 2002 4:35:58 PM]

##### Share on other sites
Could you use DirectX? why do you need to get to the VGA registers?

##### Share on other sites
quote:
Original post by MattS423
Could you use DirectX? why do you need to get to the VGA registers?

Maybe he could use a Mac as well? Or how about J2ME and do it for a cell phone? Why does he need to do graphics at all?

Stop, think, THEN post.

##### Share on other sites
He doesn''t necessarly need to change it, but maybe there is a better way of doing it. thats all i''m saying.

Let''s not reinvent the wheel...

##### Share on other sites
quote:
Let''s not reinvent the wheel...

Yeah! Lets leave it square, and hope it rounds itself off while we slip a disk and suffer a hernia trying push it around!

##### Share on other sites
quote:
Original post by MattS423
He doesn''t necessarly need to change it, but maybe there is a better way of doing it. thats all i''m saying.

Let''s not reinvent the wheel...

Unfortunatly, I don''t have that luxury. The project I''m working on (probably should''ve said this in the first place) is a mini OS. I had simple graphics working in real mode using the following:
_setmode13h:	; VGA 320x200, 8bpp	mov ah,00   mov al,0x13   int 10h	ret

But now that I''m using protected mode, I can''t use the BIOS anymore.

Does anyone know the exact ports Prototype was talking about, and what to put into them? Also, it''d be nice to do SVGA modes as well, but I have a sneaking suspicion that that''s asking a bit much...

##### Share on other sites
You could look into DPMI, I''m trying to find info on that now... That may not be an option though I suppose... (Don''t have enough info to know yet.)

Check this.

##### Share on other sites
Had the same problem. My quick''n dirty solution was to set the screen resolution at boot time via the VESA BIOS.
Backing up a little, you can forget doing SVGA stuff by yourself (you''d at the very least need a mode set routine for the different chipsets; while GFx use almost the same code, that''s not the way to go.). Assuming you want more than 640x480:4, that leaves the VESA BIOS (spec available at www.vesa.org), and 3 ways to call it:
1) v86 mode (ugly)
2) with the protected mode entry point (I could not for the life of me get this working, and I’ve read that this is sometimes broken (that would be a nice explanation )
3) at system boot, in real mode (assuming you’re writing your own loader). This way’s the smallest, easiest, and least flexible.

Code from my boot sector:

  bits 16; set vbe mode	mov	ax, 0x4f02	mov	bx, VMODE|0xc800		; lfb, no mem clear, use crtc pll timing data	mov	di, crtc_timing		[see vbe dox]	int	0x10...bits 32; set lfb cache type to wc via mtrr; > ecx = 0x0000????; > edx = 0	mov	cx, 0x20e	mov	eax, lfb|1			; base address; type = wc	lea	edi, [eax-1]	wrmsr					; MTRRPhysBase7	inc	ecx	mov	eax, (-lfb_size)|0x800		; length of range; valid bit = 1	wrmsr; clear screen; > edi -> lfb	mov	eax, 0x00396da5			; light blue	mov	ecx, XRES*YRESrep	stosd

Note: a config program autodetects / asks for the following:
VMODE		equ	0x118XRES		equ	1024YRES		equ	768lfb		equ	0xe0000000mmio		equ	0xec000000lfb_size	equ	(16*1024*1024)

(values from my current config)
If you’ve got paging enabled, you will of course have to map the LFB.

Again a little explanation: the VBE sets the desired video mode, and returns a pointer to the linear frame buffer (=: LFB; I get the address at install/assemble time, because hey, we''re talking boot sector here ). There’s no bank switching like in VBE 1.2 or hand rolled SVGA – just a simple array a la mode 0x13.

HTH
Jan

• 10
• 14
• 11
• 10
• 12