Geekboy

Untitled

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