home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 85 / asm / source / routines / blitt.asm next >
Encoding:
Assembly Source File  |  2001-07-01  |  1.3 KB  |  103 lines

  1. ; SpriteBlitt
  2. ; written by Erik Huizing (ehuizing@acs.ucalgary.ca)
  3. ; plots sprites with masks
  4. ; inputs:
  5. ; hl = sprite data
  6. ; bc = coords
  7. ; outputs:
  8. ; af, bc, de, hl, ix destoryed
  9. ; sprite plotted on screen (with mask)
  10. ;
  11. ; sprite format:
  12. ; .db xSize, ySize
  13. ; .db sprite data
  14. ; .db mask data
  15. ;
  16. ; xSize is the number of bytes wide your sprite is
  17. ; ySize is the height
  18. ;
  19. ; Optimizations:
  20. ; if the mask byte is zero, SpriteBlitt skips to the next byte
  21. ; the mask lookup is faster if your sprite is taller than it is wide
  22.  
  23. SpriteBlitt:
  24.  ld a, 63
  25.  sub c
  26.  ld c, a
  27.  push hl
  28.  CALL ROM_CALL
  29.  .dw FIND_PIXEL
  30.  ld de, VIDEO_MEM
  31.  add hl, de
  32.  pop de
  33.  ex de, hl
  34.  ld b, (hl)
  35.  inc hl
  36.  ld c, (hl)
  37.  inc hl
  38.  push hl
  39.  pop ix
  40.  push bc
  41.  push de
  42.  ld d, 0
  43.  ld e, c
  44.  loop:
  45.  add ix, de
  46.  djnz loop
  47.  pop de
  48.  pop bc
  49.  ex de, hl
  50. vLoop:
  51.  push bc
  52.  push hl
  53. hLoop:
  54.  push bc
  55.  ld b, 8
  56.  ld c, a
  57.  push de
  58.  ld a, (de)
  59.  ld e, a
  60.  ld a, (ix+0)
  61.  or a
  62.  jr nz, bitLoop
  63.  inc hl
  64.  jr noMask
  65. bitLoop:
  66.  rl a
  67.  jr nc, noMaskBit
  68.  bit 7, e
  69.  push af
  70.  ld a, c
  71.  jr z, white
  72.  or (hl)
  73.  jr setPixel
  74. white:
  75.  xor 0xFF
  76.  and (hl)
  77. setPixel:
  78.  ld (hl), a
  79.  pop af
  80. noMaskBit:
  81.  srl c
  82.  jr nc, noReset
  83.  ld c, %10000000
  84.  inc hl
  85. noReset:
  86.  rl e
  87. djnz bitLoop
  88. noMask:
  89. ld a, c
  90. pop de
  91. pop bc
  92. inc de
  93. inc ix
  94. djnz hLoop
  95. pop hl
  96. push de
  97. ld de, 16
  98. add hl, de
  99. pop de
  100. pop bc
  101. dec c
  102. jr nz, vLoop
  103. ret