From: "Patrick Smith" Newsgroups: comp.os.msdos.djgpp Subject: Re: Graphics under DJGPP V2.01 Date: 12 Dec 1996 20:01:10 GMT Organization: Traveling Software Lines: 123 Message-ID: <01bbe867$7fa64820$be7f10ac@ps.travsoft.com> References: <01bbe78f$57f16cc0$LocalHost AT default> NNTP-Posting-Host: t1.travsoft.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Thomas, Glad to see you are doing some graphics programming with DJGPP... Its pretty fun stuff, ya know. :) Anyways, lets see if I can help you out a little bit. For your first question about faster methods for moving data to video ram: It looks like you are aware of the selector you need to use to access dos memory, _dos_ds... that's good! Now if you want to do your own blitters, I'm afraid you need to use assembly. I'm sorry, I don't know any other way to use the selector in C to access dos memory. (Besides the built in functions like you were using) Basically, when you want to read/write to dos memory, you need to load the _dos_ds (data segment selector) into the es register. Then, to offset into that memory, you need to take the real mode segement, multiply it by 16 (or left shift by 4) and add the real mode offset. For VGA memory, the result would be 0xA0000. Notice there are 4 zeros instead of the 3 you are used to (that's 'cause I multiplied it (the segment) by 16). You need to move this offset value into the edi register (if you are writing to memory, if you are reading, use esi). Now if you need to offset furthur into VGA memory, just add the offset value to the edi register, for example, 0xA0140 (0xA0000 + 320) would reference the first pixel of the second scan line. Here's a quick and dirty function to write a pixel using DJGPP and VGA. short _iDosMem = _dos_ds; void PlotPixel (char chColor, short iXPos, short iYPos) { asm volatile (" push %%es push %%edi push %%eax movw _iDosMem, %%es movl $0xA0000, %%edi movw %2, %%ax imulw $320, %%ax addw %1, %%ax addw %%ax, %%di movb %0, %%al movb $0, %%ah stosb pop %%eax pop %%edi pop %%es " : // No Outputs : "g" (chColor), "g" (iXPos), "g" (iYPos) // Inputs ); return ; } You could easily expand this function to do whatever blitting you need, (transparent, RLE, whatever). I noticed that you are already using the seg*16+offset rule (0xA0000) -- thats great! I hope this example has helped a little bit... Now for your second question... How to set the VGA mode 13h? How 'bout this? void SetVGAMode (void) { __dpmi_regs tRegs; memset (&tRegs, 0, sizeof (tRegs)); tRegs.x.ax = 0x13; __dpmi_int(0x10, &tRegs); return; } To switch back to DOS 80x25 mode, just set the ax register to 0x03 instead of 0x13. :) I hope this helps... I'm certainly no expert in the area, but I believe everything I told you is correct. Happy Coding! Patrick Smith Traveling Software Thomas Harte wrote in article <01bbe78f$57f16cc0$LocalHost AT default>... > I am fairly new to this compiler, but so far I have liked everything I > have seen. My previous C compiler was a Borland DOS version, so I am very > new to protected mode. As such, I am having trouble with graphics. At the > minute (in DJGPP) I access the VGA board using the code :- > > for(temp=0;temp<64000;temp++) > { > _farpokeb(_dos_ds, 0xA0000 + temp, doublebuffer[temp]); > doublebuffer[temp]=background[temp]; > } > > which, as I'm sure you can imagine is VERY slow, in that it copies each > pixel individually. Anyway, my question is :- > > Which faster methods can I use to copy the contents of an integer into the > video ram, starting at 0xA0000 ? > > Also :- > > How would I switch graphic modes (to and from mode 13h) under DJGPP ? (at > the moment I have code from the old compiler which changes modes running > before and after the new programs in a batch file) > > Thanks, > > -Thomas >