Here's the code:
the code for drawing one double line of the 32x16 tiles looks something like this:
; in hl is the address of a table with screen addreses of each line of the tile where I should start pushing to
ld sp,hl
pop de
inc l
inc l
; now in de is the screen address where to push to
ex de,hl
ld sp,hl
exx:push bc:push af:push af:push af:push af:push bc:exx
set 3,h
ld sp,hl
exx:push bc:push af:push af:push af:push af:push bc:exx
ex de,hl
The code for restoring one double line of the bg behind the player sprite:
; bc is &0010 which is equal to width of the sprite in bytes
; get the line address from the table of line addreses held in hl
; there is a procedure to calculate the addreses of each line of the sprite
push hl
ld a,(hl)
inc l
ex af,af'
ld a,(hl)
ld h,a
ex af,af'
ld l,a
add hl,bc
ex de,hl
ld (@isrbg_SaveSP1+1),sp
ld sp,hl
; pop data from buffer (8 words = 32 pixels = sprite width)
pop ix:pop iy:pop bc:pop af:ex af,af':exx:pop af:pop bc:pop de:pop hl:exx
ex de,hl
ld sp,hl
; push data to screen (odd lines)
exx:push hl:push de:push bc:push af:ex af,af':push af:exx:push bc:push iy:push ix
set 3,h
ld sp,hl
; push data to screen (even lines)
exx:push hl:push de:push bc:push af:ex af,af':push af:exx:push bc:push iy:push ix
;; correct the scrren and buffer offsets (de and hl - add sprite width in bytes)
ld bc,&0010
ex de,hl
add hl,bc
ex de,hl
@isrbg_SaveSP1
ld sp,0
pop hl
inc l
inc l
The code for saving a double line of the bg:
;bc=&0010 = sprite width in bytes
;get the line address from table held in hl
push hl
ld a,(hl)
inc l
ex af,af'
ld a,(hl)
ld h,a
ex af,af'
ld l,a
ex de,hl
add hl,bc
ex de,hl
ld (@ssbg20l_SaveSP1+1),sp
ld sp,hl
; pop data from buffer (8 words = 32 pixels = sprite width)
pop ix:pop iy:pop bc:pop af:ex af,af':exx:pop af:pop bc:pop de:pop hl:exx
ex de,hl
ld sp,hl
; push data to screen (odd lines)
exx:push hl:push de:push bc:push af:ex af,af':push af:exx:push bc:push iy:push ix
; correct the scrren and buffer offsets (de and hl - add sprite width in bytes)
ld bc,&0010
ex de,hl
add hl,bc
@ssbg20l_SaveSP1
ld sp,0
pop hl
inc l
inc l