wireframe.fs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. start-microcode wireframe
  2. \ See http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
  3. COMM+0 constant X0
  4. COMM+1 constant Y0
  5. COMM+2 constant X1
  6. COMM+3 constant Y1
  7. COMM+4 constant steep
  8. COMM+5 constant deltax
  9. COMM+6 constant deltay
  10. COMM+7 constant ystep
  11. COMM+8 constant color
  12. : setpixel ( yx -- ) \ set pixel yx to color
  13. dup>r
  14. h# f and
  15. r@ d# 4 rshift h# 0ff0 and or
  16. r@ h# 30 and swab or
  17. RAM_SPRIMG or ( addr )
  18. dupc@ ( addr v )
  19. color c@ r> d# 5 rshift h# 6 and rshift or
  20. swap c!
  21. ;
  22. : negate invert ;fallthru
  23. : 1+ d# 1 + ;
  24. : @ dupc@ swap 1+ c@ swab or ;
  25. : byte h# ff and ;
  26. : bresenham
  27. deltay c@ negate >r \ keep -deltay on R stack for speed
  28. X0 @ \ load y0x0
  29. deltax c@ d# 1 rshift \ load deltax/1, is error
  30. ( y0x0 error )
  31. begin
  32. over byte X1 c@ xor
  33. while
  34. over
  35. steep c@ if swab then
  36. setpixel
  37. r@ + \ error -= deltay
  38. dup d# 0 < if
  39. deltax c@ + \ error += deltax
  40. ystep c@ swab 1+
  41. else
  42. d# 1
  43. then
  44. >r swap r> + swap \ increment YX
  45. repeat
  46. r> drop
  47. ;
  48. : main
  49. begin
  50. \ wait until command reg is nonzero
  51. begin
  52. ystep c@
  53. until
  54. bresenham
  55. \ tell host we're done
  56. d# 0 ystep c!
  57. again
  58. ;
  59. end-microcode