Back to real mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Back to real mode

Post by itisiuk »

hi sorry for this but i am really having a brain fart at the min :oops: :cry: :?
ive finally got a workin kernel now and im wanting to impelemt graphics now. ive been reading up anyway and i dont want to use vm86 as i have found that u can just set the video mode then write directly to the vid mem at 0xA0000, this is what i have found from visopsys anyway.

ufortunatley im loading from grub then setting up a higher half kernel at the 3Gb mark.
i am now really getting confused about how to switch back to real mode so i can setup the vid mode then switch back to pmode and finally do some graphics.

again soz for asking but has anyone got a nice simple example on how to switch back to real mode.

thanks :oops:
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Re: Back to real mode

Post by inflater »

If you want to switch to real mode,

1) you MUST load your kernel UNDER the first megabyte (nothing like GRUB permitted if you aren't relocating your kernel)
2) the kernel size must be under 64 kB, but it's possible to code your own multi-stage bootloader

Are you sure you don't want vm86? ;)
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Back to real mode

Post by itisiuk »

i have wrttien a boot loader b4 but i no longer have a floppy drive.

i can create floppy images and use them, but every time i try to write to the boot sector in linux it overwrites the the Fat BPB with 0's and i dont know how to fill these in useing a floppy image file, or avoid overwiting them.
im also still new to linux b4 i was using cygwin, but that doesnt work in vista. i so hate vista.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Back to real mode

Post by Combuster »

nice and simple:

Code: Select all

mov eax, cr0
and al, 0xFE
mov cr0, eax
i can create floppy images and use them, but every time i try to write to the boot sector in linux it overwrites the the Fat BPB with 0's and i dont know how to fill these in useing a floppy image file, or avoid overwiting them.
Get mtools.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Back to real mode

Post by itisiuk »

Thanks, im feeling like such an idiot today :oops: hence why ive been asking stuipd questions.
i think im back on track now. im going to work out out to use mtools then write my own bootloader and set graphics modes that way.
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Back to real mode

Post by Stevo14 »

You could also do it the way that I do in my kernel: I copy the raw object file containing the code that I want to be executed in real mode (which also contains the mode-switching code) to somewhere below 1mb then jump (or call if you want to return) to it. It switches to real mode, does whatever, and then switches back and jumps back into the kernel. No need for a custom boot loader or a vm86 task and it should work for a higher half kernel if you have the first 1mb identity mapped.
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: Back to real mode

Post by Ready4Dis »

I do as mentioned above, load it as a module, which is loaded below 1mb and run as a function call. I can call it with different values to do whatever i want (it is hardcoded to int 10h, and a specific buffer location for writing info back to), so I can call it, read the buffer and do what i need (set mode, get mode, query modes, get GPU memory, etc).
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Back to real mode

Post by Omega »

So, if you load the kernel above 1mb you cannot go back to rmode, is this what I am reading here? When grub gives me control I am in 32 bit, so do I need to do a vm86 emu or something to to do floppy reads/writes, etc?
Free energy is indeed evil for it absorbs the light.
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Back to real mode

Post by itisiuk »

I stubuled across oslib http://oslib.sourceforge.net/

this actually give a good way to implement vm86 tasks.
think i might just load up vm86 as a module with code derived from this.
i think this has been what ive been getting confused about the whole time. mind today has been a really bad and stange day for me today.

thanks for your comments they have kinda kept me from starting all over again :shock: dont want to do that again :cry:

as for vst_0201 comments as i have found out todat yep thats right.
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Back to real mode

Post by Stevo14 »

vst_0201 wrote:So, if you load the kernel above 1mb you cannot go back to rmode, is this what I am reading here?
itisiuk wrote:as for vst_0201 comments as i have found out todat yep thats right.
This is not entirely correct. You can get back to real mode if you load your kernel above 1mb but the code that runs in real mode must be both seperate from your kernel and below 1mb (or appear that way for a vm86 task). The two examples given in this thread would be loading the real mode code as a module or starting a vm86 task, both of which run the real mode code seperate from the rest of the kernel.

So if the question is "Can I switch back to real mode if I load my kernel above 1mb?" the answer is "Yes, but the actual code that runs in real mode needs to be seperate from the rest of the kernel and be (or appear to be for vm86) below 1mb."
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: Back to real mode

Post by Ready4Dis »

Yes, my kernel is @ the 3gb mark, and I still drop back to real-mode for video until I can get real driver support in. I have a VESA driver that has a stub program for doing this. The driver allocates memory below 1mb, copys the stub to this location, and passes it's starting offset. The stub is then called, does whatever call it is asked to do, and returns. It can be loaded to any location under 1mb (so it's position independant) and supports all the VESA functions. Very simple, works fine with my existing kernel, and no need to implement VM86 just for a SINGLE task that "should" be replaced when I can support real cards. I don't know what genius at VBE decided that changing pages was a good idea in p-mode, and not video modes, but that's what they decided for VBE 2.0, and what we have to work with.
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Back to real mode

Post by itisiuk »

I think now that it might just be best for me to impelment vm86, and then if i need any other bios calls at least it will cover everything ill need hopefully and then i wont have to think about it again.
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: Back to real mode

Post by Ready4Dis »

I was pm'd asking about my code, so for reference, it is posted for everyone (it is pretty dependant on my kernel, but the basic idea should be simple, especially the stub program!). I was having issues with the position independant code, so here is a position dependant version that is currently working, should be easily adaptable if you wanted to.

****** Edit **** Oops, pasted the wrong file in here!!!! Hopefully this makes more sense now!
First the Real mode stub:

Code: Select all

;Always placed at 0x7000
[bits	32]
[org	0x7000]

;Variables passed from application
UserAX dw 0
UserBX dw 0
UserCX dw 0
UserDX dw 0

VBE_Func:
	cli		;Disable interrupts for now

	pusha
	mov		[InitialESP],	esp				;Store this for returning
	sidt	[InitialIDT]					;Store initial IDT
	lidt	[idt_real]						;Load the real mode IDT

	jmp		0x28:do_pmode16
