Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.3 KiB

  1. /*************************************************************************\
  2. * Module Name: intline.c
  3. *
  4. * Copyright (c) 1993-1994 Microsoft Corporation
  5. * Copyright (c) 1992 Digital Equipment Corporation
  6. \**************************************************************************/
  7. #include "precomp.h"
  8. #define DEFAULT_DRAW_CMD DRAW_LINE | \
  9. DRAW | \
  10. DIR_TYPE_XY | \
  11. MULTIPLE_PIXELS | \
  12. WRITE | \
  13. LAST_PIXEL_OFF
  14. /******************************************************************************
  15. * bIntegerLine
  16. *
  17. * This routine attempts to draw a line segment between two points. It
  18. * will only draw if both end points are whole integers: it does not support
  19. * fractional endpoints.
  20. *
  21. * Returns:
  22. * TRUE if the line segment is drawn
  23. * FALSE otherwise
  24. *****************************************************************************/
  25. BOOL
  26. bIntegerLine (
  27. PDEV* ppdev,
  28. ULONG X1,
  29. ULONG Y1,
  30. ULONG X2,
  31. ULONG Y2
  32. )
  33. {
  34. LONG Cmd;
  35. LONG DeltaX, DeltaY;
  36. LONG ErrorTerm;
  37. LONG Major, Minor;
  38. X1 >>= 4;
  39. Y1 >>= 4;
  40. X2 >>= 4;
  41. Y2 >>= 4;
  42. Cmd = DEFAULT_DRAW_CMD | PLUS_Y | PLUS_X | MAJOR_Y;
  43. DeltaX = X2 - X1;
  44. if (DeltaX < 0) {
  45. DeltaX = -DeltaX;
  46. Cmd &= ~PLUS_X;
  47. }
  48. DeltaY = Y2 - Y1;
  49. if (DeltaY < 0) {
  50. DeltaY = -DeltaY;
  51. Cmd &= ~PLUS_Y;
  52. }
  53. // Compute the major drawing axis
  54. if (DeltaX > DeltaY) {
  55. Cmd &= ~MAJOR_Y;
  56. Major = DeltaX;
  57. Minor = DeltaY;
  58. } else {
  59. Major = DeltaY;
  60. Minor = DeltaX;
  61. }
  62. // Tell the S3 to draw the line
  63. IO_FIFO_WAIT (ppdev, 7);
  64. IO_CUR_X (ppdev, X1);
  65. IO_CUR_Y (ppdev, Y1);
  66. IO_MAJ_AXIS_PCNT (ppdev, Major);
  67. IO_AXSTP (ppdev, Minor * 2);
  68. IO_DIASTP (ppdev, 2 * Minor - 2 * Major);
  69. // Adjust the error term so that 1/2 always rounds down, to
  70. // conform with GIQ.
  71. ErrorTerm = 2 * Minor - Major;
  72. if (Cmd & MAJOR_Y) {
  73. if (Cmd & PLUS_X) {
  74. ErrorTerm--;
  75. }
  76. } else {
  77. if (Cmd & PLUS_Y) {
  78. ErrorTerm--;
  79. }
  80. }
  81. IO_ERR_TERM (ppdev, ErrorTerm);
  82. IO_CMD (ppdev, Cmd);
  83. return TRUE;
  84. }