Geekboy

Untitled

Oct 21st, 2011
138
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.  jp $
  4.  rrca
  5.  rrca  ;%11000000 get
  6.  ld c,a
  7.  ld a,d
  8.  and %00000111
  9.  ld b,a  ;save for getting mask address
  10.  add a,a
  11.  add a,a
  12.  add a,a ;x8 %00111000
  13.  add a,c ;merge to get correct sprite position
  14.  ld c,a  ;position saved
  15.  ld a,b
  16.  add a,8 ;getting spritemask position
  17.  ld h,$40
  18.  ld L,a
  19.  ld b,(hl) ;B=spritemask
  20. Getbfraddr:
  21.  ld a,e
  22.  add a,a
  23.  ld l,a
  24.  sbc a,a
  25.  ld h,a
  26.  add hl,hl
  27.  add hl,hl
  28.  ld a,d
  29.  ld d,e
  30.  add a,a
  31.  add a,a
  32.  add a,a  ;*8
  33.  ld e,a  
  34.  ld a,d   ; used for alignment later on needs to be preserved here
  35.  ld d,$80
  36.  add hl,de ;leaves HL as the position on the buffer
  37. Getspraddr:
  38.  ld e,b  ;put mask into e
  39.  ld b,$87
  40.  push bc
  41.  pop ix    ;put sprite into ix
  42.  ;we have bc free
  43.  
  44.  ld b,8
  45. Draw:
  46.  and 7
  47.  jp z,_aligned
  48.  ld a,e
  49.  cpl
  50.  ld c,a
  51. _Unaligned:
  52.  bit 1,h
  53.  jp nz,_skipd
  54.  ld a,e
  55.  cpl
  56.  ld c,a
  57.  ld a,(ix)  ;load a with ix
  58.  
  59.  and c
  60.  or (hl)    ;or with screen
  61.  ld (hl),a  ;draw to screen
  62.  inc hl      ;inc to next byte for alignment
  63.  inc ix
  64.  ld a,(ix)  ;load a with ix
  65.  and e       ;or with mask
  66.  or (hl)    ;or with screen
  67.  ld (hl),a  ;draw to screen
  68.  inc ix
  69.  ld de,7    ;move to next row
  70.  add hl,de
  71.  
  72. _skipd:
  73.  djnz _Unaligned
  74.  ld ix,$8eeC
  75.  ret         ;done
  76.  
  77. _aligned:
  78.  bit 1,h
  79.  jp nz,__skipd
  80.  ld a,(ix)  ;load a with ix
  81.  or (hl)    ;or with screen
  82.  ld (hl),a  ;draw to screen
  83.  inc ix
  84.  ld de,8    ;move to next row
  85.  add hl,de
  86. __skipd:
  87.  djnz _aligned
  88.  ld ix,$8eeC
  89.  ret         ;done
Advertisement
Add Comment
Please, Sign In to add comment