{
    $Id$
    This file is part of the Free Pascal run time library.
    Copyright (c) 1993,97 by the Free Pascal development team.

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

procedure putpixel(x,y:integer;colour:longint);
var viewport:viewporttype;
begin
if aktviewport.clip then viewport:=aktviewport else viewport:=aktscreen;
  asm
      xorl   %eax,%eax
      movl   %eax,%ebx
      movw   x,%bx
      movw   y,%ax
      addw   _AKTVIEWPORT,%bx
      addw   _AKTVIEWPORT+2,%ax
      cmpw   viewport,%bx
      jl     p_exit                        // wenn x < x1 Ende
      cmpw   -8(%ebp),%bx
      jg     p_exit                        // wenn x > x2 Ende
      cmpw   -10(%ebp),%ax
      jl     p_exit                        // wenn y < y1 Ende
      cmpw   -6(%ebp),%ax
      jg     p_exit                        // wenn y > y2 Ende
      movl   _Y_ARRAY(,%eax,4),%eax
      addl   _X_ARRAY(,%ebx,4),%eax     
      movl   %eax,%esi
      movl   _WINSHIFT,%ecx                // { offset / winsize        }
      shrl   %cl,%eax                      // 
      cmpl   _AW_BANK,%eax                 // { same bank ?             }
      je     p_dont_switch                 // { yep                     } 
      movl   %eax,_AW_BANK                 // { newbank                 }
      pushl  %eax                          // 
      movl   _BANKSWITCHPTR,%eax           // { switchbank              }
      call   %eax                          //
  p_dont_switch:
      andl   _WINLOMASK,%esi
      movl   colour,%eax
      addl   _WBUFFER,%esi
      movw   _SEG_WRITE,%bx
      movw   _BYTESPERPIXEL,%cx
      movw   %ds,%dx
      movw   %bx,%ds
      testl  $1,%ecx
      jz     pp_2BPP
      movb   %al,(%esi)
      jnz    pp_exit
  pp_2BPP:
      movw   %ax,(%esi)
  pp_exit:
      movw   %dx,%ds
  p_exit:
  end; 
end; { proc }

procedure pixel(offset:longint);
 { wird nur intern aufgerufen, umrechnung auf Viewport und Range- }
 { checking muessen von aufrufender Routine bereits erledigt sein }
 { Bankswitching wird durchgefuehrt }  
 begin
   asm
      movl   offset,%eax             
      movl   %eax,%esi
      movl   _WINSHIFT,%ecx                // { offset / winsize        }
      shrl   %cl,%eax                      // 
      cmpl   _AW_BANK,%eax                 // { same bank ?             }
      je     dont_switch                   // { yep                     } 
      movl   %eax,_AW_BANK                 // { newbank                 }
      pushl  %eax                          // 
      movl   _BANKSWITCHPTR,%eax           // { switchbank              }
      call   %eax                          //
 dont_switch:
      movl   _WINLOMASK,%eax
      andl   %eax,%esi
      movl   _AKTCOLOR,%eax
      movzwl _AKTWRITEMODE,%ecx
      movw   _BYTESPERPIXEL,%bx
      addl   _WBUFFER,%esi
      movw   _SEG_WRITE,%dx
      movw   %ds,%di
      movw   %dx,%ds
      testl  %ecx,%ecx
      jz     dmove
      shrl   %ebx
      jnc    dxor2BPP
      xorb   %al,(%esi)
      jnc    pd_exit
 dxor2BPP:
      xorw   %ax,(%esi)
      jnc    pd_exit 
 dmove:      
      shrl   %ebx
      jnc    dmove2BPP
      movb   %al,(%esi)
      jc     pd_exit
 dmove2BPP:
      movw   %ax,(%esi)  
 pd_exit:
      movw   %di,%ds 
   end; 
end; { proc }

function getpixel(x,y:integer):longint;
var viewport:viewporttype;
begin
if aktviewport.clip then viewport:=aktviewport else viewport:=aktscreen;
  asm
      movswl x,%ebx
      movswl y,%eax
      addw   _AKTVIEWPORT,%bx
      addw   _AKTVIEWPORT+2,%ax
      cmpw   viewport,%bx
      jl     gp_exit                        // wenn x < x1 Ende
      cmpw   -8(%ebp),%bx
      jg     gp_exit                        // wenn x > x2 Ende
      cmpw   -10(%ebp),%ax
      jl     gp_exit                        // wenn y < y1 Ende
      cmpw   -6(%ebp),%ax
      jg     gp_exit                        // wenn y > y2 Ende
      movl   _Y_ARRAY(,%eax,4),%eax
      addl   _X_ARRAY(,%ebx,4),%eax     
      movl   %eax,%esi
      movl   _WINSHIFT,%ecx                // { offset / winsize        }
      shrl   %cl,%eax                      // 
      cmpl   _AW_BANK,%eax                 // { same bank ?             }
      je     g_dont_switch                 // { yep                     }
      pushl  %esi                          // { save Offset             }       
      movl   %eax,_AW_BANK                 // { newbank                 }
      pushl  %eax                          // 
      movl   _BANKSWITCHPTR,%eax           // { switchbank              }
      call   %eax                          //
      popl   %esi                          // { restore Offset          }
  g_dont_switch:
      movl   _WINLOMASK,%eax
      andl   %eax,%esi
      xorl   %eax,%eax
      movl   _BYTESPERPIXEL,%edx
      addl   _WBUFFER,%esi   
      movw   _SEG_WRITE,%bx
      movw   %ds,%cx
      movw   %bx,%ds   
      testl  $1,%edx                       // { 1 or 2 BytesPerPixel ? }
      jnz    g_8BPP
      movw   %ds:(%esi),%ax
      jnz    g_Result
  g_8BPP:    
      movb   %ds:(%esi),%al
  g_Result:    
      movw   %cx,%ds
      movl   %eax,__RESULT 
  gp_exit:
  end;
end; { proc }


{
  $Log$
  Revision 1.1  1998-03-25 11:18:42  root
  Initial revision

  Revision 1.3  1998/01/26 11:58:33  michael
  + Added log at the end


  
  Working file: rtl/dos/ppi/pixel.ppi
  description:
  ----------------------------
  revision 1.2
  date: 1997/12/01 12:21:32;  author: michael;  state: Exp;  lines: +13 -1
  + added copyright reference in header.
  ----------------------------
  revision 1.1
  date: 1997/11/27 08:33:51;  author: michael;  state: Exp;
  Initial revision
  ----------------------------
  revision 1.1.1.1
  date: 1997/11/27 08:33:51;  author: michael;  state: Exp;  lines: +0 -0
  FPC RTL CVS start
  =============================================================================
}
