line.z80 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. fastline:
  2. ;(H,L) is (x0,y0)
  3. ;(D,E) is (x1,y1)
  4. ;IX points to the pixel plotting routine
  5. ;
  6. ; LICENSING NOTE:
  7. ; This code is (heavily) modified from Axe's open source code.
  8. ; There are structural similarities, but the majority of it is rewritten.
  9. ld a,d
  10. sub h
  11. jp p,+_
  12. ex de,hl
  13. neg
  14. _:
  15. push hl ;Save the coordinates
  16. ld c,a
  17. ld a,l
  18. ld l,c
  19. sub e
  20. ld c,0
  21. jp p,+_
  22. dec c
  23. neg
  24. _:
  25. ld h,a ; H=DY, L=DX
  26. cp l
  27. jr nc,+_
  28. ld a,l
  29. _:
  30. pop de ;restore coordinates
  31. ld b,a ; Pixel counter
  32. inc b
  33. cp h
  34. ;want to preserve Z
  35. jr nz,__LineH ; Line is rather horizontal than vertical
  36. ;divide A by 2, given carry is reset
  37. rra
  38. __LineVLoop:
  39. call call_ix ;plot
  40. rlc c
  41. jr nc,+_
  42. inc e
  43. .db $FE
  44. _:
  45. dec e
  46. sub l ; Handling gradient
  47. jr nc,+_
  48. inc d
  49. add a,h
  50. _:
  51. djnz __LineVLoop
  52. ret
  53. __LineH:
  54. ;divide A by 2, given carry is set
  55. or a
  56. rra
  57. __LineHLoop:
  58. call call_ix ;plot
  59. inc d
  60. sub h ; Handling gradient
  61. jr nc,__LineHNext
  62. rlc c
  63. jr nc,+_
  64. inc e
  65. .db $FE
  66. _:
  67. dec e
  68. add a,l
  69. __LineHNext:
  70. djnz __LineHLoop
  71. ret
  72. pxloff:
  73. push hl
  74. push bc
  75. push af
  76. ld b,d
  77. ld c,e
  78. call getPixelLoc
  79. jr nc,+_
  80. cpl
  81. and (hl)
  82. ld (hl),a
  83. _:
  84. pop af
  85. pop bc
  86. pop hl
  87. ret
  88. pxlon:
  89. push hl
  90. push bc
  91. push af
  92. ld b,d
  93. ld c,e
  94. call getPixelLoc
  95. jr nc,+_
  96. or (hl)
  97. ld (hl),a
  98. _:
  99. pop af
  100. pop bc
  101. pop hl
  102. ret
  103. pxlchange:
  104. push hl
  105. push bc
  106. push af
  107. ld b,d
  108. ld c,e
  109. call getPixelLoc
  110. jr nc,+_
  111. xor (hl)
  112. ld (hl),a
  113. _:
  114. pop af
  115. pop bc
  116. pop hl
  117. ret