Advertisement
Zeda

Scaled Sprite Modified

Feb 9th, 2015
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;being modified by Zeda Thomas so that when called the first time, ANDs a mask, then the second time, XORs the sprite
  2.  
  3. ; -------------------- putScaledSprite --------------------
  4. ; Draws a scaled sprite to the graph buffer.
  5. ;
  6. ; Version: 1.1
  7. ; Author: Badja <http://move.to/badja> <badja@alphalink.com.au>
  8. ; Date: 21 December 1999
  9. ;
  10. ; Modified by Eric Piel : LD and smaller and quicker < Eric.Piel@etu.utc.fr >
  11. ; Date: 19 May 2000
  12. ; Size: 156 bytes (161 bytes if XORing the sprite, 151 bytes if just Loading it)
  13. ;
  14. ; Input:
  15. ;   HL -> sprite
  16. ;    D = x-coordinate
  17. ;    E = y-coordinate
  18. ;    B = height of unscaled sprite
  19. ;    C = width of unscaled sprite (in bytes, so divide by 8)
  20. ;    A = scale factor ($01 to $00 <=> 0.4% to 100%)
  21. ;        eg: $80 is 50%
  22. ;
  23. ; Output:
  24. ;   The sprite is ORed to the graph buffer. To XOR the sprite
  25. ;   instead, add the following line near the top of your program:
  26. ;   #define _SS_XOR
  27. ;   To just load it insert:
  28. ;   #define _SS_LD
  29. ;
  30. ; Destroys:
  31. ;   AF, BC, DE, HL
  32.  
  33.  
  34. putScaledSprite:
  35.    ld   (_SS_SetScale1),a
  36.    ld   (_SS_SetScale2),a
  37.    ld   a,(_SS_Logic)          ;zeda
  38.    xor  8                      ;zeda
  39.    ld   (_SS_Logic),a          ;zeda
  40.    ld   a,d
  41.  
  42.    push   hl
  43.    ld   d,0
  44.    ld   h,d
  45.    ld   l,e
  46.    add   hl,de
  47.    add   hl,de
  48.    add   hl,hl
  49.    add   hl,hl
  50.    ld   de,(iy)      ;preset buffer
  51.    add   hl,de
  52.    ld   d,0
  53.    ld   e,a
  54.    srl   e
  55.    srl   e
  56.    srl   e
  57.    add   hl,de
  58.    and   %00000111
  59.    ld   (_SS_SetPreShift),a
  60.    neg
  61.    add   a,8
  62.  
  63.    ld   (_SS_SetBitsLeft),a
  64.    ex   de,hl
  65.  
  66.    ld   a,c
  67.    ld   (_SS_SetByteWidth),a
  68.    sla   a
  69.    sla   a
  70.    sla   a
  71.    ld   (_SS_SetPixelWidth),a
  72.  
  73.    pop   hl
  74.    ld   c,0
  75.    push   bc
  76.    jr   _SS_DoRow
  77.  
  78. _SS_SpriteLoop:
  79. _SS_SetScale1 = $ + 1
  80.    ld   a,0      ; scale factor (self-modified)
  81.    add   a,c
  82.    ld   c,a
  83.    push   bc
  84.    jr   z,_SS_DoRow
  85.    jr   c,_SS_DoRow
  86. _SS_SetByteWidth = $ + 1
  87.    ld   bc,$0000   ; C = byte width of sprite data (self-modified)
  88.    add   hl,bc
  89.    jr   _SS_SkipRow
  90. _SS_DoRow:
  91.    push   de
  92.  
  93. _SS_SetPreShift = $ + 2
  94.    ld   bc,$0000   ; B = # bits before start of row (self-modified)
  95.    ld   a,b
  96.    or   a
  97.    jr   z,_SS_PutBitsLeft
  98.    ld   a,(de)
  99. _SS_PreShift:
  100.    rlca
  101.    djnz   _SS_PreShift
  102.    ld   (de),a
  103. _SS_PutBitsLeft:
  104. _SS_SetBitsLeft = $ + 1
  105.    ld   b,$00      ; # bits to copy into first byte (self-modified)
  106.  
  107. _SS_SetPixelWidth = $ + 1
  108.    ld   a,$00      ; pixel width of sprite data (self-modified)
  109.    push   af
  110.    jr   _SS_DoPixel
  111. _SS_RowLoop:
  112.    and   %00000111
  113.    jr   nz,_SS_SameByte
  114.    inc   hl
  115. _SS_SameByte:
  116. _SS_SetScale2 = $ + 1
  117.    ld   a,0      ; scale factor (self-modified)
  118.    add   a,c
  119.    ld   c,a
  120. ;   jr   z,_SS_DoPixel   ;Zeda Edit: only ever becomes z if c
  121.    jr   nc,_SS_SkipPixel
  122. _SS_DoPixel:
  123. ;;All messed up by Zeda
  124.    ex de,hl
  125.    ld   a,(de)
  126. _SS_Logic:       ;pixel logic, self modified (xor 8 to make it "and (hl)")
  127.    xor  (hl)
  128.    rla
  129.    rl   (hl)
  130.    ex de,hl
  131.    djnz   _SS_DoneByte
  132.    ld   b,8
  133.    inc   de
  134.    jr   _SS_DoneByte
  135. _SS_SkipPixel:
  136.    rlc   (hl)
  137. _SS_DoneByte:
  138.    pop   af
  139.    dec   a
  140.    push   af
  141.    jr   nz,_SS_RowLoop
  142. _SS_DoneRow:
  143.    inc   hl
  144.    bit   3,b
  145.    jr   nz,_SS_RowComplete
  146.    ld   a,(de)
  147. _SS_PostShift:
  148.    rlca
  149.    djnz   _SS_PostShift
  150.    ld   (de),a
  151.    inc   de
  152. _SS_RowComplete:
  153.    pop   af
  154.    ex   (sp),hl
  155.    ld   de,12
  156.    add   hl,de
  157.    ex   de,hl
  158.    pop   hl
  159.  
  160. _SS_SkipRow:
  161.    pop   bc
  162.    djnz   _SS_SpriteLoop
  163.    ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement