; overworld/sprites.asm

; wDrawSpriteInd - wDrawSpriteFlags
DrawSprite_M:
    ld hl, wOAMBuffer		; ld hl with first sprite addr
    ld bc, $4
    ld a, [wDrawSpriteInd]
    call AddNTimes
    ld a, [wDrawSpriteSize]
    push af			; ld de with size
    and a, %00001111
    ld e, a
    pop af
    rra
    rra
    rra
    rra
    and a, %00001111
    ld d, a
    	;ld a, [wDrawSpriteFlags]	; ld c with flags
    	;ld c, a
    ld a, [wDrawSpritePos]		; ld bc with pos
    ld b, a
    ld a, [wDrawSpritePos+1]
    ld c, a

    push de
    
.colLoop
    push bc
    ld a, [wDrawSpriteFlags]
    bit 1, a
    jr z, .rowLoop
    
    ld a, d
    call MultBy4
    add b
    ld b, a
    
.rowLoop
    ld a, c
    ld [hli], a
    ld a, b
    ld [hli], a
    ld a, [wDrawSpriteGraphic]
    ld [hli], a
    inc a
    ld [wDrawSpriteGraphic], a
    
    
    ld a, [wDrawSpriteFlags]
    bit 1, a
    ld a, b
    jr z, .add8
.sub8
    push af
    ld a, $20
    ld [hli], a
    pop af
    sub 8
    jr .rejoin
.add8    
    push af
    xor a
    ld [hli], a
    pop af
    add 8
.rejoin
    ld b, a
    dec d
    jr nz, .rowLoop
    pop bc
    dec e
    jr z, .done
    ld a, e
    pop de
    push de
    ld e, a
    ld a, 8
    add a, c
    ld c, a
    jr .colLoop
.done
    pop de
    ret