Advertisement
Runer112

Untitled

Dec 7th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. p_HLine:
  2. .db __HLineEnd-$-1
  3. ld de,plotSScreen
  4. x_HLineEntry:
  5.  
  6. ;; de=buff, l=x2, (sp)=ret, (sp+2)=x1, (sp+4)=y
  7. ;; Rearrange stuff
  8. ld a,l
  9. pop hl
  10. pop bc
  11. ex (sp),hl
  12.  
  13. ;; a=x2, c=x1, de=buff, l=y
  14. ;; Check if x2 is offscreen left; if so, note and fix it
  15. ld h,0
  16. ld b,a
  17. rla
  18. jr nc,$+3
  19. ld b,h
  20.  
  21. ;; carry=x2 offscreen, b=left-fixed x2, c=x1, de=buff, h=0, l=y
  22. ;; Check if x1 is offscreen left; if so, abort if x2 was too, then fix it
  23. bit 7,c
  24. jr z,$+4
  25. ret c
  26. ld c,h
  27.  
  28. ;; b=left-fixed x2, c=left-fixed x1, de=buff, h=0, l=y
  29. ;; Check if x1 is offscreen right; if so, abort if x2 is too, then fix it
  30. ld a,95
  31. cp c
  32. jr nc,$+5
  33. cp b
  34. ret c
  35. ld c,a
  36.  
  37. ;; a=95, b=left-fixed x2, c=fixed x1, de=buff, h=0, l=y
  38. ;; Check if x2 is offscreen right; if so, fix it
  39. cp b
  40. jr nc,$+3
  41. ld b,a
  42.  
  43. ;; X Clipping complete; x1 and x2 guaranteed to be onscreen
  44. ;; a=95, b=x2, c=x1, de=buff, h=0, l=y
  45. ;; Locate the lesser and greater (will refer to them as x1 and x2) of x1 and x2
  46. ld a,b
  47. cp c
  48. jr c,$+5
  49. ld c,b
  50. ld b,a
  51. ld a,c
  52.  
  53. ;; a=x1, b=x1, c=x2, de=buff, h=0, l=y
  54. ;; Abort if y is offscreen while calculating y*4
  55. add hl,hl
  56. add hl,hl
  57. dec h
  58. ret m
  59. inc h
  60.  
  61. ;; a=x1, b=x1, c=x2, de=buff, h=0, l=y*4
  62. ;; Calculate x1/8 and add it and y*12 to the buffer pointer
  63. ex de,hl
  64. add hl,de
  65. rra
  66. add hl,de
  67. rra
  68. add hl,de
  69. rra
  70. ld e,a
  71. add hl,de
  72.  
  73. ;; Begin drawing! y no longer needed
  74. ;; a=x1/8, b=x1, c=x2, d=0, e=x1/8, hl=y*12+(x1/8)+buff
  75. ;; Calculate the mask for the first byte
  76. ld e,b
  77. ld a,b
  78. and %00000111
  79. jr z,__HLineLeft8
  80. ld b,a
  81. ld a,$01
  82. __HLineLeftLoop:
  83. rrca
  84. djnz __HLineFirstLoop
  85. __HLineLeft8:
  86. dec a
  87.  
  88. ;; a=first mask, b=0, c=x2, d=0, e=x1, hl=y*12+(x1/8)+buff
  89. ;; Prepare the first byte and calculate the negative remaining width after the
  90. ;; first byte; if positive, jump to the masking code for the last byte
  91. or (hl)
  92. ld d,a
  93. ld a,e
  94. or %00000111
  95. sub c
  96. jr nc,__HLineRight
  97.  
  98. ;; a=-width remaining, b=0, c=x2, d=byte, e=x1, hl=y*12+(x1/8)+buff
  99. ;; Draw bytes until there is no width remaining
  100. __HLineMidLoop:
  101. ld (hl),d
  102. inc hl
  103. ld d,$FF
  104. add a,8
  105. jr nc,__HLineMidLoop
  106.  
  107. ;; a=width remaining-1%8+1, b=0, c=x2, d=byte, e=x1, hl=y*12+(x2/8)+buff
  108. ;; Calculate the mask for the last byte
  109. __HLineRight:
  110. ld b,a
  111. inc b
  112. ld a,$80
  113. __HLineRightLoop:
  114. rlca
  115. djnz __HLineRightLoop
  116. dec a
  117. cpl
  118.  
  119. ;; a=mask, b=0, c=x2, d=byte, e=x1, hl=y*12+(x2/8)+buff
  120. ;; Draw the last byte
  121. and d
  122. or (hl)
  123. ld (hl),a
  124.  
  125. ret
  126. __HLineEnd:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement