Page 1 of 1

To use BGI or not to use BGI

Posted: Fri Nov 03, 2006 9:37 am
by inflater
Hi,
well, I decided to "hardcode" my first GUI for OS without any tutorials - starting position :D is a simple graphic mode 640x480 with 16 colors. Fine.

I've created a simple window with simple text. I've linked this little OS expletive to my OS myself. Worked - in Windows. Fine again.

But, I tried to execute GUI in QEMU. No such Windows/DOS kernel inside virtual machine; only PortixOS kernel (that's name of my OS :D :D) and it won't work. It just displayed this:

BGI Error: Graphics not initialized (use InitGraph)

and I used correctly Initgraph and other stuff - that is because it worked under Win kernel. QEMU was set to use Cirrus Logic VGA card. Also, i tried to use Virtual PC - same result.

I used other architecture to prepare graphic mode:
- I used BINOBJ to convert EGAVGA.BGI to EGAVGA.OBJ.
- I followed the tutes how to link EGAVGA.OBJ directly to EXE - the kernel
of my OS.
- In Windows it worked perfectly.

I think that loading the BGI driver requires some memory operations - a memory handler. I dunno why BGI needs memory... But i DO have memory managment, simpler, but I think good:

Function MemRB (Offset : LongInt) : Byte; External;
Procedure MemWB (Offset : LongInt; Value : Byte); External;


Offset can be any number until 4GB memory limit (this is mem managment from A.Frounze - see below).
MemRB stands for "Memory Read Byte" and
MemWB stands for "Memory Write Byte".
I have also functions like MemRW ("Memory Read WORD") and so on.

Finally :D - How can I reserve memory for BGI driver load?
Or the memory is not the main problem?

Thank you and big regards to all! (for very long reading... :D)

A.Frounze's mem managment:
It creates under Protected Mode a 4GB segment, returns back to real mode and programmer can use all system memory - well, to 4GB.

OFF-TOPIC:
aaaargh, today's visit in surgery was very painful... i can feel it now as well...
A rip of your toe-nail with doctor tongs is very disgusting...

inflater

Posted: Fri Nov 03, 2006 10:16 am
by xsix
Ah. BGI uses BIOS interrupts and video services, that's why it doesn't work. you need to write your own, low level VGA/SVGA code or use VESA.

Posted: Fri Nov 03, 2006 10:23 am
by inflater
Again, i am programming REAL MODE - BIOS interrupts are free, not protected mode, where it is all different. Sorry, my mistake.

inflater

Posted: Fri Nov 03, 2006 10:28 am
by bubach
It might use some DOS intterupt thats not present in your OS. I don't think BGI is a good idea anyway. Try writing your own graphic routines.

Posted: Fri Nov 03, 2006 10:31 am
by inflater
I have been worried for this... that i must write my own GUI functions...
Really.. Can't i use some universal method to fire up BGIs non DOS environment?... :cry:

inflater

Posted: Fri Nov 03, 2006 11:30 am
by Dex
You need to search swag for graphics for vesa or that does not use BGI
see here: http://www.bsdg.org/SWAG/index.html

here a examples:
http://www.bsdg.org/SWAG/EGAVGA/0134.PAS.html

Heres graphics index:
http://www.bsdg.org/SWAG/EGAVGA/0277.PAS.html

Posted: Sat Nov 04, 2006 2:55 am
by inflater
Thanx! I've constructed a new procedures to make a simple window :D
BUT - how can write a text to it? I cant use console functions!
In BGI it would be simple - OutText...

//EDIT: And, how can I display standard 16 color bitmap (BMP) to screen? I used Bin2PAS to make "array of byte" out of the bitmap and i linked this file to my OS (attachment).

inflater

Posted: Sat Nov 04, 2006 8:40 am
by Dex
Theres stuff for fonts in here: http://www.bsdg.org/SWAG/EGAVGA/0233.PAS.html
There should be a bmp display some where in the index.

Posted: Sat Nov 04, 2006 8:34 pm
by carbonBased
If you'd like to make use of your BGI fonts, I have code that will display them to the screen.

If you check out my graphics library petal at http://neuraldk.org/product-Petal, there's a file called font.cc which contains font rendering code for BGI fonts.

Keep in mind this code is anchient and unsupported. The DOS code is more likely to continue to work -- DOS never changes :) The Linux code, however, I'd be surprised if it still works -- linux has changed a lot since I wrote that code. The font code is the same across platforms, of course, but if you want to see it in action, I suggest finding a DOS box, or emulating one.

Also, as I said, this code is ancient -- and partially embarrassing... the coding style is pretty bad. But... it works.

--Jeff

Posted: Sun Nov 05, 2006 7:29 am
by inflater
WOW :shock: It is a bit more complicated... For me it can take a three months to understand and convert it to Pascal :shock: I didn't knew that BGI fonts are such a bitter coffee... :o

inflater

Posted: Mon Nov 06, 2006 7:16 pm
by carbonBased
inflater wrote:WOW :shock: It is a bit more complicated... For me it can take a three months to understand and convert it to Pascal :shock: I didn't knew that BGI fonts are such a bitter coffee... :o
You should try true type fonts. The borland stroked fonts are relatively easy, by comparison.

Effectively, the borland stroked font consists of two byte pairs. The high order bit of each pair is combined to make an opcode which describes the action. The rest of the bytes are interpreted as a coordinate (x,y).

Generally, there are only two opcodes used -- moveto, and lineto. An opcode of 0 ends the character definition. There's another opcode called "do scan"... I don't know what this is supposed to be, but I've never had an issue with ignoring it.

All my code does is read these in and act upon them. I also perform rudimentary scaling via the numerator and denominator variables. Bolding is available through the use of thicker lines. Italics could be performed by skewing the x variable based on the current y variable local to that character (although I don't do this).

Trust me, it's easier then it looks. I banged that code off in a couple hours... unfortunately, I neglected to link to the document I was using that described the format. I believe this might have been it http://www.wotsit.org/download.asp?f=chr

If you have any questions, let me know... I wrote this years ago, but I still vaguely remember it.

--Jeff