[bits 16]
do_pmode16:

	mov		ax,		0x30
	mov		ds,		ax
	mov		es,		ax
	mov		fs,		ax
	mov		gs,		ax
	mov		ss,		ax

	mov		eax,	cr0
	and		eax,	0x7ffffffe				;Disable paging and pmode ;)
	mov		cr0,	eax						;Unset pmode bit (aka, real mode)

	jmp		0x0000:do_realmode				;Jump to real mode now
do_realmode:

	xor		ax,		ax
	mov		ds,		ax
	mov		es,		ax
	mov		fs,		ax
	mov		gs,		ax
	mov		ss,		ax
	mov		edi,	VBE_Data				;es:di = source/dest, so last 512 bytes of this page
	mov		esp,	VBE_Data				;Stack right under our VBE_Data just incase ;)

	mov		ax,		[UserAX]
	mov		bx,		[UserBX]
	mov		cx,		[UserCX]
	mov		dx,		[UserDX]

	sti
	int		0x10
	cli

	mov		[UserDX],	dx
	mov		[UserCX],	cx
	mov		[UserBX],	bx
	mov		[UserAX],	ax

	mov		eax,	cr0
	or		eax,	0x80000001				;Enable pmode & paging
	mov		cr0,	eax

	jmp		0x08:do_pmode32					;Jump to 32-bit pmode
[bits 32]
do_pmode32:
	mov		ax,		0x10
	mov		ds,		ax
	mov		es,		ax
	mov		fs,		ax
	mov		gs,		ax
	mov		ss,		ax
	mov		esp,	[InitialESP]
	popa
	lidt	[InitialIDT]
	sti		;Re-enable interrupts
	ret

; *** Data variables ***

;Our starting ESP
InitialESP	dd	0

InitialIDT:
	dw	0
	dd	0
;Real mode IVT
idt_real:
	dw	0x3ff
	dd	0x0000

;0x8000-512 = 0x7E00
VBE_Data equ 0x4000
Now, the VESA header file, includes my ASCII font that I typed by hand into my editor ;)

Code: Select all

#ifndef VESA_H
#define VESA_H

struct VBEInfo_S
{
	s8		Signature[4];		//Signature 'VESA', returns VBE2
	u16		Version;			//0x0200
	u32		OEMString;			//Pointer to OEM string (fix me, we are seg:off)
	u32		Caps;				//Capabilities, unused for now
	u32		VideoModePtr;		//Pointer to video modes (fix me, we are seg:off)
	u16		TotalMemory;		//How many 64k segments we have
	u16		SoftwareRev;		//Software revision
	u32		OEMVendorPtr;		//(fix me, we are seg:off)
	u32		OEMNamePtr;			//(fix me, we are seg:off)
	u32		OEMRevPtr;			//(fix me, we are seg:off)
};

struct VBEModeInfo_S
{
	u16		ModeAttributes;
	u8		WinAAttributes,WinBAttributes;
	u16		WinGranularity;
	u16		WinSize;
	u16		WinASegment,WinBSegment;
	u32		WinFuncPtr;
	u16		BytesPerScanLine;
	u16		XRes;
	u16		YRes;
	u8		XCharSize,YCharSize;
	u8		NumberOfPlanes;
	u8		BitsPerPixel;
	u8		NumberOfBanks;
	u8		MemoryModel;
	u8		BankSize;
	u8		NumberOfImagePages;
	u8		res1;
	u8		RedMaskSize,RedFieldPosition;
	u8		GreenMaskSize,GreenFieldPosition;
	u8		BlueMaskSize,BlueFieldPosition;
	u8		RsvedMaskSize,RsvedFieldPosition;
	u8		DirectColorModeAttr;
	//VBE 2.0
	u32		PhysBasePtr;
	u32		OffScreenMemOffset;
	u16		OffScreenMemSize;
};

struct VESARegs_S
{
	u16 ax;
	u16 bx;
	u16 cx;
	u16 dx;
};

struct VESAMode_S
{
	u32		Mode;
	u32		BasePtr;
	u32		Attributes;
	u32		Width, Height;
	u32		BitDepth;
	u32		ScanlineWidth;
	u8		RedMaskSize, RedPosition;
	u8		GreenMaskSize, GreenPosition;
	u8		BlueMaskSize, BluePosition;
};

