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

  1. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  2. ;│█████ Z80 ██████│    Sprite83    │█████████████████████│ movax │████████████│
  3. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  4.  
  5. ; Sprite draw routine v1.0 and sprite clear routine v1.0
  6. ; Coded by Hannes Edfeldt in 1997
  7.  
  8. ; With these two routines you can draw and clear non-aligned sprites. See
  9. ; sprdemo.z80 for an example of how to use these routines.
  10.  
  11. ; Feel free to use these routines in your own productions as long as you give
  12. ; me some credit.
  13.  
  14. ; This file should of course be viewed in a DOS texteditor ;)
  15.  
  16. ; Hannes Edfeldt -+- movax@algonet.se -+- http://www.algonet.se/~movax
  17.  
  18.  
  19. ;▄████████████▀ DRWSPR ▀███████████████████████████████████████████████████████
  20. ;┌────────────────────────────────────────────────────────────────────────────┐
  21. ;│ Draw 8x8 sprite ■ a=x, e=y, hl=sprite address                              │
  22. ;└────────────────────────────────────────────────────────────────────────────┘
  23. DRWSPR:
  24.  
  25.         push    hl              ; Save sprite address
  26.  
  27. ;████   Calculate the address in graphbuf   ████
  28.  
  29.         ld      hl,0            ; Do y*12
  30.         ld      d,0
  31.         add     hl,de
  32.         add     hl,de
  33.         add     hl,de
  34.         add     hl,hl
  35.         add     hl,hl
  36.  
  37.         ld      d,0             ; Do x/8
  38.         ld      e,a
  39.         srl     e
  40.         srl     e
  41.         srl     e
  42.         add     hl,de
  43.  
  44.         ld      de,8e29h
  45.         add     hl,de           ; Add address to graphbuf
  46.  
  47.         ld      b,00000111b     ; Get the remainder of x/8
  48.         and     b
  49.         cp      0               ; Is this sprite aligned to 8*n,y?
  50.         jp      z,ALIGN
  51.  
  52.  
  53. ;████   Non aligned sprite blit starts here   ████
  54.  
  55.         pop     ix              ; ix->sprite
  56.         ld      d,a             ; d=how many bits to shift each line
  57.  
  58.         ld      e,8             ; Line loop
  59. LILOP:  ld      b,(ix+0)        ; Get sprite data
  60.  
  61.         ld      c,0             ; Shift loop
  62.         push    de
  63. SHLOP:  srl     b
  64.         rr      c
  65.         dec     d
  66.         jp      nz,SHLOP
  67.         pop     de
  68.  
  69.         ld      a,b             ; Write line to graphbuf
  70.         or      (hl)
  71.         ld      (hl),a
  72.         inc     hl
  73.         ld      a,c
  74.         or      (hl)
  75.         ld      (hl),a
  76.  
  77.         ld      bc,11           ; Calculate next line address
  78.         add     hl,bc
  79.         inc     ix              ; Inc spritepointer
  80.  
  81.         dec     e
  82.         jp      nz,LILOP        ; Next line
  83.  
  84.         jp      DONE1
  85.  
  86.  
  87. ;████   Aligned sprite blit starts here   ████
  88.  
  89. ALIGN:                          ; Blit an aligned sprite to graphbuf
  90.         pop     de              ; de->sprite
  91.         ld      b,8
  92. ALOP1:  ld      a,(de)
  93.         or      (hl)            ; xor=erase/blit
  94.         ld      (hl),a
  95.         inc     de
  96.         push    bc
  97.         ld      bc,12
  98.         add     hl,bc
  99.         pop     bc
  100.         djnz    ALOP1
  101.  
  102. DONE1:
  103.         ret
  104. ;▄████████████▄ DRWSPR ▄███████████████████████████████████████████████████████
  105.  
  106.  
  107. ;▄████████████▀ CLRSPR ▀███████████████████████████████████████████████████████
  108. ;┌────────────────────────────────────────────────────────────────────────────┐
  109. ;│ Clear 8x8 sprite ■ a=x, e=y, hl=sprite address                             │
  110. ;└────────────────────────────────────────────────────────────────────────────┘
  111. CLRSPR:
  112.         push    hl              ; Save sprite address
  113.  
  114. ;████   Calculate the address in graphbuf   ████
  115.  
  116.         ld      hl,0            ; Do y*12
  117.         ld      d,0
  118.         add     hl,de
  119.         add     hl,de
  120.         add     hl,de
  121.         add     hl,hl
  122.         add     hl,hl
  123.  
  124.         ld      d,0             ; Do x/8
  125.         ld      e,a
  126.         srl     e
  127.         srl     e
  128.         srl     e
  129.         add     hl,de
  130.  
  131.         ld      de,8e29h
  132.         add     hl,de           ; Add address to graphbuf
  133.  
  134.         ld      b,00000111b     ; Get the remainder of x/8
  135.         and     b
  136.         cp      0               ; Is this sprite aligned to 8*n,y?
  137.         jp      z,ALIGN2
  138.  
  139.  
  140. ;████   Non aligned sprite erase starts here   ████
  141.  
  142.         pop     ix              ; ix->sprite
  143.         ld      d,a             ; d=how many bits to shift each line
  144.  
  145.         ld      e,8             ; Line loop
  146. LILOP2: ld      b,(ix+0)        ; Get sprite data
  147.  
  148.         ld      c,0             ; Shift loop
  149.         push    de
  150. SHLOP2: srl     b
  151.         rr      c
  152.         dec     d
  153.         jp      nz,SHLOP2
  154.         pop     de
  155.  
  156.         ld      a,b             ; Write line to graphbuf
  157.         cpl
  158.         and     (hl)
  159.         ld      (hl),a
  160.         inc     hl
  161.         ld      a,c
  162.         cpl
  163.         and     (hl)
  164.         ld      (hl),a
  165.  
  166.         ld      bc,11           ; Calculate next line address
  167.         add     hl,bc
  168.         inc     ix              ; Inc spritepointer
  169.  
  170.         dec     e
  171.         jp      nz,LILOP2       ; Next line
  172.  
  173.         jp      DONE5
  174.  
  175.  
  176. ;████   Aligned sprite erase starts here   ████
  177.  
  178. ALIGN2:                         ; Erase an aligned sprite in graphbuf
  179.         pop     de              ; de->sprite
  180.         ld      b,8
  181. ALOP2:  ld      a,(de)
  182.         cpl
  183.         and     (hl)
  184.         ld      (hl),a
  185.         inc     de
  186.         push    bc
  187.         ld      bc,12
  188.         add     hl,bc
  189.         pop     bc
  190.         djnz    ALOP2
  191.  
  192. DONE5:
  193.         ret
  194. ;▄████████████▄ CLRSPR ▄███████████████████████████████████████████████████████
  195.  
  196. ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
  197. ;│█████ Z80 ██████│    Sprite83    │█████████████████████│ movax │████████████│
  198. ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
  199.