Advertisement
captmicro

Untitled

Dec 31st, 2012
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. void kvideo_putline(uint16 x1, uint16 y1, uint16 x2, uint16 y2, char c, uint8 col)
  2. {
  3. if (c == '\0') return;
  4. uint16 *vptr = (uint16*)VGA_TEXTCOLOR;
  5. unsigned short lc = (col << 8) | c;
  6. unsigned int i = 0, j = 0;
  7. if (y1 == y2) //horizontal
  8. {
  9. if (x1 > x2) {
  10. for (i = x2; i < x1; i++)
  11. *(vptr + i + (y1 * KVIDEO_W)) = lc;
  12. } else if (x2 > x1) {
  13. for (i = x1; i < x2; i++)
  14. *(vptr + i + (y1 * KVIDEO_W)) = lc;
  15. } else if (x1 == x2) {
  16. *(vptr + x1 + (y1 * KVIDEO_W)) = lc;
  17. }
  18. }
  19. else if (x1 == x2) //vertical
  20. {
  21. if (y1 > y2) {
  22. for (i = y2; i < y1; i++)
  23. *(vptr + x1 + (i * KVIDEO_W)) = lc;
  24. } else if (y2 > y1) {
  25. for (i = y1; i < y2; i++)
  26. *(vptr + x1 + (i * KVIDEO_W)) = lc;
  27. } else if (y1 == y2) {
  28. *(vptr + x1 + (y1 * KVIDEO_W)) = lc;
  29. }
  30. }
  31. else //cant get off that easy...
  32. {
  33. short deltax = x2 - x1;
  34. short deltay = y2 - y1;
  35. short deltaxabs = abs_16(deltax);
  36. short deltayabs = abs_16(deltay);
  37. short sgndeltax = sgn_16(deltax);
  38. short sgndeltay = sgn_16(deltay);
  39. short x = deltayabs >> 1;
  40. short y = deltaxabs >> 1;
  41. short drawx = x1, drawy = y1;
  42. *(vptr + drawx + (drawy * KVIDEO_W)) = lc;
  43. int n = 0;
  44. if (deltaxabs >= deltayabs) {
  45. for (n = 0; n < deltaxabs; n++) {
  46. y += deltayabs;
  47. if (y >= deltaxabs) {
  48. y -= deltaxabs;
  49. drawy += sgndeltay;
  50. }
  51. drawx += sgndeltax;
  52. *(vptr + drawx + (drawy * KVIDEO_W)) = lc;
  53. }
  54. } else {
  55. for (n = 0; n < deltayabs; n++) {
  56. x += deltaxabs;
  57. if (x >= deltayabs) {
  58. x -= deltayabs;
  59. drawx += sgndeltax;
  60. }
  61. drawy += sgndeltay;
  62. *(vptr + drawx + (drawy * KVIDEO_W)) = lc;
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement