filledcircle.z80 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ;Written by Zeda Thomas, free to use.
  2. ;This draws the fill of a circle centered at 8-bit coordinates and with radius
  3. ;up to 127.
  4. ;IX points to a `horizontal line` routine that takes E=x, A=y, D=width as input
  5. ;and does something with it, like plot a horizontal line.
  6. ;
  7. ; For example, on the ti-83+/84+/SE calculators, you might have:
  8. ; horizontal_line:
  9. ; ld b,e
  10. ; ld c,a
  11. ; ld e,1
  12. ; ld hl,gbuf
  13. ; jp rectOR
  14. ; Required subroutines:
  15. ; call_ix_01:
  16. ; jp (ix)
  17. filledcircle:
  18. ;Input:
  19. ; (B,C) is the center (x,y)
  20. ; E is the radius, unsigned, less than 128 (0 or greater than 128 just quits).
  21. ; IX points to a `plot` routine that takes (B,C)=(x,y) as input.
  22. ld a,e
  23. add a,a
  24. ret c
  25. ret z
  26. ld l,e
  27. dec a
  28. ld e,a
  29. xor a
  30. ld h,-1
  31. ld d,1
  32. filledcircleloop:
  33. ; call c,fillcircle_plot
  34. inc h
  35. sub d
  36. inc d
  37. inc d
  38. jr nc,filledcircleloop
  39. _:
  40. dec l
  41. call fillcircle_plot
  42. add a,e
  43. dec e
  44. ret z
  45. dec e
  46. jr nc,-_
  47. jp filledcircleloop
  48. fillcircle_plot:
  49. inc h
  50. dec h
  51. ret z
  52. push hl
  53. push de
  54. push bc
  55. push af
  56. dec h
  57. ld a,b
  58. sub h
  59. ld e,a
  60. ld d,h
  61. sll d ;aka `slia`, undocumented
  62. ld a,l
  63. or a
  64. ld h,c
  65. jr z,+_
  66. add a,h
  67. push de
  68. push hl
  69. call nz,call_ix_01
  70. pop hl
  71. pop de
  72. _:
  73. ld a,h
  74. sub l
  75. call call_ix_01
  76. pop af
  77. pop bc
  78. pop de
  79. pop hl
  80. ret