
DrawTileMapSprite:
	push af
		ld a,c
		and %00000011
		rlca
		;ld (YShift),a
	pop af
	
	and %00000011
	rlca
	;ld (XShift),a
	

	ld a,VTileMapXoff+HTileMapYoffL 	;X offset
	ld ixl,a

	ld iyh,VTilemapWidth ;Screen End byte
	
	
	ifdef vasm
		ld hl,(LTilemapHeight-VTilemapHeight)*2	;Set Spacer
	else
		ld hl,LTilemapHeight-VTilemapHeight*2	;Set Spacer
	endif
	ld (TileYUnused_Plus2-2),hl

	ld a,(ActiveBank)
	add HTileMapYoffH 
	ld ixh,a		;Top byte of screen address

	ld iyl,VTilemapHeight	;Height (24)


DrawTilesSprite:
	ex de,hl	
	di
	;exx
		;ld c,&80		;used to move down 1 screen line
		
	;exx
	ld c,ixl	;Draw Start Xpos
NextLineS:

	ld b,iyl	;Rows
	ld a,c
	exx
		ld l,a		;L from C (Draw Start L)

		ld c,vdpControl
		
		ld a,ixh	;Draw Start
		ld h,a
		
		ld de,64			;64 bytes per X line
	exx
NextTileS:
	
	ld e,(hl)	;Get Tile Addr
	inc l
	ld d,(hl)
	inc hl
	
	ld a,d
	and e
	inc a
	jr z,CustomTileTranspS	;DE=&FFFF
DrawNormalTileSimpleS:		;For when Transparency isn't needed
	
	exx
		ld a,(HSpriteNum)
		out (vdpControl),a		;LByte
			
		ld a,&3F+&40			;HByte
		out (vdpControl),a
		
		ld a,h
		;ld a,60
		out (vdpData),a
		
		ld a,(HSpriteNum)
		rlca					;2 bytes per tile - 1'st is X, 2nd is tile number
		add &80
		out (vdpControl),a		;LByte
		
		ld a,&3F+&40			;HByte
		out (vdpControl),a
	
		ld a,l					;X Pos
		rlca
		out (vdpData),a
	exx
	ld a,e					;tile number
	out (vdpData),a
	
	ld a,(HSpriteNum)
	inc a
	ld (HSpriteNum),a
	exx
		
CustomTileDoneS:
		ld a,8
		add h
		ld h,a
		
CustomTileDone2S:
	exx
	djnz NextTileS
		

	ld de,(TileYUnused_Plus2-2)
	add hl,de
	
	inc c
	inc c
	inc c
	inc c
	jr z,NextTileDoneS
	
	dec iyh
	jp nz,NextLineS


NextTileDoneS:
	ret

CustomTileTranspS:			;Special tile code (Empty tile)
	exx
	jp CustomTileDoneS
	
	

	