;Prepare VDP to read VRAM

func_prep_read_vram:

ld a,($fcaf)
cp 7
jr nc,func_prep_read_vram_scr8

call func_prep_read_vram_scr5

func_prep_read_vram_2:

rlc h
rla
rlc h
rla
srl h
srl h
di
out ($99),a
ld a,142
out ($99),a
ld a,l
nop
out ($99),a
ld a,h
ei
out ($99),a

ret

func_prep_read_vram_scr5:

ld a,($faf6)
and 3
cp 1
jr z,func_prep_read_vram_scr5_p1
cp 2
jr z,func_prep_read_vram_scr5_p2
cp 3
jr z,func_prep_read_vram_scr5_p3

ret

func_prep_read_vram_scr5_p1:
xor a
ld de,32768
add hl,de
bit 7,h
ret nz
inc a
ret

func_prep_read_vram_scr5_p2:
ld a,1
ret

func_prep_read_vram_scr5_p3:
ld a,1
ld de,32768
add hl,de
bit 7,h
ret nz
inc a
ret

func_prep_read_vram_scr8:
ld a,($faf6)
jr func_prep_read_vram_2
