Board index » delphi » Q: BP7+ASM

Q: BP7+ASM

{
 Hi ASM gurus
 I want draw a Gouraud-shaded horizontal line.
 But there is a little problem in this procedure,
 if C2 is greater 127 (see example output).
 Please can you tell me what's wrong ?
 Do you know a correct solution ?
 THANX a lot   ;-) Gerd
Quote
}

uses crt;

const segPage: word=$A000;

{c1: color index of 1.pixel
 c2: color index if last pixel}
procedure _GouraudHLineAsm (x1,x2, y, c1,c2: word); Assembler;

asm
  mov  cx,X2
  inc  cx
  sub  cx,X1       {cx = (X2-X1+1)}
  jle @fin         {if x2+1 <= x1 goto fin}
  mov  ax,Y
  shl  ax,6
  mov  bx,ax
  shl  ax,2
  add  bx,ax
  add  bx,X1
  mov  di,bx       {di = Y*320+X1}
  mov  es,segPage  {es = seg(page256^)}
  mov  bx,C1
  mov  ax,C2
  sub  ax,bx
  shl  ax,8        {ax = (C2-C1) shl 8}
  cwd
  idiv cx          {ax = ax/cx}
  shl  bx,8        {bx = C1 shl 8}
  shr  cx,1        {cx = cx/2}
  jnz @next        {if cx <> 0 goto next}
  mov  es:[di],bh
  jmp @fin
 @next:
  jnc @loop
  mov  es:[di],bh
  add  bx,ax       {bx += ax}
  inc  di
 @loop:
  mov  dl,bh       {dl = bh}
  add  bx,ax       {bx += ax}
  mov  dh,bh       {dh = bh}
  add  bx,ax       {bx += ax}
  mov  es:[di],dx
  inc  di
  inc  di
  dec  cx
  jnz @loop
 @fin:
end;

var   y: integer;
begin
  asm mov ax,19;int 16; end;
  for y := 0 to 199
  do _GouraudHLineAsm (y div 3, 319-(y div 3), y, 17,56+y);
  readkey;
  TextMode(3);
end.

 

Re:Q: BP7+ASM


On Wed, 16 Sep 1998 20:52:27 GMT, antispam.pl...@siemens.at (Gerd)
wrote:

Quote
>{
>  Hi ASM gurus

[snip]

Quote
>  sub  ax,bx

replace the lines

Quote
>  shl  ax,8        {ax = (C2-C1) shl 8}
>  cwd
>  idiv cx          {ax = ax/cx}

with
  sub dh,dh
  mov dl,ah
  shl ax,8
  idiv cx

Quote
>  shl  bx,8        {bx = C1 shl 8}

[snip]

Hope this helps

Wolfgang

Other Threads