FAST putpixel? 
Author Message
 FAST putpixel?

Does anybody have a REALLY fast putpixel procedure ?
The fastest i know of is the mem[$a000h.....]. Is there any faster (probably) ?


Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?

Quote:
> Does anybody have a REALLY fast putpixel procedure ?
> The fastest i know of is the mem[$a000h.....]. Is there any faster
> (probably) ?

For video mode 13h (320x200x256), here's a fast one:

procedure PutPixel(posX, posY: integer; Color: byte); assembler;
asm
        mov     ax, 320
        mul     posY
        add     posX
        mov     di, 0A000h
        xchg    ax, di
        mov     es, ax
        mov     al, Color
        stosb
end;

Stephan

-------------------------------------------------------------------------

       <<< Bug is a registered trademark of Microsoft Corp. >>>
-------------------------------------------------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?
On 7 Jan 1996 01:55:00 GMT,

Quote:
>Does anybody have a REALLY fast putpixel procedure ?
>The fastest i know of is the mem[$a000h.....]. Is there any faster (probably) ?

The fastest putpixels are written in assembler and make use of some
extra knowledge and set several pixels at once.  If you're drawing a
line or filling a polygon, it is a big timesaver to set 8 or 16 bits
at a time.  You also avoid having to do 8 to 16 address calculations
and segment register loads.

-----------------------------------------------------------------------
George R. Gonzalez                        Programmer / Grumbler



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?


Quote:

>> Does anybody have a REALLY fast putpixel procedure ?

>For video mode 13h (320x200x256), here's a fast one:
>procedure PutPixel(posX, posY: integer; Color: byte); assembler;
>asm
>        mov     ax, 320
>        mul     posY
>        add     posX
>        mov     di, 0A000h
>        xchg    ax, di
>        mov     es, ax
>        mov     al, Color
>        stosb
>end;

The above won't compile, and I have to say is somewhat weird.

Here is a very fast putpixel routine.

procedure PutPixel(x,y:word; color:byte); assembler;
asm
        mov     es,sega000
        db 66h; xor ax,ax
        db 66h; xor bx,bx
        mov     ax,x
        mov     bx,y
        mov     cl,color
        shl     bx,6
        db 26h, 67h, 88h, 0ch, 98h  ;{mov es:[eax+ebx*4],cl}
end;


Programmer for Stranger Than Fiction Games, Inc.
Project WallyWorld Quote:  "Sure, Jazz had [what looked like] texture mapped
floors, but did they have texture mapped spheres!?  Mwahahahaha."



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?

Quote:

>Does anybody have a REALLY fast putpixel procedure ?
>The fastest i know of is the mem[$a000h.....]. Is there any faster (probably)?

Well, assembler is a little bit faster. Try this.

VAR bytesperline:Word;   { Set to 320 if 320x200x256 mode, ofcourse }

PROCEDURE putpixel(x,y:Word; color:Byte);
BEGIN
 MOV AX,y
 MUL bytesperline        { Hope this works, haven't tried it myself }
 ADD AX,x
 MOV BX,AX
 MOV AX,$A000
 MOV ES,AX
 MOV AL,color
 MOV [ES:BX],AL
END;



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?

Quote:
>Here is a very fast putpixel routine.

>procedure PutPixel(x,y:word; color:byte); assembler;
>asm
>    mov     es,sega000
>    db 66h; xor ax,ax
>    db 66h; xor bx,bx
>    mov     ax,x
>    mov     bx,y
>    mov     cl,color
>    shl     bx,6
>    db 26h, 67h, 88h, 0ch, 98h  ;{mov es:[eax+ebx*4],cl}
>end;

Nice routine...
On a somewhat related note: You're using db's to use 386 instructions
that TP's built-in assembler doesn't know. Since I would like to do the
same: Do you know where I can get a list of all 80386 instructions and
their op-codes?
TIA,

 __________________________________________________________________________
| Mario van den Ancker             \  Hey, you didn't expect any of these  |
| Amsterdam, The Netherlands.       \  views to be shared by anyone but    |  

| WWW: http://www.astro.uva.nl/mario/ \                                    |    
|______________________________________\___________________________________|



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?
Quote:
>The fastest putpixels are written in assembler and make use of some
>extra knowledge and set several pixels at once.  If you're drawing a
>line or filling a polygon, it is a big timesaver to set 8 or 16 bits
>at a time.  You also avoid having to do 8 to 16 address calculations
>and segment register loads.

Yep, also for a putpixel, it takes more time entering and leaving the
procedure than the actual putpixel. Such (small) routines should be
inline code. Too bad Pascal has no macros.
Replacing every
 putpixel(x,y,c)
with
 mem[$A000:x + (y shl 6) + (y shl 8)] := c
in your main body is almost the fastest you can get

Herman



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?

Quote:



> >> Does anybody have a REALLY fast putpixel procedure ?

> >For video mode 13h (320x200x256), here's a fast one:
> >procedure PutPixel(posX, posY: integer; Color: byte); assembler;
> >asm
> >        mov     ax, 320
> >        mul     posY
> >        add     posX

           ^^^^^^^^^^^^

Quote:
> >        mov     di, 0A000h
> >        xchg    ax, di
> >        mov     es, ax
> >        mov     al, Color
> >        stosb
> >end;

> The above won't compile, and I have to say is somewhat weird.

The underlined line should be
        add     ax, posX

Seems that I was a "little bit" ;-) tired when reading my mails/news
last time....