//Max of 256
u8 AsciiChars[256*8] =
{
	0,0,0,0,0,0,0,0,	//0
	0,0,0,0,0,0,0,0,	//1
	0,0,0,0,0,0,0,0,	//2
	0,0,0,0,0,0,0,0,	//3
	0,0,0,0,0,0,0,0,	//4
	0,0,0,0,0,0,0,0,	//5
	0,0,0,0,0,0,0,0,	//6
	0,0,0,0,0,0,0,0,	//7
	0,0,0,0,0,0,0,0,	//8
	0,0,0,0,0,0,0,0,	//9
	0,0,0,0,0,0,0,0,	//10
	0,0,0,0,0,0,0,0,	//11
	0,0,0,0,0,0,0,0,	//12
	0,0,0,0,0,0,0,0,	//13
	0,0,0,0,0,0,0,0,	//14
	0,0,0,0,0,0,0,0,	//15
	0,0,0,0,0,0,0,0,	//16
	0,0,0,0,0,0,0,0,	//17
	0,0,0,0,0,0,0,0,	//18
	0,0,0,0,0,0,0,0,	//19
	0,0,0,0,0,0,0,0,	//20
	0,0,0,0,0,0,0,0,	//21
	0,0,0,0,0,0,0,0,	//22
	0,0,0,0,0,0,0,0,	//23
	0,0,0,0,0,0,0,0,	//24
	0,0,0,0,0,0,0,0,	//25
	0,0,0,0,0,0,0,0,	//26
	0,0,0,0,0,0,0,0,	//27
	0,0,0,0,0,0,0,0,	//28
	0,0,0,0,0,0,0,0,	//29
	0,0,0,0,0,0,0,0,	//30
	0,0,0,0,0,0,0,0,	//31
	0,0,0,0,0,0,0,0,	//32

/* 33 '!' */
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x00,		//00000000
	0x10,		//00010000
	0x00,		//00000000

/* 34 '"' */
	0x6c,		//01101100
	0x6c,		//01101100
	0x28,		//00101000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000


/* 35 '#' */
	0x24,		//00100100
	0x24,		//00100100
	0x7E,		//01111110
	0x24,		//00100100
	0x7E,		//01111110
	0x24,		//00100100
	0x24,		//00100100
	0x00,		//00000000

/* 36 '$' */
	0x10,		//00010000
	0x7C,		//01111100
	0x90,		//10010000
	0x7C,		//01111100
	0x12,		//00010010
	0x7C,		//01111100
	0x10,		//00010000
	0x00,		//00000000

/* 37 '%' */
	0x00,		//00000000
	0x44,		//01000100
	0x08,		//00001000
	0x10,		//00010000
	0x20,		//00100000
	0x44,		//01000100
	0x00,		//00000000
	0x00,		//00000000

/* 38 '&' */
	0x70,		//01110000
	0x88,		//10001000
	0x50,		//01010000
	0x20,		//00100000
	0x54,		//01010100
	0x88,		//10001000
	0x74,		//01110100
	0x00,		//00000000


/* 39 ''' */
	0x18,		//00011000
	0x10,		//00010000
	0x20,		//00100000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000

/* 40 '(' */
	0x08,		//00001000
	0x10,		//00010000
	0x20,		//00100000
	0x20,		//00100000
	0x20,		//00100000
	0x10,		//00010000
	0x08,		//00001000
	0x00,		//00000000

/* 41 ')' */
	0x20,		//00100000
	0x10,		//00010000
	0x08,		//00001000
	0x08,		//00001000
	0x08,		//00001000
	0x10,		//00010000
	0x20,		//00100000
	0x00,		//00000000

/* 42 '*' */
	0x00,		//00000000
	0x44,		//01000100
	0x28,		//00101000
	0x7C,		//01111100
	0x28,		//00101000
	0x44,		//01000100
	0x00,		//00000000
	0x00,		//00000000

/* 43 '+' */
	0x00,		//00000000
	0x10,		//00010000
	0x10,		//00010000
	0x7C,		//01111100
	0x10,		//00010000
	0x10,		//00010000
	0x00,		//00000000
	0x00,		//00000000

/* 44 ',' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x18,		//00011000
	0x10,		//00010000
	0x20,		//00100000

/* 45 '-' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x7C,		//01111100
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000

/* 46 '.' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x18,		//00011000
	0X18,		//00011000
	0x00,		//00000000

/* 47 '/' */
	0x00,		//00000000
	0x04,		//00000100
	0x08,		//00001000
	0x10,		//00010000
	0x20,		//00100000
	0x40,		//01000000
	0x00,		//00000000
	0x00,		//00000000

/* 48 '0' */
	0x38,		//00111000
	0x44,		//01000100
	0x8A,		//10001010
	0x92,		//10010010
	0xA2,		//10100010
	0x44,		//01000100
	0x38,		//00111000
	0x00,		//00000000

/* 49 '1' */
	0x18,		//00011000
	0x28,		//00101000
	0x48,		//01001000
	0x08,		//00001000
	0x08,		//00001000
	0x08,		//00001000
	0x7E,		//01111110
	0x00,		//00000000

/* 50 '2' */
	0x7C,		//01111100
	0x82,		//10000010
	0x82,		//10000010
	0x1C,		//00011100
	0xE0,		//11100000
	0x80,		//10000000
	0xFE,		//11111110
	0x00,		//00000000

/* 51 '3' */
	0x7C,		//01111100
	0x82,		//10000010
	0x02,		//00000010
	0x1C,		//00011100
	0x02,		//00000010
	0x82,		//10000010
	0x7C,		//01111100
	0x00,		//00000000

/* 52 '4' */
	0x04,		//00000100
	0x44,		//01000100
	0x44,		//01000100
	0x7C,		//01111100
	0x04,		//00000100
	0x04,		//00000100
	0x04,		//00000100
	0x00,		//00000000

/* 53 '5' */
	0xFE,		//11111110
	0x80,		//10000000
	0xFC,		//11111100
	0x02,		//00000010
	0x02,		//00000010
	0x82,		//10000010
	0x7C,		//01111100
	0x00,		//00000000

/* 54 '6' */
	0x06,		//00000110
	0x18,		//00011000
	0x20,		//00100000
	0x7C,		//01111100
	0x82,		//10000010
	0x82,		//10000010
	0x7C,		//01111100
	0x00,		//00000000

/* 55 '7' */
	0xFE,		//11111110
	0x84,		//10000100
	0x08,		//00001000
	0x08,		//00001000
	0x10,		//00010000
	0x10,		//00010000
	0x20,		//00100000
	0x00,		//00000000

/* 56 '8' */
	0x7C,		//01111100
	0x82,		//10000010
	0x82,		//10000010
	0x7C,		//01111100
	0x82,		//10000010
	0x82,		//10000010
	0x7C,		//01111100
	0x00,		//00000000

/* 57 '9' */
	0x7E,		//01111110
	0x82,		//10000010
	0x82,		//10000010
	0x7E,		//01111110
	0x04,		//00000100
	0x04,		//00000100
	0x08,		//00001000
	0x00,		//00000000

/* 58 ':' */
	0x00,		//00000000
	0x10,		//00010000
	0x00,		//00000000
	0x00,		//00000000
	0x10,		//00010000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000

/* 59 ';' */
	0x00,		//00000000
	0x10,		//00010000
	0x00,		//00000000
	0x00,		//00000000
	0x10,		//00010000
	0x20,		//00100000
	0x00,		//00000000
	0x00,		//00000000

/* 60 '<' */
	0x08,		//00001000
	0x10,		//00010000
	0x20,		//00100000
	0x40,		//01000000
	0x20,		//00100000
	0x10,		//00010000
	0x08,		//00001000
	0x00,		//00000000

/* 61 '=' */
	0x00,		//00000000
	0x00,		//00000000
	0x7C,		//01111100
	0x00,		//00000000
	0x00,		//00000000
	0x7C,		//01111100
	0x00,		//00000000
	0x00,		//00000000

/* 62 '>' */
	0x20,		//00100000
	0x10,		//00010000
	0x08,		//00001000
	0x04,		//00000100
	0x08,		//00001000
	0x10,		//00010000
	0x20,		//00100000
	0x00,		//00000000

/* 63 '?' */
	0x7C,		//01111100
	0x82,		//10000010
	0x04,		//00000100
	0x08,		//00001000
	0x10,		//00010000
	0x00,		//00000000
	0x10,		//00010000
	0x00,		//00000000

/* 64 '@' */
	0x7C,		//01111100
	0x82,		//10000010
	0xBA,		//10111010
	0xAA,		//10101010
	0xBE,		//10111110
	0x80,		//10000000
	0x7E,		//01111110
	0x00,		//00000000

/* 65 'A' */
	0x10,		//00010000
	0x28,		//00101000
	0x28,		//00101000
	0x44,		//01000100
	0x7C,		//01111100
	0x82,		//10000010
	0x82,		//10000010
	0x00,		//00000000

/* 66 'B' */
	0xFC,		//11111100
	0x82,		//10000010
	0x82,		//10000010
	0xFC,		//11111100
	0x82,		//10000010
	0x82,		//10000010
	0xFC,		//11111100
	0x00,		//00000000

/* 67 'C' */
	0x7C,		//01111100
	0x82,		//10000010
	0x80,		//10000000
	0x80,		//10000000
	0x80,		//10000000
	0x82,		//10000010
	0x7C,		//01111100
	0x00,		//00000000

/* 68 'D'*/
	0xF8,		//11111000
	0x84,		//10000100
	0x82,		//10000010
	0x82,		//10000010
	0x82,		//10000010
	0x84,		//10000100
	0xF8,		//11111000
	0x00,		//00000000

/* 69 'E' */
	0xFE,		//11111110
	0x80,		//10000000
	0x80,		//10000000
	0xF8,		//11111000
	0x80,		//10000000
	0x80,		//10000000
	0xFE,		//11111110
	0x00,		//00000000

/* 70 'F' */
	0xFE,		//11111110
	0x80,		//10000000
	0x80,		//10000000
	0xF8,		//11111000
	0x80,		//10000000
	0x80,		//10000000
	0x80,		//10000000
	0x00,		//00000000

/* 71 'G' */
	0x7C,		//01111100
	0x82,		//10000010
	0x80,		//10000000
	0x80,		//10000000
	0x9C,		//10011100
	0x82,		//10000010
	0x7C,		//01111100
	0x00,		//00000000

/* 72 'H' */
	0x82,		//10000010
	0x82,		//10000010
	0x82,		//10000010
	0xFE,		//11111110
	0x82,		//10000010
	0x82,		//10000010
	0x82,		//10000010
	0x00,		//00000000

/* 73 'I' */
	0x7C,		//01111100
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x7C,		//01111100
	0x00,		//00000000

/* 74 'J' */
	0x3E,		//00111110
	0x08,		//00001000
	0x08,		//00001000
	0x08,		//00001000
	0x08,		//00001000
	0x88,		//10001000
	0x70,		//01110000
	0x00,		//00000000

/* 75 'K' */
	0x86,		//10000110
	0x88,		//10001000
	0x90,		//10010000
	0xA0,		//11100000
	0xD0,		//10010000
	0x88,		//10001000
	0x86,		//10000110
	0x00,		//00000000

/* 76 'L' */
	0x80,		//10000000
	0x80,		//10000000
	0x80,		//10000000
	0x80,		//10000000
	0x80,		//10000000
	0x80,		//10000000
	0xFE,		//11111110
	0x00,		//00000000

/* 77 'M' */
	0x82,		//10000010
	0xC6,		//11000110
	0xAA,		//10101010
	0x92,		//10010010
	0x82,		//10000010
	0x82,		//10000010
	0x82,		//10000010
	0x00,		//00000000

/* 78 'N' */
	0x82,		//10000010
	0xC2,		//11000010
	0xA2,		//10100010
	0x92,		//10010010
	0x8A,		//10001010
	0x86,		//10000110
	0x82,		//10000010
	0x00,		//00000000

/* 79 'O' */
	0x38,		//00111000
	0x44,		//01000100
	0x82,		//10000010
	0x82,		//10000010
	0x82,		//10000010
	0x44,		//01000100
	0x38,		//00111000
	0x00,		//00000000

/* 80 'P' */
	0xFC,		//11111100
	0x82,		//10000010
	0x82,		//10000010
	0xFC,		//11111100
	0x80,		//10000000
	0x80,		//10000000
	0x80,		//10000000
	0x00,		//00000000

/* 81 'Q' */
	0x38,		//00111000
	0x44,		//01000100
	0x82,		//10000010
	0x82,		//10000010
	0x9A,		//10011010
	0x44,		//01000100
	0x3A,		//00111010
	0x00,		//00000000

/* 82 'R' */
	0xFC,		//11111100
	0x82,		//10000010
	0x82,		//10000010
	0xFC,		//11111100
	0x90,		//10010000
	0x88,		//10001000
	0x86,		//10000110
	0x00,		//00000000

/* 83 'S' */
	0x7C,		//01111100
	0x82,		//10000010
	0x80,		//10000000
	0x7C,		//01111100
	0x02,		//00000010
	0x82,		//10000010
	0x7C,		//01111100
	0x00,		//00000000

/* 84 'T' */
	0xFE,		//11111110
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x00,		//00000000

/* 85 'U' */
	0x82,		//10000010
	0x82,		//10000010
	0x82,		//10000010
	0x82,		//10000010
	0x82,		//10000010
	0x44,		//01000100
	0x38,		//00111000
	0x00,		//00000000

/* 86 'V' */
	0x82,		//10000010
	0x82,		//10000010
	0x44,		//01000100
	0x44,		//01000100
	0x28,		//00101000
	0x28,		//00101000
	0x10,		//00010000
	0x00,		//00000000

/* 87 'W' */
	0x82,		//10000010
	0x82,		//10000010
	0x92,		//10010010
	0x92,		//10010010
	0xAA,		//10101010
	0xAA,		//10101010
	0x44,		//01000100
	0x00,		//00000000

/* 88 'X' */
	0x82,		//10000010
	0x44,		//01000100
	0x28,		//00101000
	0x10,		//00010000
	0x28,		//00101000
	0x44,		//01000100
	0x82,		//10000010
	0x00,		//00000000

/* 89 'Y' */
	0x82,		//10000010
	0x44,		//01000100
	0x28,		//00101000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x00,		//00000000

/* 90 'Z' */
	0xFE,		//11111110
	0x04,		//00000100
	0x08,		//00001000
	0x10,		//00010000
	0x20,		//00100000
	0x40,		//01000000
	0xFE,		//11111110
	0x00,		//00000000

/* 91 '[' */
	0x38,		//00111000
	0x20,		//00100000
	0x20,		//00100000
	0x20,		//00100000
	0x20,		//00100000
	0x20,		//00100000
	0x38,		//00111000
	0x00,		//00000000

/* 92 '\' */
	0x00,		//00000000
	0x40,		//01000000
	0x20,		//00100000
	0x10,		//00010000
	0x08,		//00001000
	0x04,		//00000100
	0x00,		//00000000
	0x00,		//00000000

/* 93 ']' */
	0x38,		//00111000
	0x08,		//00001000
	0x08,		//00001000
	0x08,		//00001000
	0x08,		//00001000
	0x08,		//00001000
	0x38,		//00111000
	0x00,		//00000000

/* 94 '^' */
	0x10,		//00010000
	0x28,		//00101000
	0x44,		//01000100
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000

/* 95 '_' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0xFF,		//11111111

/* 96 '`' */
	0x30,		//00110000
	0x10,		//00010000
	0x08,		//00001000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000

/* 97 'a' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x7C,		//01111100
	0x84,		//10000100
	0x84,		//10000100
	0x7A,		//01111010
	0x00,		//00000000

/* 98 'b' */
	0x80,		//10000000
	0x80,		//10000000
	0x80,		//10000000
	0x78,		//11111000
	0x84,		//10000100
	0x84,		//10000100
	0x78,		//11111000
	0x00,		//00000000

/* 99 'c' */
	0x00,		//00000000
	0x00,		//00000000
	0x38,		//00111000
	0x44,		//01000100
	0x80,		//10000000
	0x44,		//01000100
	0x38,		//00111000
	0x00,		//00000000

/* 100 'd' */
	0x04,		//00000100
	0x04,		//00000100
	0x04,		//00000100
	0x7C,		//01111100
	0x84,		//10000100
	0x84,		//10000100
	0x7C,		//01111100
	0x00,		//00000000

/* 101 'e' */
	0x00,		//00000000
	0x00,		//00000000
	0x78,		//01111000
	0x84,		//10000100
	0xFC,		//11111100
	0x80,		//10000000
	0x7C,		//01111100
	0x00,		//00000000

/* 102 'f' */
	0x38,		//00111000
	0x44,		//01000100
	0x40,		//01000000
	0xF0,		//11110000
	0x40,		//01000000
	0x40,		//01000000
	0x40,		//01000000
	0x00,		//00000000

/* 103 'g' */
	0x00,		//00000000
	0x00,		//00000000
	0x38,		//00111000
	0x44,		//01000100
	0x44,		//01000100
	0x3C,		//00111100
	0x04,		//00000100
	0x38,		//00111000

/* 104 'h' */
	0x80,		//10000000
	0x80,		//10000000
	0x80,		//10000000
	0xB8,		//10111000
	0xC4,		//11000100
	0x84,		//10000100
	0x84,		//10000100
	0x00,		//00000000

/* 105 'i' */
	0x00,		//00000000
	0x10,		//00010000
	0x00,		//00000000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x00,		//00000000

/* 106 'j' */
	0x00,		//00000000
	0x08,		//00001000
	0x00,		//00000000
	0x08,		//00001000
	0x08,		//00001000
	0x08,		//00001000
	0x48,		//01001000
	0x30,		//00110000

/* 107 'k' */
	0x80,		//10000000
	0x80,		//10000000
	0x98,		//10011000
	0xA0,		//10100000
	0xC0,		//11000000
	0xA0,		//10100000
	0x90,		//10010000
	0x00,		//00000000

/* 108 'l' */
	0x00,		//00000000
	0x20,		//00100000
	0x20,		//00100000
	0x20,		//00100000
	0x20,		//00100000
	0x20,		//00100000
	0x30,		//00110000
	0x00,		//00000000

/* 109 'm' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x6C,		//01101100
	0x92,		//10010010
	0x92,		//10010010
	0X92,		//10010010
	0x00,		//00000000

/* 110 'n' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x78,		//01111000
	0x84,		//10000100
	0x84,		//10000100
	0x84,		//10000100
	0x00,		//00000000

/* 111 'o' */
	0x00,		//00000000
	0x00,		//00000000
	0x78,		//01111000
	0x84,		//10000100
	0x84,		//10000100
	0x84,		//10000100
	0x78,		//01111000
	0x00,		//00000000

/* 112 'p' */
	0x00,		//00000000
	0x00,		//00000000
	0xB8,		//10111000
	0xC4,		//11000100
	0x82,		//10000010
	0xC4,		//11000100
	0xB8,		//10111000
	0x80,		//10000000

/* 113 'q' */
	0x00,		//00000000
	0x00,		//00000000
	0x78,		//01111000
	0x84,		//10000100
	0x84,		//10000100
	0x7C,		//01111100
	0x04,		//00000100
	0x06,		//00000110

/* 114 'r' */
	0x00,		//00000000
	0x00,		//00000000
	0x5C,		//01011100
	0x22,		//00100010
	0x20,		//00100000
	0x20,		//00100000
	0x20,		//00100000
	0x00,		//00000000

/* 115 's' */
	0x00,		//00000000
	0x00,		//00000000
	0x3C,		//00111100
	0x40,		//01000000
	0x38,		//00111000
	0x04,		//00000100
	0x78,		//01111000
	0x00,		//00000000

/* 114 't' */
	0x00,		//00000000
	0x00,		//00000000
	0x10,		//00010000
	0x3C,		//00111100
	0x10,		//00010000
	0x10,		//00010000
	0x10,		//00010000
	0x00,		//00000000

/* 115 'u' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x44,		//01000100
	0x44,		//01000100
	0x44,		//01000100
	0x3A,		//00111010
	0x00,		//00000000

/* 116 'v' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x82,		//10000010
	0x44,		//01000100
	0x28,		//00101000
	0x10,		//00010000
	0x00,		//00000000

/* 117 'w' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x82,		//10000010
	0x92,		//10010010
	0x54,		//01010100
	0x28,		//00101000
	0x00,		//00000000

/* 118 'x' */
	0x00,		//00000000
	0x00,		//00000000
	0x44,		//01000100
	0x28,		//00101000
	0x10,		//00010000
	0x28,		//00101000
	0x44,		//01000100
	0x00,		//00000000

/* 119 'y' */
	0x00,		//00000000
	0x00,		//00000000
	0x00,		//00000000
	0x82,		//10000010
	0x44,		//01000100
	0x28,		//00101000
	0x10,		//00010000
	0x60,		//01100000

/* 120 'z' */
	0x00,		//00000000
	0x00,		//00000000
	0x7C,		//01111100
	0x08,		//00001000
	0x10,		//00010000
	0x20,		//00100000
	0x7C,		//01111100
	0x00,		//00000000

};

