Draw Line.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Example of a fast line-drawing routine
  2. #define USE_TI89 // Compile for TI-89
  3. #define USE_TI92PLUS // Compile for TI-92 Plus
  4. #define USE_V200 // Compile for V200
  5. #define MIN_AMS 100 // Compile for AMS 1.00 or higher
  6. #define SAVE_SCREEN // Save/Restore LCD Contents
  7. #include <tigcclib.h> // Include All Header Files
  8. // Draws a line from (x1,y2) to (x2,y2).
  9. void DrawLineFast(short x1, short y1, short x2, short y2)
  10. {
  11. short x = x1, y = y1;
  12. short dx = abs (x2 - x1), dy = abs (y2 - y1);
  13. short ystep = (y1 < y2) ? 1 : -1, pystep = 30 * ystep;
  14. short mov = dx ? 0 : -1;
  15. unsigned char *ptr = (char*)LCD_MEM + 30 * y + (x >> 3);
  16. short mask = 1 << (~x & 7);
  17. if (x1 < x2)
  18. while (x != x2 || y != y2)
  19. {
  20. *ptr |= mask;
  21. if (mov < 0) y += ystep, ptr += pystep, mov += dx;
  22. else
  23. {
  24. mov -= dy;
  25. if (++x & 7) mask >>= 1;
  26. else ptr++, mask = 0x80;
  27. }
  28. }
  29. else
  30. while (x != x2 || y != y2)
  31. {
  32. *ptr |= mask;
  33. if (mov < 0) y += ystep, ptr += pystep, mov += dx;
  34. else
  35. {
  36. mov -= dy;
  37. if (x-- & 7) mask <<= 1;
  38. else ptr--, mask = 1;
  39. }
  40. }
  41. }
  42. // Main Function
  43. void _main(void)
  44. {
  45. DrawLineFast (10, 10, 60, 70);
  46. ngetchx ();
  47. }