Stephan

-------------------------------------------------------------------------

       <<< Bug is a registered trademark of Microsoft Corp. >>>
-------------------------------------------------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?

Quote:
>I wrote a test program, and found that this and one other assembly
>PutPixel routine are indeed 4-5X faster than the standard Borland
>routine.  Cool!

>HOWEVER...I've tried integrating this and one other assembly PutPixel
>into a program I wrote that uses the BGI256 SVGA drivers(at 800x600
>resolution and in protected mode).  I'm having trouble.  Subsequent
>lines of the "image" I am placing, pixel by pixel, are getting
>scrambled, sorta like this...

>xxxxxxxxxxxxxx
>                        xxxxxxxxxxxxxxxx    
>                                                 xxxxxxxxxxxxxx
>xxxxxxxxxxxxxx          
>                        xxxxxxxxxxxxxxxx
>                                                 xxxxxxxxxxxxxx

>... etc.  Any ideas?  I'd KILL for a faster PutPixel! ...or maybe send
>you a beer.  8)

>Thanks!   - Bill Guilford

     Those PutPixel routines posted earlier were for VGA, (320x200x256),
resolution and less.  If you want to program in SVGA, (e.g. 800x600), the
procedure is slightly different.
     With SVGA, you can only access 64k of the screen at once, (which just
happens to be 320x200 = 64000).  This means that for SVGA programming you will
have to do something called bank switching, to allow you to use any more than
the first 100 lines or so of your screen in SVGA modes.
     As well, the distortion, (I'm not positive, since I didn't see the code),
is probably due to the fact that the assembly procedures were designed for a
VGA screen, (320x200), and are therefore not designed for an 800 pixel-long
line.
     The bank switching and SVGA/VGA putpixel routines can be found in the
