Geekboy

Untitled

Oct 21st, 2011
133
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.  add a,a
  23.  add a,a ;x4
  24.  ld l,a
  25.  add hl,hl ; sets xpos on buffer into hl
  26.  ld a,d
  27.  ld d,e
  28.  add a,a
  29.  add a,a
  30.  add a,a  ;*8
  31.  ld e,a  
  32.  ld a,d   ; used for alignment later on needs to be preserved here
  33.  ld d,$80
  34.  add hl,de ;leaves HL as the position on the buffer
  35. Getspraddr:
  36.  ld e,b  ;put mask into e
  37.  ld b,$87
  38.  push bc
  39.  pop ix    ;put sprite into ix
  40.  ld b,8
  41. Draw:
  42.  and 7
  43.  jp z,_aligned
  44. _Unaligned:
  45.  ld a,(ix)  ;load a with ix
  46.  or (hl)    ;or with screen
  47.  ld (hl),a  ;draw to screen
  48.  inc l      ;inc to next byte for alignment
  49.  
  50.  ld a,(ix)  ;load a with ix
  51.  or e       ;or with mask
  52.  or (hl)    ;or with screen
  53.  ld (hl),a  ;draw to screen
  54.  
  55.  ld de,8    ;move to next row
  56.  add hl,de
  57.  ret c      ;ret if off screen
  58.  djnz _Unaligned
  59.  ret         ;done
  60.  
  61. _alinged:
  62.  
  63.  ld a,(ix)  ;load a with ix
  64.  or e       ;or with mask
  65.  or (hl)    ;or with screen
  66.  ld (hl),a  ;draw to screen
  67.  
  68.  ld de,8    ;move to next row
  69.  add hl,de
  70.  ret c      ;ret if off screen
  71.  djnz _aligned
  72.  ret         ;done
Advertisement
Add Comment
Please, Sign In to add comment