Board index » delphi » Transparent PutImage 386+ -- freebee

Transparent PutImage 386+ -- freebee

Hello all:  I had time to prepare another procedure you you guys to
consume for your knowledge.  It is a mode 13h version of a transparent
putimage which is pretty well optimized.  Here you go, enjoy!

{$DEFINE PUTIMAGE2}
{$IFNDEF PUTIMAGE} {$I PUTIMAGE} {$ENDIF}

Procedure PutImage2(X1,Y1:Word; Var IMG); Assembler;
  { X1,X2 = Position to place IMG                    }
  { IMG = Buffer to a standard formatted image       }
  { Note: Image is transparent with zero values      }
  { Revision History:                                }
  {   05-06-95 Pascal Prototype by Steven J Morales! }
  {   09-24-95 (SJM)  Converted to Assembler!        }
Var
  CX1 : Word;        { Holders for precalculations   }
ASM
  { Instructions:  Clocks: Comments:                 }
  PUSH DS;           { 11: DS Must be preserved!     }

  LDS SI, IMG;       { 16: DS:SI = Image Buffer      }
  MOV AX, $A000;     { 04: A000:00 = Video Buffer     }
  MOV ES, AX;        { 02: Can't "MOV ES, Immediate" }

  LODSW;             { 12: Get Width in AX           }

  MOV CX1, AX;        { 10: Set Counter to IMG width  }

  MOV DX, 320;       { 04: Width of full screen ..   }
  SUB DX, AX;        { 03: .. SUB width of IMG in DX }

  LODSW;             { 12: Get Height in AX          }
  MOV BX, AX;        { 10: Get Height from IMG       }

  MOV AX, Y1;        { 04: MOV Y1 into AX for SHLing }
  MOV CX, AX;        { 03: Store a second copy in BX }
  SHL AX, 6;         { 04: ** AX := (Y1*320)+X1   ** }
  SHL CX, 8;         { 04: ** without using MUL   ** }
  ADD AX, CX;        { 03: ** by using shifts     ** }
  ADD AX, X1;        { 09: ** and adding.         ** }

  MOV DI, AX;        { 02: DI to start position      }
@LOOP1:              { --: Loop here after each line }
  MOV CX, CX1;       { 08: Number of BYTEs restored  }
@LOOP2:              { --: Loop here after each byte }
  LODSB;             { 12: Get BYTE from IMAGE       }
  CMP Al, 0;         { 04: Is it a zero?             }
  JE @SKIP;          { 16: If so, SKIP it!           }
  STOSB;             { 11: else STOS it!             }
  LOOP @LOOP2;       { 17: Next Byte?                }
  JMP @DONE;         { 15: else done with line...    }
@SKIP:               { --: Come here to skip BYTE    }
  INC DI;            { 03: INC Destination pointer   }
  LOOP @LOOP2;       { 17: Next Byte or DONE?        }
@DONE:               { --: Done with line...         }
  ADD DI, DX;        { 03: Update index to next line }
  DEC BX;            { 03: Decrement height counter  }
  JNZ @LOOP1;        { 16: Start the line Loop       }
  POP DS;            { 08: DS Must be preserved!     }

  { Clocks Based on Intel 8086/8088 Instruction Set! }

END;

Rottweiler/Steven Morales

 

Re:Transparent PutImage 386+ -- freebee


In article <49mbqi$...@polaris.unm.edu>,
NewOrder Demo Group <newor...@unm.edu> wrote:
[snip]
Quote
>    sub     bx,ax
>    add     di,x1
>    mov     ax,ds:[si]    ;{width}
>    mov     dx,ds:[si+2]  ;{height}

[snip]
That should be:
        add     di,x1
        mov     ax,ds:[si]    ;{width}
        mov     dx,ds:[si+2]  ;{height}
        sub     bx,ax

Sorry. :)

--TCA of NewOrder  /  newor...@argo.unm.edu  /  http://www.nmt.edu/~surface

Re:Transparent PutImage 386+ -- freebee


In article <Pine.LNX.3.91.951129195407.11450E-100...@peterlaz.dh.i-2000.com>,

Quote
morale46  <moral...@peterlaz.dh.i-2000.com> wrote:
>Hello all:  I had time to prepare another procedure you you guys to
>consume for your knowledge.  It is a mode 13h version of a transparent
>putimage which is pretty well optimized.  Here you go, enjoy!

Oh, dear lord!  Here is a slightly *more* optimized version.

Quote
>{$DEFINE PUTIMAGE2}
>{$IFNDEF PUTIMAGE} {$I PUTIMAGE} {$ENDIF}

>Procedure PutImage2(X1,Y1:Word; Var IMG); Assembler;
>  { X1,Y1 = Position to place IMG                    }
>  { IMG = Buffer to a standard formatted image       }
>  { Note: Image is transparent with zero values      }
>  { Revision History:                                }
>  {   05-06-95 Pascal Prototype by Steven J Morales! }
>  {   09-24-95 (SJM)  Converted to Assembler!        }

asm
        push    ds
        mov     es,Sega000
        lds     si,Img
        mov     ax,y1
        mov     di,ax
        shl     ax,8
        shl     di,6
        mov     bx,320       ;Interleave so the pentium can fill both pipes}
        add     di,ax
        sub     bx,ax
        add     di,x1
        mov     ax,ds:[si]    ;{width}
        mov     dx,ds:[si+2]  ;{height}
        add     si,4
@lop1:  mov     cx,ax
@lop2:  mov     al,ds:[si]
        test    al,al     ;{this method is occasionally faster on the pentium}
        jz      @nop
        mov     es:[di],al    ;{draw the pixel}
@nop:   inc     si
        inc     di
        dec     cx
        jnz     @lop2
        add     di,bx
        dec     dx
        jnz     @lop1
        pop     ds
end;

Of course, there is a *much* faster way of drawing sprites transparently that
doesn't require any compares and can move data Dwords at a time if possible.
However, it requires that you convert all your bitmaps into another format.
(Btw, the above hasn't been checked, but I looked it over 3 times and it
looks okay.  However, I'm sure Joshua will mention any mistakes I've made :).

Quote
>Rottweiler/Steven Morales

--TCA of NewOrder  /  newor...@argo.unm.edu  /  http://www.nmt.edu/~surface
Programmer for Stranger Than Fiction Games, Inc.
Project WallyWorld Quote:  "His hair looks like Jello."  "Just wait until
you see the bullets bounce off it."

Re:Transparent PutImage 386+ -- freebee


On 1 Dec 1995, NewOrder Demo Group wrote:

Quote
>    test    al,al     ;{this method is occasionally faster on the pentium}
>    jz      @nop

In this case I generally use or al, al myself... although this is solely
a matter of opinion (oth 1 clock-cycle on 486 and 2 bytes large, seeing
as how  test is really AND :)

Quote
> Of course, there is a *much* faster way of drawing sprites transparently that
> doesn't require any compares and can move data Dwords at a time if possible.
> However, it requires that you convert all your bitmaps into another format.
> (Btw, the above hasn't been checked, but I looked it over 3 times and it
> looks okay.  However, I'm sure Joshua will mention any mistakes I've made :).

Only problem I could see was a difference in opinion. :)  And When you
said "*much* faster way...doesn't require any compares..." I knew
immediately what you were talking about (so, is there an NDA on this
technique yet? :)

Quote
> --TCA of NewOrder  /  newor...@argo.unm.edu  /  http://www.nmt.edu/~surface
> Programmer for Stranger Than Fiction Games, Inc.
> Project WallyWorld Quote:  "His hair looks like Jello."  "Just wait until
> you see the bullets bounce off it."

Now I *really* want to see the latest internal beta! :)

    ________________________________________________________________________
   / Joshua Shagam                    /    (Quantum Porcupine / Versatile) /
  / mailto:JSha...@nmsu.edu          /       http://web.nmsu.edu/~jshagam /
 / phone://1.505.645.3856/~joshua   /  for the Quantum Porcupine Archive /
/__________________________________/____________________________________/
 Stop the execution of King Louis XIV!  If you agr-- oops, too late! :)

Other Threads