🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #60

Code for loading directly into VGA mem

#60
From: Corey D. Stinson
Date: Sun, 01 Nov 1992 19:13
63 lines
2363 bytes
Recently someone posted the code below in answer to someone's questoin
concerning loading directly into the VGA memory buffer.  The coder
mentioned that he/she was using Microsoft C.  Neither of the examples
below will work for me (I'm using Turbo/Borland C++) and I wonder if
someone might have some suggestions which would allow this to work
correctly under my compiler:



Why this doesn't work:

    unsigned char (far *VideoMemory)[200][320];
    VideoMemory=(unsigned char (far *)[200][320])0xA0000000L;
    for (x=0;x<=15;x++ )
	for (y=0;y<=15;y++)
	    VideoMemory[y][x]=pic[x][y];
   **** LValue required error on above line ****

    unsigned char (far *VideoMemory)[200][320];
    VideoMemory=(unsigned char (far *)[200][320])0xA0000000L;
    for (x=0;x<=15;x++ )
	for (y=0;y<=15;y++)
	    VideoMemory[y][x]=pic[x][y];

    -A good compiler should be able to optimize this pretty good.

    OR, using Microsoft C inline assembler, a very fast version:


Why this doesn't work:

   void PUTBLT( int x, int y, int width, int height, char far * buffer )
   {
   _asm   {
   push   es
   push   ds 
   mov    ax, A000h   ; The segment of VGA memory
   mov    es, ax
   mov    ax, 320
   mul    y
   add    ax, height  ; AX = y*320+x
   mov    di, ax      ; The offset into VGA memory
   mov    dx, width   ; USe DX for width
   mov    bx, height  ; Use BX for height 
   lds    si, buffer  ; Point DS:SI to the memory
   rowloop:
   mov    cx, dx      ; Number of pixels to fill per row
   rep    movsb       ; blast 'em out there
   dec    bx
   jnz    rowloop 

*** it's not recognizing the label I designated previously.  A friend
    tells me it is illegal to create labels in inline assembler but
    I would think there would be a way to do it.
 **
   pop    ds
   pop    es
    
    -This is assuming you're using mode 13h.
    -This just writes directly to video memory.

Any help or advice would be GREATLY appreciated! :)
Technical Details
Message-ID: <Bx1xF3.31B@uxa.ecn.bgu.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!newsflash.concordia.ca!garrot.DMI.USherb.CA!uxa.ecn.bgu.edu!mucds

Show Full Headers
Complete Article Headers
Newsgroups: rec.games.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!newsflash.concordia.ca!garrot.DMI.USherb.CA!uxa.ecn.bgu.edu!mucds
From: mucds@uxa.ecn.bgu.edu (Corey D. Stinson)
Subject: Code for loading directly into VGA mem
Message-ID: <Bx1xF3.31B@uxa.ecn.bgu.edu>
Organization: Educational Computing Network
Date: Sun, 1 Nov 1992 19:13:51 GMT
Lines: 63