Skip to content

Instantly share code, notes, and snippets.

@jacobly0
Last active September 7, 2016 02:06
Show Gist options
  • Save jacobly0/906014af70e7b02dede15c1f2d9bfd87 to your computer and use it in GitHub Desktop.
Save jacobly0/906014af70e7b02dede15c1f2d9bfd87 to your computer and use it in GitHub Desktop.
GetSprite
;-------------------------------------------------------------------------------
_GetSprite:
; Grabs the data from the current draw buffer and stores it in another buffer
; Arguments:
; arg0 : Pointer to storage buffer
; arg1 : X Coord
; arg2 : Y Coord
; Returns:
; Pointer to resultant sprite
ld iy,0
add iy,sp
ld bc,(iy+9)
bit 0,b
ld b,lcdWidth/2
mlt bc
ld hl,(currDrawBuffer)
add hl,bc
add hl,bc
jr z,_
ld de,-lcdWidth*256
add hl,de
_: ld de,(iy+6)
add hl,de
ld de,(iy+3)
push de
ld a,(de)
inc de
ld (GetSprCpyAmt),a \.r
ld c,a
ld a,lcdWidth&$ff
sub a,c
ld c,a
sbc a,a
inc a
ld b,a
ld (GetSprLineOff+1),bc \.r
ld a,(de)
inc de
GetSprCpyAmt =$+1
_: ld bc,0
ldir
GetSprLineOff =$+1
ld bc,0
add hl,bc
dec a
jr nz,-_
pop hl
ret
@mateoconlechuga
Copy link

GetSprLineOff+1 should be GetSprLineOff, but other than that, everything works great. I really like that neat thing where you subtract -lcdWidth*256, since sprites can't be larger than that. Very nicely done. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment