;play *.tfd
macro INCHL
inc l
call z,INCH
endm
INCH
inc h
ret nz
ld h,0xc0
push af
push bc
ld a,(tfdplay_pg)
inc a
ld (tfdplay_pg),a
ld c,a
ld b,tpgs/256
ld a,(bc)
SETPGC000
pop bc
pop af
ret
skipstr
xor a
ld b,a
ld c,a ;чтобы точно найти терминатор
cpir ;найдём обязательно, если длина=0, то bc=-1 и т.д.
ret
tfd_ini
xor a
ld (tfdplay_pg),a
ld c,a
ld b,tpgs/256
ld a,(bc)
SETPGC000
LD HL,0xc000;tfmData
ld a,(hl)
cp 'T'
ret nz;jr nz,tfd_ini_noheader
inc hl
ld a,(hl)
cp 'F'
ret nz;jr nz,tfd_ini_noheader
inc hl
ld a,(hl)
cp 'M'
ret nz;jr nz,tfd_ini_noheader
inc hl
ld a,(hl)
cp 'D'
ret nz;jr nz,tfd_ini_noheader
inc hl
call skipstr
call skipstr
call skipstr
ld (tfdplay_addr),hl
;tfd_ini_noheader
ret
tfd_play
;a = port bd77 value
di
push af
and 0xf7;0xa0;%10101000 ;320x200 mode noturbo
ld bc,0xbd77 ;shadow ports and palette remain on
out (c),a
call tfd_playPP
pop af
;LD A,0xa8;%10101000 ;320x200 mode
ld bc,0xbd77 ;shadow ports and palette remain on
out (c),a
ei
ret
tfd_playPP
tfdplay_wait=$+1
ld a,0
or a
jr z,tfd_play_nowait
dec a
ld (tfdplay_wait),a
ret
tfd_play_nowait
tfdplay_pg=$+1
ld c,0
ld b,tpgs/256
ld a,(bc)
SETPGC000
tfdplay_addr=$+1
ld hl,0xc000
LD DE,#FFBF
LD C,#FD
CALL selChip0
parse0
LD A,(HL)
CP D ;0xff
JR NZ,parse1
;команда 0xff - новый кадр
;HALT
;out (0),a
INCHL
;CALL selChip0
parse0q
ld (tfdplay_addr),hl
ret
parse1
CP #FC
JR NZ,parse2
CALL selChip0
INCHL
JR parse0
parse2
CP #FD
JR NZ,parse3
CALL selChip1
INCHL
JR parse0
parse3
CP #FB
JR NZ,parse4
;loop
loopPos_pg=$+1
ld a,0
ld (tfdplay_pg),a
ld c,a
ld b,tpgs/256
ld a,(bc)
SETPGC000
loopPos_addr=$+1
LD HL,0xc000;tfmData
JP parse0 ;q???
parse4
CP #FA
JR NZ,parse5
;set loop
INCHL
ld a,(tfdplay_pg)
ld (loopPos_pg),a
LD (loopPos_addr),HL
JP parse0
parse5
CP #FE
JR NZ,parse6
INCHL
LD a,(HL)
;INC B
;INC B
;INC B
add a,2;3
ld (tfdplay_wait),a
;HALT
;DJNZ $-1 ;TODO
INCHL
;CALL selChip0
JP parse0q
parse6
LD B,D
WaitStatus
LD A,(HL)
OUT (C),A
INCHL
LD B,E
WaitStatus
LD A,(HL)
OUT (C),A
INCHL
jp parse0
if 0
selChip0
LD B,D
LD A,#FB;D
OUT (C),A
RET
selChip1
LD B,D
LD A,#FA;#FE
OUT (C),A
RET
endif
align 256
tpgs
ds 256
;tfmData
;INCBIN "ddd.t"