home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 83 / asm / source / routines / andxorsp.z80 next >
Encoding:
Text File  |  2001-07-01  |  6.0 KB  |  184 lines

  1. ; Sprite AND XOR Routine
  2. ; by Frank Schoep. Revision: 33
  3.  
  4. ; Routine input:  D is the x coordinate
  5. ;                 E is the y coordinate
  6. ;                 BC as pointer to bit mask (8 bits) + sprite data (8 bits)
  7. ; Routine output: N/A
  8.  
  9. GrBufBackup:                                    ;main identifier of grbufbak
  10.         ld hl,plotsscreen                       ;hl->screen
  11.         ld de,saferam1                          ;de->safe bak memory
  12.         ld bc,768                               ;bc=786 bytes to copy
  13.         ldir                                    ;LoaD Increment Repeat (bc=0)
  14.         ret                                     ;return
  15.  
  16. GrBufResBackup:                                 ;main identifier of grresbak
  17.         ld hl,saferam1                          ;hl->safe bak memory
  18.         ld de,plotsscreen                       ;de->screen
  19.         ld bc,768                               ;bc=786 bytes to copy
  20.         ldir                                    ;copy backup to screen
  21.         ret                                     ;return
  22.  
  23. SPRANDXOR:                                      ;display sprite AND XOR way                                        
  24.         push de                                 ;store memory address (XOR)
  25.         ld a,d                                  ;a=x coord
  26.         call sprand                             ;draw bit mask
  27.         pop de                                  ;restore memory address (XOR)
  28.         ld a,d                                  ;a=x coord
  29.         call sprxor                             ;draw xor sprite
  30.         ret                                     ;return
  31.  
  32. SPRAND:
  33.  
  34.         push bc ;for Baldur's Gate only!
  35.  
  36.         push    bc              ; Save sprite address
  37.         ld      hl,0            ; Do y*12
  38.         ld      d,0
  39.         add     hl,de
  40.         add     hl,de
  41.         add     hl,de
  42.         add     hl,hl
  43.         add     hl,hl
  44.         ld      e,a
  45.         srl     e
  46.         srl     e
  47.         srl     e
  48.         add     hl,de
  49.         ld      de,8e29h
  50.         add     hl,de           ; Add address to graphbuf
  51.         ld      b,00000111b     ; Get the remainder of x/8
  52.         and     b
  53.         or a
  54.         jp      z,AALIGN
  55.         pop     ix              ; ix->sprite
  56.         ld      d,a             ; d=how many bits to shift each line
  57.         ld      e,8             ; Line loop
  58. ALILOP: ld      b,(ix+0)        ; Get sprite data
  59.         ld      c,$ff           ; Changed into $FF because of AND bit mask!!!
  60.         scf
  61.         push    de
  62. ASHLOP: rr      b               ;srl
  63.         rr      c
  64.         dec     d
  65.         jp      nz,ASHLOP
  66.         pop     de
  67.         ld      a,b             ; Write line to graphbuf
  68.         and     (hl)
  69.         ld      (hl),a
  70.         inc     hl
  71.         ld      a,c
  72.         and     (hl)
  73.         ld      (hl),a
  74.         ld      bc,11           ; Calculate next line address
  75.         add     hl,bc
  76.         inc     ix              ; Inc spritepointer
  77.         dec     e
  78.         jp      nz,ALILOP       ; Next line
  79.         jp      ADONE1
  80. AALIGN:                         ; Blit an aligned sprite to graphbuf
  81.         pop     de              ; de->sprite
  82.         ld      b,8
  83. AALOP1: ld      a,(de)
  84.         and     (hl)
  85.         ld      (hl),a
  86.         inc     de
  87.         push    bc
  88.         ld      bc,12
  89.         add     hl,bc
  90.         pop     bc
  91.         djnz    AALOP1
  92. ADONE1:
  93.         pop bc                  ;this code is for the memory increment after
  94.         inc bc                  ;displaying.
  95.         inc bc                  ;added by Frank Schoep
  96.         inc bc                  ;MOVAX has nothing to do with it
  97.         inc bc
  98.         inc bc
  99.         inc bc
  100.         inc bc
  101.         inc bc
  102.         ret
  103.  
  104. ; Sprite XOR Routine
  105. ; originally written by MOVAX
  106. ; edited for SPRANDXOR by Frank Schoep
  107. ; Revision: 3
  108.  
  109. ; Routine input:  A is the x coordinate
  110. ;                 E is the y coordinate
  111. ;                 BC as pointer to sprite data
  112. ; Routine output: N/A
  113.  
  114. SPRXOR:
  115.  
  116.         push bc ;for needed for SPRANDXOR
  117.  
  118.         push    bc              ; Save sprite address
  119.         ld      hl,0            ; Do y*12
  120.         ld      d,0
  121.         add     hl,de
  122.         add     hl,de
  123.         add     hl,de
  124.         add     hl,hl
  125.         add     hl,hl
  126.         ld      e,a
  127.         srl     e
  128.         srl     e
  129.         srl     e
  130.         add     hl,de
  131.         ld      de,8e29h
  132.         add     hl,de           ; Add address to graphbuf
  133.         ld      b,00000111b     ; Get the remainder of x/8
  134.         and     b
  135.         or a
  136.         jp      z,ALIGN
  137.         pop     ix              ; ix->sprite
  138.         ld      d,a             ; d=how many bits to shift each line
  139.         ld      e,8             ; Line loop
  140. LILOP:  ld      b,(ix+0)        ; Get sprite data
  141.         ld      c,0             ; Shift loop
  142.         push    de
  143. SHLOP:  srl     b
  144.         rr      c
  145.         dec     d
  146.         jp      nz,SHLOP
  147.         pop     de
  148.         ld      a,b             ; Write line to graphbuf
  149.         xor     (hl)
  150.         ld      (hl),a
  151.         inc     hl
  152.         ld      a,c
  153.         xor     (hl)
  154.         ld      (hl),a
  155.         ld      bc,11           ; Calculate next line address
  156.         add     hl,bc
  157.         inc     ix              ; Inc spritepointer
  158.         dec     e
  159.         jp      nz,LILOP        ; Next line
  160.         jp      DONE1
  161. ALIGN:                          ; Blit an aligned sprite to graphbuf
  162.         pop     de              ; de->sprite
  163.         ld      b,8
  164. ALOP1:  ld      a,(de)
  165.         xor     (hl)
  166.         ld      (hl),a
  167.         inc     de
  168.         push    bc
  169.         ld      bc,12
  170.         add     hl,bc
  171.         pop     bc
  172.         djnz    ALOP1
  173. DONE1:
  174.         pop bc                  ;this code is for the memory increment after
  175.         inc bc                  ;displaying.
  176.         inc bc                  ;added by Frank Schoep
  177.         inc bc                  ;MOVAX has nothing to do with it
  178.         inc bc
  179.         inc bc
  180.         inc bc
  181.         inc bc
  182.         inc bc
  183.         ret
  184.