#endif
Last but not least, my VESA driver thus far (not much functionality yet).

Code: Select all

#include "../../../Global/Driver.h"
#include "../../../Global/LowLevel.h"
#include "../../../Global/kprint.h"
#include "../../../Global/Interrupts.h"
#include "../../../Global/VFS.h"
#include "../../../Global/Memory.h"
#include "../../../Global/Multitask.h"
#include "../../../Global/List.h"
#include "../../../Global/Interface.h"
#include "../../../Global/Graphics.h"
#include "VESA.h"

struct DriverInfo_S DriverInfo = {3,7,1,0};

/* VBE Modes (in bx)
	D0-D8 (d8=1 = vesa)
	D9-D13 = 0, reserved
	D14 = lineare bit (1=linear, 0=banked)
	D15 = 0-clear video memory, 1-preserve

	ah = 0x4f, vbe function
	al = function to perform

Function 0x00
	ES:DI  = pointer to buffer to place VbeInfoBlock struct
			(VBESignature should be set to 'VBE2' when called, 512 bytes)
*/

u32 VideoMem=1;
volatile u32 Running=1;
struct VESARegs_S *VesaRegs = (struct VESARegs_S*)0x7000;					//Our registers
void (*CallVesaBios)(void) = (void (*)(void))0x7008;						//ax,bx,cx,dx
struct VBEInfo_S		*ptrVBEInfo = (struct VBEInfo_S*)0x4000;			//Reserved for VESA info
struct VBEModeInfo_S	*ptrVBEModeInfo = (struct VBEModeInfo_S*)0x4000;
struct VESAMode_S	*ptrCurrentVESAMode = (struct VESAMode_S*)1;
struct DoubleList_S	VESAModeList = {0,0,0,sizeof(struct VESAMode_S)};

