Skip to main content
gamedev.net
🔒 Locked

Mode-changing without BIOS

Started by Quantum2005 Dec 5, 2002 at 3:54 PM 10 replies 1k views
Original Post
Quantum2005
Quantum2005
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*.
----------------------- I am 0x539. Are you?
Prototype
Prototype
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
lesmes
lesmes
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...
Quantum2005
Quantum2005
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]
----------------------- I am 0x539. Are you?
MattS423
MattS423
Could you use DirectX? why do you need to get to the VGA registers?
Programmers of the world, UNTIE!
scaught
scaught
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.
MattS423
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...
Programmers of the world, UNTIE!
Xanth
Xanth
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!
"I thought Genius lived in bottles..." - Patrick Star
Quantum2005
Quantum2005
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...
----------------------- I am 0x539. Are you?
Xanth
Xanth
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.)
"I thought Genius lived in bottles..." - Patrick Star
Jan Wassenberg
Jan Wassenberg
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*YRES
rep stosd



Note: a config program autodetects / asks for the following:

VMODE equ 0x118
XRES equ 1024
YRES equ 768

lfb equ 0xe0000000
mmio equ 0xec000000
lfb_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
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.