home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 83 / asm / source / sprxor.z80 < prev    next >
Encoding:
Text File  |  2001-07-01  |  3.3 KB  |  111 lines

  1. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  2. ;│█████ Z80 ██████│    Sprite83    │█████████████████████│ movax │████████████│
  3. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  4.  
  5. ; Sprite xor routine v1.0
  6. ; Coded by Hannes Edfeldt in 1997
  7.  
  8. ; This routine uses xor to draw the sprite, therefore you can erase the sprite
  9. ; by just drawing it again at the same x and y coordinates. See xordemo.z80
  10. ; for an example of how to use this routine.
  11.  
  12. ; Feel free to use this routine in your own productions as long as you give me
  13. ; some credit.
  14.  
  15. ; This file should of course be viewed in a DOS texteditor ;)
  16.  
  17. ; Hannes Edfeldt -+- movax@algonet.se -+- http://www.algonet.se/~movax
  18.  
  19.  
  20. ;▄████████████▀ SPRXOR ▀███████████████████████████████████████████████████████
  21. ;┌────────────────────────────────────────────────────────────────────────────┐
  22. ;│ Xor 8x8 sprite ■ a=x, e=y, bc=sprite address                               │
  23. ;└────────────────────────────────────────────────────────────────────────────┘
  24. SPRXOR:
  25.  
  26.         push    bc              ; Save sprite address
  27.  
  28. ;████   Calculate the address in graphbuf   ████
  29.  
  30.         ld      hl,0            ; Do y*12
  31.         ld      d,0
  32.         add     hl,de
  33.         add     hl,de
  34.         add     hl,de
  35.         add     hl,hl
  36.         add     hl,hl
  37.  
  38.         ld      d,0             ; Do x/8
  39.         ld      e,a
  40.         srl     e
  41.         srl     e
  42.         srl     e
  43.         add     hl,de
  44.  
  45.         ld      de,8e29h
  46.         add     hl,de           ; Add address to graphbuf
  47.  
  48.         ld      b,00000111b     ; Get the remainder of x/8
  49.         and     b
  50.         cp      0               ; Is this sprite aligned to 8*n,y?
  51.         jp      z,ALIGN
  52.  
  53.  
  54. ;████   Non aligned sprite blit starts here   ████
  55.  
  56.         pop     ix              ; ix->sprite
  57.         ld      d,a             ; d=how many bits to shift each line
  58.  
  59.         ld      e,8             ; Line loop
  60. LILOP:  ld      b,(ix+0)        ; Get sprite data
  61.  
  62.         ld      c,0             ; Shift loop
  63.         push    de
  64. SHLOP:  srl     b
  65.         rr      c
  66.         dec     d
  67.         jp      nz,SHLOP
  68.         pop     de
  69.  
  70.         ld      a,b             ; Write line to graphbuf
  71.         xor     (hl)
  72.         ld      (hl),a
  73.         inc     hl
  74.         ld      a,c
  75.         xor     (hl)
  76.         ld      (hl),a
  77.  
  78.         ld      bc,11           ; Calculate next line address
  79.         add     hl,bc
  80.         inc     ix              ; Inc spritepointer
  81.  
  82.         dec     e
  83.         jp      nz,LILOP        ; Next line
  84.  
  85.         jp      DONE1
  86.  
  87.  
  88. ;████   Aligned sprite blit starts here   ████
  89.  
  90. ALIGN:                          ; Blit an aligned sprite to graphbuf
  91.         pop     de              ; de->sprite
  92.         ld      b,8
  93. ALOP1:  ld      a,(de)
  94.         xor     (hl)
  95.         ld      (hl),a
  96.         inc     de
  97.         push    bc
  98.         ld      bc,12
  99.         add     hl,bc
  100.         pop     bc
  101.         djnz    ALOP1
  102.  
  103. DONE1:
  104.         ret
  105. ;▄████████████▄ SPRXOR ▄███████████████████████████████████████████████████████
  106.  
  107.  
  108. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  109. ;│█████ Z80 ██████│    Sprite83    │█████████████████████│ movax │████████████│
  110. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  111.