u8 *TestInfo = (u8*)0x4000;
KBDFunc_T OldKBDFunc=(KBDFunc_T)1;

void VESAKeyFunc(u32 Key)
{
	kprint("VESA Key Hit\n");
	Running = 0;
}

void InstallVesaBios(void)
{
	struct VFS_S *ptrVFS;
	ptrVFS = VFS_FindPath(&VFS_Root,"dev/block/rd0/VESA.bin");
	VFS_Read(ptrVFS,0,ptrVFS->Size,VesaRegs);		//Read it to it's proper location ;)
}

//Turns  real-mode pointer (seg:offset) to a linear pointer
void Real2Linear(u32 *ptr)
{
	u32 Tmp;
	Tmp = (*ptr)>>12;			//Remove the bottom 16-bits
	Tmp |= (*ptr) & 0x0000ffff;	//Add the bottom 16-bits
	*ptr = Tmp;
}

void SetColorPal(u8 Index, u8 r, u8 g, u8 b)
{
	Outport8(0x3c8,Index);
	Outport8(0x3c9,b>>4);
	Outport8(0x3c9,g>>4);
	Outport8(0x3c9,r>>4);
}

//Try a generic pallete
void SetPallete(void)
{
	u32 r,g,b,i=0;
	u32 cr, cg, cb;
	for (r=0;r!=6;++r)
	{
		cr = r*51;
		for (g=0;g!=7;++g)
		{
			cg = g*42;
			for (b=0;b!=6;++b)
			{
				cb = b*51;
				SetColorPal(i,cr,cg,cb);
				++i;
			}
		}
	}
}

#define abs(v) ((v)<0)?-(v):(v)

struct VESAMode_S *FindClosestVESAMode(u32 Width, u32 Height, u32 BitDepth)
{
	u32 Ctr=0;
	u32 ClosestDiff=0xffffffff;
	s32 TmpDiff;
	struct VESAMode_S	*ptrMode, *ptrClosest=0;

	ptrMode = DL_GetFirst(&VESAModeList);
	while (ptrMode)
	{
		TmpDiff =	abs((s32)Width-(s32)ptrMode->Width) +
					abs((s32)Height-(s32)ptrMode->Height) +
					abs((s32)BitDepth-(s32)ptrMode->BitDepth);
		if (TmpDiff < ClosestDiff)
		{
			ClosestDiff = TmpDiff;
			ptrClosest = ptrMode;
		}
		++Ctr;
		ptrMode = DL_GetNext(&VESAModeList);
	}
	return ptrClosest;
}

void SetTextMode(void)
{
//	VesaRegs->ax = 0x1112;								//Set 80x50 text mode
	VesaRegs->ax = 0x03;								//Set 80x25 text mode
	VesaRegs->bx = 0;
	CallVesaBios();										//Make the call
	VesaRegs->ax = 0x1112;								//Set 80x50 text mode
	VesaRegs->bx = 0;
	CallVesaBios();										//Make the call
}

/* Returns 0 on success, otherwise returns error value */
u8 SetMode(u32 Width, u32 Height, u32 BitDepth)
{
	struct VESAMode_S	*ptrMode;
	u32 Addr, Pages;

	ptrMode = FindClosestVESAMode(Width,Height,BitDepth);

	VesaRegs->ax = 0x4f02;								//Set VBE Mode
	VesaRegs->bx = ptrMode->Mode | 0x4000;				//What mode to set + linear bit
	CallVesaBios();										//Make the call

	if ((VesaRegs->ax & 0x4f) != 0x4f)
		return -1;	//failed to set mode

	ptrCurrentVESAMode = ptrMode;	//Update the current mode

/* Lets map our entire video card area */
	Pages = VideoMem/4096;
	Addr = 0;
	while (Pages--)
	{
		Virtual2Physical(0x800000+Addr,ptrMode->BasePtr+Addr);
		Addr+=4096;
	}
//If this is an 8-bit mode, lets set the pallete here
	SetPallete();
	return 0;
}

