PageGUI  EQU 3
BeginGUI EQU #C800

        ORG #6128

        INCLUDE "GuiVar",#40
        INCLUDE "ResGUI",#08

TEST    EQU 2

Runner  LD A,PageGUI+#10
        LD (GUI_PAGE),A
        LD A,4+#10
        LD (STORE_PAGE),A
        LD A,#10
        LD (S_PAGE),A
        LD HL,Resident
        LD (ResAdr),HL

        CALL AUTOCONF
        LD A,LOAD_CAT
        CALL GUI

        LD HL,0
        LD (total),HL
        LD HL,(END_DISK)
        LD (TEK_SEC),HL
        CALL INI_BUFF

        LD B,200
dnz3    PUSH BC
        LD HL,dbsym
        LD B,4
        CALL ADD_BYTES
        LD B,7
dnz2    PUSH BC
        CALL GADR
        LD A,(HL)
        LD DE,bytsym1
        PUSH DE
        CALL CONV
        POP HL
        LD B,4
        CALL ADD_BYTES
        POP BC
        DJNZ dnz2
        CALL GADR
        LD A,(HL)
        LD DE,bytsym2
        PUSH DE
        CALL CONV
        POP HL
        LD B,4
        CALL ADD_BYTES
        POP BC
        DJNZ dnz3
        LD A,0          ; добавить конец диска
        CALL ADD_BYTE
        CALL Flush      ; сбросили остаток буфера
        CALL ClFile
        RET 

ClFile  LD HL,FNAME
        LD DE,23773
        LD BC,11
        LDIR 
        LD HL,#4000
        LD DE,(total)
        PUSH DE
        DEC DE
        INC D
        LD B,D
        POP DE
        LD C,#FF
        LD A,DOS_FUNC
        CALL GUI
        RET 

FNAME   DB "flush3  COD"

GADR    LD HL,0
        PUSH HL
        INC HL
        LD (GADR+1),HL
        POP HL
        RET 

ADD_BYTES
dnz1    PUSH BC
        PUSH HL
        LD A,(HL)
        CALL ADD_BYTE
        POP HL
        INC HL
        POP BC
        DJNZ dnz1
        RET 

ADD_BYTE
        LD HL,(badr)
        LD (HL),A
        INC HL
        LD (badr),HL
        LD HL,(total)
        INC HL
        LD (total),HL
        LD HL,(bbyte)
        INC HL
        LD (bbyte),HL
        LD DE,lbuff
        AND A
        SBC HL,DE
        CALL Z,FLUSH
        RET 

Flush   LD HL,(bbyte)
        LD A,H
        OR L
        RET Z
        JR FLUSH

FLUSH   LD A,7
        OUT (#FE),A
        XOR A
        OUT (#FE),A
        LD HL,buffer
        LD DE,(TEK_SEC)
        LD B,'lbuff
        LD C,#06
        LD A,DOS_FUNC
        CALL GUI
        CALL INI_BUFF
        RET 

INI_BUFF:
        LD HL,buffer
        LD (badr),HL
        LD HL,0
        LD (bbyte),HL
        RET 

CONV    LD C,0
        EX AF,AF'
        LD A,GET_NUM
        JP GUI

total   DW 0             ; сколько всего байтов файл
lbuff   EQU 256
dbsym   DB #09,"DB "
bytsym1 DB "000,"
bytsym2 DB "000",13,10
bbyte   DW 0
badr    DW buffer
buffer  DS lbuff

        ORG Runner

