Thread: VDU memory

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    1

    VDU memory

    I am New to C programming . Please Someone Guide me how access VDU memory and well as VDU fundamentals

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    The name wasn't immediately familiar to me, but a quick google search brought up loads of funderful stuff; int86(), far pointers, CGA graphics...

    It's the 21st century; are you sure you want to mess with that junk?

    If so, give a better description of why you need to use archaic low level video functions.
    hello, internet!

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    It's the 21st century; are you sure you want to mess with that junk?
    I agree to some extend.

    But as you will look into this you will learn alot, i agree this is the 21st century...
    Its not because we have online newspapers we should forget about normal "physical paper" which we can hold tight, adore or trow away when they write crap...

    If you want a good reference and a great tutorial with source code included etc ( even for different compilers ) about VGA mode check out this site
    http://www.brackeen.com/home/vga/.

    For making cool OLD-looking console games these tutorials just rock .
    :::reminds me about Commander Keen series:::

    Greets,

    Ganglylamb.
    Last edited by GanglyLamb; 09-27-2004 at 09:51 AM.

  4. #4
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    For someone new to graphics programming, I don't see how this is anything but a dead end though. The only support of this stuff comes from archaic compilers running on archaic systems. Win2k+ emulate some of the dirty tricks involved, but all that is very iffy.

    In addition, IMO this is harder than learning modern graphics programming. I believe strongly in Allegro, a cross program graphics library. It supports a number of modern systems and modern hardware configurations, and is easy to learn. Drawing and graphics primitives are all documented in plain easy-to-understand english. There are also about eleventeen bazillion less wild pointers to take heed of.
    hello, internet!

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Direct acess to VDU memory is not allowed in later *nix nor windows NT, due to the protected memory mode. You'll have to use a high level API. Create a window and maximize it, and change the screen resolution. Or go back to old ms dos or win 95/98/me. You may use a dev environemt like DJGPP (gcc included). I've already worked with this package with the same purpose.
    Try this url for the toolkit:
    http://www.delorie.com/djgpp/

    some extras (using of course DJGPP):
    Code:
    #include <dpmi.h>
    #include <go32.h>
    #include <sys/nearptr.h>
    
    #define pixel(buf, x, y, color) ((buf)[(y)*1024+(x)]=(color))
    __dpmi_meminfo map;	//memory mapping
    
    unsigned long GetMapVideoMem(int mode){
        __dpmi_regs r;
        unsigned long dosbuf, address=0;    
        dosbuf = __tb & 0xFFFFF;
        dosmemput(&address, 4, dosbuf+40);    
        r.x.ax = 0x4F01;
        r.x.di = dosbuf & 0xF;
        r.x.es = (dosbuf>>4)& 0xFFFF;
        r.x.cx = mode;
        __dpmi_int(0x10, &r);    
        if(r.h.ah) return 0;    
        dosmemget(dosbuf+40, 4, &address);
        if(!address) return 0;    
        return address;
    }
    
    void *GetVideoMemPtr(int mode){
    	__djgpp_nearptr_enable();
    	map.address = GetMapVideoMem(mode);//0xDA000000;
    	if(!map.address) return 0;
    	map.size = resH*resV*1;
    	__dpmi_physical_address_mapping(&map);    
    	return (void *)(map.address + __djgpp_conventional_base);
    }
    
    void FreeVideoMemPtr(){
    	__dpmi_free_physical_address_mapping(&map);
    	__djgpp_nearptr_disable();
    }
    
    int ChangeVideoMode(int mode){
    	__dpmi_regs mode;
    	mode.x.ax = 0x4F02;
    	mode.x.bx = 0x4000 | mode;
    	return !__dpmi_int(0x10, &mode);
    }
    
    int RestoreVideoMode(){
    	__dpmi_regs mode;
    	mode.x.ax = 0x0003;    
    	return !__dpmi_int(0x10, &mode); 
    }
    
    void DrawRectangle(char *buf,int x1,int y1,int x2, int y2, char color){
    	int i,j, tmp;
    	
    	//avoid exchanged variables
    	if(x1>x2){tmp=x1;x1=x2;x2=tmp;}
    	if(y1>y2){tmp=y1;y1=y2;y2=tmp;}
    	
    	//draw the rectangle
    	for(i=x1;i<=x2; i++)
    		for(j=y1;j<=y2;j++)
    			pixel(buf,i,j,color);
    }
    
    int main(){
    	char *VDUmem;//8 bits per pixel
    	int mode = 0x0105;//0x105h (1024x768x8bit)
    
    	if(!ChangeVideoMode(mode)){
    		fprintf(stderr,"ERROR: graphics mode not changed.\n");
    		return 1;
    	}
    	VDUmem=(char*)GetVideoMemPtr(mode);
    	if(!VDUmem){
    		fprintf(stderr,"ERRO: video memory mapping failed.\n");
    		RestoreVideoMode();   
    		return 2;
    	}
    	DrawRectangle(VDUmem,0,0,1023,768,14);//yellow
    	DrawRectangle(VDUmem,200,200,823,568,12);//light red
    	DrawRectangle(VDUmem,400,300,623,468,2);//blue
    
    	getch();
    	FreeVideoMemPtr();
    	RestoreVideoMode();
    
    	return 0;
    }
    Comments: the above code display 2 rectangles, one on top of the other, in yellow background. This program is VBE compliant.

    unsigned long GetMapVideoMem(int mode);
    - Gets a linear adress for the screen buffer, starting at the upper-left pixel, to the lower-right
    char *GetVideoMemPtr(int mode);
    - Creates a physical memory map that adresses the linear buffer for the hardware
    void FreeVideoMemPtr();
    - release the physical memory map
    int ChangeVideoMode(int mode);
    - changes the current video mode to the one specified
    int RestoreVideoMode();
    - restores the video mode, to non-VBE compliant (or 80*25 character mode)
    void DrawRectangle(char *buf,int x1,int y1,int x2, int y2, char color);
    - like duh?!?

    Plus, the video modes info:
    http://www.geocities.com/SiliconVall...8933/vesa.html

    Have fun...

    [edit]
    I almost forgot the most important of all!
    http://www.vesa.org/
    [/edit]
    Last edited by xErath; 09-27-2004 at 06:41 PM.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Old OSes are still around, and are certainly fun to play with. But invest research into this type of programming only for educational purposes. Its not a marketable skill.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Suggestions on this C style code
    By Joelito in forum C Programming
    Replies: 11
    Last Post: 06-07-2007, 03:22 AM
  3. Relate memory allocation in struct->variable
    By Niara in forum C Programming
    Replies: 4
    Last Post: 03-23-2007, 03:06 PM
  4. Copying memory, pointers and the like.
    By psychopath in forum C++ Programming
    Replies: 34
    Last Post: 12-12-2006, 01:37 PM
  5. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 06:45 PM