void PutPixel(s32 x, s32 y, u32 r, u32 g, u32 b)
{
	u32 Offset;
	u8 *PtrBuff = (u8*)0x800000;
	r&=0xff;
	g&=0xff;
	b&=0xff;
	switch (ptrCurrentVESAMode->BitDepth)
	{
	case 8:
		Offset = (y * ptrCurrentVESAMode->ScanlineWidth) + x;
		PtrBuff[Offset] = (r+50)/51;
		PtrBuff[Offset]+= ((g+41)/42)*6;
		PtrBuff[Offset]+= ((b+50)/51)*6*7;
		break;
	case 15:
	case 16:
		break;
	case 24:
		Offset = (y * ptrCurrentVESAMode->ScanlineWidth) + x*3;
		PtrBuff[Offset++] = b;
		PtrBuff[Offset++] = g;
		PtrBuff[Offset++] = r;
		break;
	case 32:
		Offset = (y * ptrCurrentVESAMode->ScanlineWidth) + x*4;
		PtrBuff[Offset++] = b;
		PtrBuff[Offset++] = g;
		PtrBuff[Offset++] = r;
		break;
	};
}

void VESA_WriteByteE(u8 c, u32 x, u32 y, u32 r, u32 g, u32 b)
{
	u32 Ctr, Ct2;
	u32 Start;
	u8 Bit;
	Start = (c*8);	//Start in our AsciiChars
	for (Ctr=0;Ctr!=8;++Ctr)		//Each byte
	{
		for (Ct2=0;Ct2!=8;++Ct2)	//Each bit
		{
			Bit = (AsciiChars[Ctr+Start]>>Ct2)&1;
			if (Bit)
				PutPixel(x+8-Ct2,y+Ctr,r,g,b);
			else
				PutPixel(x+8-Ct2,y+Ctr,0,0,0);
		}
	}
}


/* Our 2D Basic Functions */

struct Clipper_S	CurrentClipper = {0,0,1,1};

void SetClipper(struct Clipper_S *Clipper)
{
	MemCopy8(&CurrentClipper,Clipper,sizeof(struct Clipper_S));
}

struct Blend_S
{
	s32 CurRed, CurGreen, CurBlue, CurAlpha;
	s32 IncRed, IncGreen, IncBlue, IncAlpha;
};

void GenerateBlend(struct Color_S *c1, struct Color_S *c2, struct Blend_S *blend, s32 Dist)
{
	blend->CurRed = c1->r;
	blend->CurGreen = c1->g;
	blend->CurBlue = c1->b;
	blend->CurAlpha = c1->a;
	blend->IncRed = c2->r;
	blend->IncGreen = c2->g;
	blend->IncBlue = c2->b;
	blend->IncAlpha = c2->a;
	blend->IncRed -= c1->r;
	blend->IncGreen -= c1->g;
	blend->IncBlue -= c1->b;
	blend->IncAlpha -= c1->a;

	blend->CurRed<<=16;
	blend->CurGreen<<=16;
	blend->CurBlue<<=16;
	blend->CurAlpha<<=16;
	blend->IncRed<<=16;
	blend->IncGreen<<=16;
	blend->IncBlue<<=16;
	blend->IncAlpha<<=16;

	blend->IncRed/=Dist;
	blend->IncGreen/=Dist;
	blend->IncBlue/=Dist;
	blend->IncAlpha/=Dist;
}

void UpdateBlend(struct Blend_S *blend)
{
	blend->CurRed += blend->IncRed;
	blend->CurGreen += blend->IncGreen;
	blend->CurBlue += blend->IncBlue;
	blend->CurAlpha += blend->IncAlpha;
}

void UpdateBlendTimes(struct Blend_S *blend, u32 Times)
{
	blend->CurRed += blend->IncRed*Times;
	blend->CurGreen += blend->IncGreen*Times;
	blend->CurBlue += blend->IncBlue*Times;
	blend->CurAlpha += blend->IncAlpha*Times;
}

void DrawHLine32(s32 y, s32 x1, s32 x2, u32 r, u32 g, u32 b)
{
	u32 Value, Offset;
	r&=0xff;
	g&=0xff;
	b&=0xff;

	Value = (r<<16) + (g<<8) + b;
	Offset = (y * ptrCurrentVESAMode->ScanlineWidth) + x1*4;
	MemSet32((void*)(0x800000+Offset),Value,x2-x1);
}

void DrawHLine(s32 y, s32 x1, s32 x2, u32 r, u32 g, u32 b)
{
	while (x1++ != x2)
		PutPixel(x1,y,r,g,b);
}

void DrawRect(struct FillRect_S *Rect)
{
	struct Blend_S Blender;
	struct FillRect_S NewRect = *Rect;
	u32 Ctr;

/*
	if (NewRect.Top > NewRect.Bottom)	//Upside down?
	{
		Ctr = NewRect.Top;
		NewRect.Top = NewRect.Bottom;
		NewRect.Bottom = Ctr;
	}
*/

	if (Rect->Flags & GRAPH_FILL_VGRADIENT)	//Vertical Gradient?
	{
		GenerateBlend(&NewRect.Color1,&NewRect.Color2,&Blender, NewRect.Bottom-NewRect.Top);
		if (NewRect.Top < CurrentClipper.Top)
		{
			UpdateBlendTimes(&Blender,CurrentClipper.Top-NewRect.Top);
			Rect->Top = CurrentClipper.Top;
		}
		if (NewRect.Bottom > CurrentClipper.Bottom)
			NewRect.Bottom = CurrentClipper.Bottom;
		if (NewRect.Left < CurrentClipper.Left)
			NewRect.Left = CurrentClipper.Left;
		if (NewRect.Right > CurrentClipper.Right)
			NewRect.Right = CurrentClipper.Right;
		for (Ctr=NewRect.Top;Ctr!=Rect->Bottom;++Ctr)
		{
//			DrawHLine(Ctr,Rect->Left,Rect->Right,Blender.CurRed>>16,Blender.CurGreen>>16,Blender.CurBlue>>16);
			DrawHLine32(Ctr,Rect->Left,Rect->Right,Blender.CurRed>>16,Blender.CurGreen>>16,Blender.CurBlue>>16);
			UpdateBlend(&Blender);
		}
	}
	else if (Rect->Flags & GRAPH_FILL_HGRADIENT)	//Horizontal Gradient?
	{
		GenerateBlend(&Rect->Color1,&Rect->Color2,&Blender, Rect->Bottom-Rect->Top);
		if (Rect->Left < CurrentClipper.Left)
		{
			UpdateBlendTimes(&Blender,CurrentClipper.Left-Rect->Left);
			Rect->Left = CurrentClipper.Left;
		}
		if (Rect->Top < CurrentClipper.Top)
			Rect->Top = CurrentClipper.Top;
		if (Rect->Bottom > CurrentClipper.Bottom)
			Rect->Bottom = CurrentClipper.Bottom;
		if (Rect->Right > CurrentClipper.Right)
			Rect->Right = CurrentClipper.Right;
	}
	else	//Solid fill?!?!
	{
	}
}