SWAG archives, at ftp://garbo.uwasa.fi/pc/turbopas/swag*.zip, or in any of the
`SimTel' mirrors.

                 Hope this Helps!

                                               Jeff Wentworth



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?

Quote:


>: Does anybody have a REALLY fast putpixel procedure ?
>: The fastest i know of is the mem[$a000h.....]. Is there any faster (probably) ?
>Procedure putpixel(x,y:word;c:byte);assembler;
>asm
>   mov  cx,x
>   mov  dx,y
>   mov  ah,$0c
>   mov  al,c
>   int  $10
>end;

I'm sorry, but a putpixel using interrupts is NOT fast... :)

there are at least two good ways to do a mode 13 putpixel in Pascal.
Here are my two:

procedure PutPixel1(X, Y: word; Color: byte);  assembler;
asm
  mov ax, 0a000h
  mov es, ax
  mov bx, y
  mov ax, bx
  shl   ax, 6
  shl   bx, 8
  add bx, ax    {bx has y * 320}
  add bx, x     {bx has offset}
  mov al, Color
  mov es:[bx], al
end;

-----OR-------
{this is done once ahead of time}
var
  Count:        word;
  LookupTable = array[0..199] of word;

begin
  for Count := 0 to 199
     do LookUpTable[Count] := Count * 320;  
end

procedure  PutPixel2(X, Y: word; Color: byte);
begin
  mov ax, 0a000h
  mov es, ax
  mov bx, Y
  shl bx, 1                     {bx has offset in LookupTable of Y*320}
  mov bx, ds:[LookUpTable+bx]    {bx has Y*320}
  add bx, x                     {bx has offset}
  mov al, Color
  mov es:[bx], al
end;

Note that I'm not naive enough to claim that these are the only fast
ways to do it.  These are just the fastest that I've been able to come
up with in Pascal, and both are faster than an interrupt putpixel.

Chris



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?

: Does anybody have a REALLY fast putpixel procedure ?
: The fastest i know of is the mem[$a000h.....]. Is there any faster (probably) ?

Procedure putpixel(x,y:word;c:byte);assembler;
asm
   mov  cx,x
   mov  dx,y
   mov  ah,$0c
   mov  al,c
   int  $10
end;

That's always worked for me. x & y are the coordinates, and c is the
color.



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?

under Topic "FAST putpixel?":

Quote:
> Does anybody have a REALLY fast putpixel procedure ?
> The fastest i know of is the mem[$a000h.....]. Is there any faster
> (probably) ?

This is the fastest one (without lookup tables) i know :

procedure putpixel(x,y : word; color : byte);assembler;
     asm
        mov ax,$a000
        mov es,ax
        mov ax,word ptr y
        mov di,ax
        shl ax,8
        shl di,6
        add di,ax
        add di,word ptr x
        mov al,byte ptr color
        mov es:[di],al
     end;

This putpixel-Routine is of course for the simple mode $13 ...
               (320x200x256)

I hope that helps you a little bit :-)

########################################################
##                                                    ##

##                                                    ##
#################################################-TI95-#
## CrossPoint v3.1 ##



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?

Quote:


>>>Here is a very fast putpixel routine.

>>>procedure PutPixel(x,y:word; color:byte); assembler;
>...

>>Nice routine...
>...

>I wrote a test program, and found that this and one other assembly
>PutPixel routine are indeed 4-5X faster than the standard Borland
>routine.  Cool!

>HOWEVER...I've tried integrating this and one other assembly PutPixel
>into a program I wrote that uses the BGI256 SVGA drivers(at 800x600
>resolution and in protected mode).  I'm having trouble.  Subsequent
>lines of the "image" I am placing, pixel by pixel, are getting
>scrambled, sorta like this...

Well, yes, you are forgetting that a 800x600x256color image simply doesn't
fit into a single 64k segment (the $A000 segment, referred to in BP7 DPMI as
SegA000). What you should do is add a bank switching routine to your PutPixel
procedure. This can be tricky because different SVGA chipset perform bank
switching in all sorts of diferent ways. So, you should either a) write a dedicated
routine for your specific chipset, or b) include code for all SVGA chipsets you
wish to support, or c) use VESA BIOS calls to perform bank switching. In the latter
case, of course, your program will only run on SVGA's with a VESA compatible BIOS, or,
alternatively, the user of your program first has to load a TSR (supplied by the card
manufacturer or available from e.g. SimTel and Garbo) which supplies the VESA extensions.

For technical details on virtually all SVGA chipsets in existence, as well as the VESA
BIOS interface, and source code in Borland Pascal, you should get a file named VGADOC4B.ZIP
available from SimTel and others. If you don't know where to find it, search using:
http://www.pvv.unit.no/ftpsearch

Haye van den Oever



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?
Quote:
>> >> Does anybody have a REALLY fast putpixel procedure ?

FASTEST putpixel for 13h:
procedure PutPixel(x,y : word; col : byte); Assembler;
asm
  mov ax, A000h
  mov es, ax
  mov ax, y
  mov di, ax
  shl di, 6
  shl ax, 8
  add di, ax
  add di, x
  mov al, col
  mov [es:di],al
end;

GD



Wed, 18 Jun 1902 08:00:00 GMT  
 FAST putpixel?
Quote:

>>> >> Does anybody have a REALLY fast putpixel procedure ?

>FASTEST putpixel for 13h:
 ^^^^^^^ NOT
>procedure PutPixel(x,y : word; col : byte); Assembler;
>asm
>  mov ax, A000h
>  mov es, ax
>  mov ax, y

{ Here starts the slow section }
Quote:
>  mov di, ax
>  shl di, 6
>  shl ax, 8
>  add di, ax
>  add di, x

{ The slow section ends here }

Quote:
>  mov al, col
>  mov [es:di],al
>end;

Var Scr_Ofs : Array[0..199] of Word;

Procedure Putpixel (X,Y : Integer; Col : Byte; where:word); assembler;
{ This puts a pixel on the screen by writing directly to memory. }
{ Progamming by Antti Brax (n50) }
asm
   mov  es,[where]
   mov  bx,[y]
   add  bx,bx
   mov  di,[x]
   add  di,[OFFSET scr_ofs+bx]
   mov  al,[col]
   mov  es:[di],al
end;

Procedure MakeLut;
Var Counter : Word;
Begin
  For Counter := 0 to 199 do
    Scr_Ofs[Counter] := Counter * 320;
End;

Naturally you must make the lookup table before trying to put any pixels,
but as this is executed only when the program is run, it doesn't matter.

--

 Computer science, not a damn architect



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 21 post ]  Go to page: [1] [2]

 Relevant Pages 

1. I need a fast putpixel for 640x480x16 !

2. I need FAST putpixel and bar routines

3. Looking for a FAST putpixel (mode 13h)

4. fastest putpixel

5. Fast Putpixel (AGAIN??!!)

6. Fast Putpixel

7. Need fast putpixel-sequence for TP

8. Need fast putpixel-sequence for TP

9. FAST putpixel?

10. Need help on a fast putpixel for 640x480x256

 

 
Powered by phpBB® Forum Software