Geekboy

Untitled

Oct 21st, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DrawClippedSprite:  ;D=X E=Y A=spriteID. Allows negative numbers to an extent.
  2. ;screen dimensions are 64x64 pixels
  3.  rrca
  4.  rrca  ;%11000000 get
  5.  ld c,a
  6.  ld a,d
  7.  and %00000111
  8.  ld b,a  ;save for getting mask address
  9.  add a,a
  10.  add a,a
  11.  add a,a ;x8 %00111000
  12.  add a,c ;merge to get correct sprite position
  13.  ld c,a  ;position saved
  14.  ld a,b
  15.  add a,8 ;getting spritemask position
  16.  ld h,$40
  17.  ld L,a
  18.  ld b,(hl) ;B=spritemask
  19. Getbfraddr:
  20.  ld h,$00
  21.  ld a,e
  22.  sla ;x2
  23.  sla ;x4
  24.  ld l,a
  25.  add hl,hl ; sets xpos on buffer into hl
  26.  srl d
  27.  srl d
  28.  srl d ;*8
  29.  ld a,e    ; used for alignment later on needs to be preserved here
  30.  ld e,d
  31.  ld d,0
  32.  add hl,de
  33.  ld de,$8000
  34.  add hl,de ;leaves HL as the position on the buffer
  35. Getspraddr:
  36.  ld d,$87
  37.  ld e,c
  38.  push de
  39.  pop ix    ;put sprite into ix
  40.  ld e,b  ;put mask into e
  41. Draw:
  42.  and 7
  43.  jp z,_aligned
  44. _Dloop:
  45.  ld a,(ix)  ;load a with ix
  46. ; or e       ;or with mask @@ we do not mask here not off side of screen
  47.  ld c,(hl)  ;ld c with screen
  48.  or c       ;or with screen
  49.  ld (hl),c  ;draw to screen
  50.  inc l      ;inc to next byte for alignment
  51.  
  52. _alinged:
  53.  
  54.  ld a,(ix)  ;load a with ix
  55.  or e       ;or with mask
  56.  ld c,(hl)  ;ld c with screen
  57.  or c       ;or with screen
  58.  ld (hl),c  ;draw to screen
  59.  
  60.  ld de,8    ;move to next row
  61.  add hl,de
  62.  ret c      ;ret if off screen
  63.  djnz _dloop
  64.  ret         ;done
Advertisement
Add Comment
Please, Sign In to add comment