/*** Our Init Function ***/

//We always know we start @ 800x600x32 :)
u32 Init(void)
{
	u32 Ctr;
	struct VESAMode_S	VESAMode, *ptrMode;
	u16 *ptrModeList;
//	Virtual2Physical(0x7000,0x7000);			//Memory map this page

	ptrCurrentVESAMode = (struct VESAMode_S*)0;

	InstallVesaBios();							//First copy the vesa bios functions
	MemCopy8(ptrVBEInfo->Signature,"VBE2",4);
	ptrVBEInfo->Version = 0x0200;				//Version 2.0 at least?
	VesaRegs->ax = 0x4f00;						//Get VBE Controller information
	CallVesaBios();

	if ((VesaRegs->ax & 0x4f) != 0x4f) //Didn't work?
	{
		kprint("VBE 2.0 not supported!\n");
		return 1;
	}

	VideoMem = ptrVBEInfo->TotalMemory;
	VideoMem*=65536;

	kprint("Found video memory: %dmb\n",VideoMem/1024/1024);

	Real2Linear(&ptrVBEInfo->VideoModePtr);
	Real2Linear(&ptrVBEInfo->OEMNamePtr);
	Real2Linear(&ptrVBEInfo->OEMString);
	Real2Linear(&ptrVBEInfo->OEMVendorPtr);
	Real2Linear(&ptrVBEInfo->OEMRevPtr);

	ptrModeList = (u16*)ptrVBEInfo->VideoModePtr;
	Ctr=0;
	while (ptrModeList[Ctr] != 0xffff)
	{
		VESAMode.Mode = ptrModeList[Ctr];
		DL_Add(&VESAModeList,&VESAMode);
		++Ctr;
	}

	Ctr=0;
	ptrMode = DL_GetFirst(&VESAModeList);
	while (ptrMode)
	{
		VesaRegs->ax = 0x4f01;								//Get VBE Mode Info
		VesaRegs->cx = ptrMode->Mode;						//Video mode to get info for
		MemCopy8(ptrVBEInfo->Signature,"VBE2",4);			//Set our signature
		CallVesaBios();										//Grab the info
		ptrMode->BasePtr = ptrVBEModeInfo->PhysBasePtr;		//Store our base pointer
		ptrMode->Width = ptrVBEModeInfo->XRes;				//Grab the horizontal resolution
		ptrMode->Height = ptrVBEModeInfo->YRes;				//Grab the vertical resolution
		ptrMode->BitDepth = ptrVBEModeInfo->BitsPerPixel;	//How many bits per pixel to use
		ptrMode->Attributes = ptrVBEModeInfo->ModeAttributes;
		ptrMode->RedPosition = ptrVBEModeInfo->RedFieldPosition;
		ptrMode->RedMaskSize = ptrVBEModeInfo->RedMaskSize;
		ptrMode->GreenPosition = ptrVBEModeInfo->GreenFieldPosition;
		ptrMode->GreenMaskSize = ptrVBEModeInfo->GreenMaskSize;
		ptrMode->BluePosition = ptrVBEModeInfo->BlueFieldPosition;
		ptrMode->BlueMaskSize = ptrVBEModeInfo->BlueMaskSize;
		ptrMode->ScanlineWidth = ptrVBEModeInfo->BytesPerScanLine;
		kprint("Mode(%d) 0x%x - %dx%dx%d, Phys: 0x%x, Attr: 0x%x, %d\n",Ctr,ptrMode->Mode,ptrMode->Width,ptrMode->Height,ptrMode->BitDepth,ptrMode->BasePtr,ptrMode->Attributes,ptrMode->ScanlineWidth);
		ptrMode = DL_GetNext(&VESAModeList);
		++Ctr;
	}

	SetMode(800,600,32);	//Testing

	for (Ctr=0;Ctr!=256;++Ctr)
		VESA_WriteByteE(Ctr,(Ctr&7)*8,(Ctr>>3)*8,0,0,255);

	for (Ctr=0;Ctr!=5;++Ctr)
		SleepTask();

	struct FillRect_S TestRect;
	TestRect.Left = 0;
	TestRect.Right = 500;
	TestRect.Top = 0;
	TestRect.Bottom = 100;
	TestRect.Color1.r = 32;
	TestRect.Color1.g = 64;
	TestRect.Color1.b = 255;

	TestRect.Color2.r = 128;
	TestRect.Color2.g = 128;
	TestRect.Color2.b = 255;
	TestRect.Flags = GRAPH_FILL_VGRADIENT;

	DrawRect(&TestRect);

//	SetTextMode();

	return 0;
}
Last edited by Ready4Dis on Mon Jun 30, 2008 1:49 am, edited 1 time in total.
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Back to real mode

Post by itisiuk »

Nice, thanks for that. i may not have to implement vm86 after all :D

however, i found a massive bug in my virt mem manager, it was just mappimg everything as physical address #-o carnt belive i missed that.
ive now decided todo another complete re-write cos itll be easyer that trying to fix the current code + then i can add a few other things i wanted anyway.
Post Reply