1  /********************************************************************** <BR>


2  This file is part of Crack dot Com's free source code release of


3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for


4  information about compiling & licensing issues visit this URL</a>


5  <PRE> If that doesn't help, contact Jonathan Clark at


6  golgotha_source@usa.net (Subject should have "GOLG" in it)


7  ***********************************************************************/


8 


9  #include "software/r1_software.hh"


10  #include "software/r1_software_globals.hh"


11 


12  #define R1_S_ABS(x) ((x)<0)?((x)):(x)


13 


14  void r1_software_class::draw_line(sw32 _x0, sw32 _y0, sw32 _x1, sw32 _y1, w16 color)


15  {


16  sw32 x0,y0,x1,y1,dx,dy;


17 


18  register w16 *sp;


19  register sw32 error,count;


20  register sw32 change;


21 


22  dx = R1_S_ABS(_x1  _x0)+1;


23  dy = R1_S_ABS(_y1  _y0)+1;


24 


25  if (dx>dy)


26  {


27  if (_x1<_x0)


28  {


29  y0 = _y1;


30  x0 = _x1;


31  y1 = _y0;


32  x1 = _x0;


33  }


34  else


35  {


36  y0 = _y0;


37  x0 = _x0;


38  y1 = _y1;


39  x1 = _x1;


40  }


41  sp = r1_software_render_buffer_ptr + x0 + (y0*r1_software_render_buffer_wpl);


42  if (dy==0)


43  {


44  while (dx)


45  {


46  *sp = color;


47  sp++;


48  dx;


49  }


50  return;


51  }


52 


53  if (y0>y1)


54  {


55  change = r1_software_render_buffer_wpl;


56  }


57  else


58  {


59  change = r1_software_render_buffer_wpl;


60  }


61 


62  error = 0;


63  count = dx;


64 


65  while(count)


66  {


67  *sp = color;


68  sp++;


69  error += dy;


70  if (error>dx)


71  {


72  sp += change;


73  error = dx;


74  }


75  count;


76  }


77  }


78  else


79  {


80  if (_y1<_y0)


81  {


82  y0 = _y1;


83  x0 = _x1;


84  y1 = _y0;


85  x1 = _x0;


86  }


87  else


88  {


89  y0 = _y0;


90  x0 = _x0;


91  y1 = _y1;


92  x1 = _x1;


93  }


94 


95  sp = r1_software_render_buffer_ptr + x0 + (y0*r1_software_render_buffer_wpl);


96  if (dx==0)


97  {


98  while (dy)


99  {


100  *sp = color;


101  sp += r1_software_render_buffer_wpl;


102  dy;


103  }


104  return;


105  }


106  if (x0>x1) change = 1;


107  else change = 1;


108 


109  error = 0;


110  count = dy;


111 


112  while(count)


113  {


114  *sp = color;


115  sp += r1_software_render_buffer_wpl;


116  error += dx;


117  if (error>dy)


118  {


119  sp += change;


120  error = dy;


121  }


122  count;


123  }


124  }


125  }


126 


127  void r1_software_class::draw_line(sw32 _x0, sw32 _y0, sw32 _x1, sw32 _y1, w16 s_color, w16 e_color)


128  {


129  /*


130  sw32 x0,y0,x1,y1,dx,dy,dr,dg,db;


131  sw32 r_int_add = 0, g_int_add = 0, b_int_add = 0;


132  sw32 r_error = 0, g_error = 0, b_error = 0;


133 


134  register w16 *sp;


135  register w16 color;


136  register sw32 error,count;


137  register sw32 change;


138 


139  dr = (e_color & fmt.red_mask)  (s_color & fmt.red_mask);


140  dg = (e_color & fmt.green_mask)  (s_color & fmt.green_mask);


141  db = (e_color & fmt.blue_mask)  (s_color & fmt.blue_mask);


142 


143  dx = R1_S_ABS(_x1  _x0)+1;


144  dy = R1_S_ABS(_y1  _y0)+1;


145 


146  if (dx>dy)


147  {


148  if (dr > dx)


149  {


150  r_int_add = dr / dx;


151  dr = dr % dx;


152  }


153 


154  if (dg > dx)


155  {


156  g_int_add = dg / dx;


157  dg = dg % dx;


158  }


159 


160  if (db > dx)


161  {


162  b_int_add = db / dx;


163  db = db % dx;


164  }


165 


166  color = start_color;


167 


168  if (_x1<_x0)


169  {


170  y0 = _y1;


171  x0 = _x1;


172  y1 = _y0;


173  x1 = _x0;


174  }


175  else


176  {


177  y0 = _y0;


178  x0 = _x0;


179  y1 = _y1;


180  x1 = _x1;


181  }


182  sp = r1_software_render_buffer_ptr + x0 + (y0*r1_software_render_buffer_wpl);


183  if (dy==0)


184  {


185  color += r_int_add;


186  color += g_int_add;


187  color += b_int_add;


188 


189  r_error += dr;


190  if (r_error > dx)


191  {


192  r_error = dx;


193  color += 0;


194  }


195 


196  while (dx)


197  {


198  *sp = color;


199  sp++;


200  dx;


201  }


202  return;


203  }


204 


205  if (y0>y1)


206  {


207  change = r1_software_render_buffer_wpl;


208  }


209  else


210  {


211  change = r1_software_render_buffer_wpl;


212  }


213 


214  error = 0;


215  count = dx;


216 


217  while(count)


218  {


219  *sp = color;


220  sp++;


221  error += dy;


222  if (error>dx)


223  {


224  sp += change;


225  error = dx;


226  }


227  count;


228  }


229  }


230  else


231  {


232  if (_y1<_y0)


233  {


234  y0 = _y1;


235  x0 = _x1;


236  y1 = _y0;


237  x1 = _x0;


238  }


239  else


240  {


241  y0 = _y0;


242  x0 = _x0;


243  y1 = _y1;


244  x1 = _x1;


245  }


246 


247  sp = r1_software_render_buffer_ptr + x0 + (y0*r1_software_render_buffer_wpl);


248  if (dx==0)


249  {


250  while (dy)


251  {


252  *sp = color;


253  sp += r1_software_render_buffer_wpl;


254  dy;


255  }


256  return;


257  }


258  if (x0>x1) change = 1;


259  else change = 1;


260 


261  error = 0;


262  count = dy;


263 


264  while(count)


265  {


266  *sp = color;


267  sp += r1_software_render_buffer_wpl;


268  error += dx;


269  if (error>dy)


270  {


271  sp += change;


272  error = dy;


273  }


274  count;


275  }


276  }


277  */


278  }

