        MAIN "",134

TRDOS   LD (TRDOS16),IX
        LD (TRDOS1),HL
        LD (TRDOS2),DE
        LD (TRDOS3),BC
        LD (TRDOS4),A
        LD (TRDOS5),SP
        CALL TRDOS6
        LD HL,(#5C3D)
        LD (TRDOS10),HL
TRDOS8  XOR A
        LD (#5D0F),A
        LD (#5D10),A
        LD HL,TRDOS9
        PUSH HL
        LD (#5C3D),SP
        LD HL,#0000
TRDOS1  EQU $-2
        LD DE,#0000
TRDOS2  EQU $-2
        LD BC,#0000
TRDOS3  EQU $-2
        LD A,#00
TRDOS4  EQU $-1
        DI 
        PUSH IY
        LD IY,#5C3A
        CALL #3D13
TRDOS_C EQU $-2
        POP IY
        PUSH BC
        CALL TRDOS6
        POP BC
        POP HL
TRDOS11
        XOR A
        LD HL,#0000
TRDOS10 EQU $-2
        LD (#5C3D),HL
        RET 

TRDOS12 EX (SP),HL
        PUSH AF
        LD A,H
        CP #0D
        JR NZ,TRDOS14
        LD A,L
        CP #6B
        JR Z,TRDOS9
TRDOS14
        LD A,H
        AND A
        JR NZ,TRDOS14_1
        OR L
        CP #10
        JR Z,TRDOS9
TRDOS14_1
        POP AF
        EX (SP),HL
        RET 

TRDOS6
        LD HL,TRDOS13
        LD DE,#5CC2
        LD B,3
TRDOS7
        LD C,(HL)
        LD A,(DE)
        EX DE,HL
        LD (DE),A
        LD (HL),C
        EX DE,HL
        INC HL
        INC DE
        DJNZ TRDOS7
        RET 

TRDOS13 JP TRDOS12

TRDOS9
        LD A,(#5D0F)
        AND A
        RET Z
        LD (IY+0),#FF
        LD SP,#0000
TRDOS5  EQU $-2
        AND A
        CALL #0000
TRDOS16 EQU $-2
        AND A
        JR Z,TRDOS8
        SCF 
        JR TRDOS16-1

FDOS    CALL DOS
        RET 

D_ERR   JP C,FM_EXIT
d_err   PUSH HL
        PUSH DE
        PUSH BC
        CP #14
        JR NZ,D_ERR1
        LD A,7
        JR D_ERR2
D_ERR1  CP #1C
        JR Z,D_ERR1-4
D_ERR2  CP 8
        JR C,D_ERR2_1
        LD A,5
D_ERR2_1
        CALL GET_MSG
        POP BC
        POP DE
        POP HL
        RET 

GET_MSG LD L,A
        LD H,0
        ADD HL,HL
        ADD HL,HL
        LD DE,mess_tab
        ADD HL,DE
        DEFHL1
        LD A,(HL)
        EX DE,HL
        LD DE,_MESS
        LD C,A
        LD B,0
        LDIR 
        EX DE,HL
        LD (HL),#0D
        INC HL
        EX DE,HL
        LD HL,request
        LD BC,req_len
        LDIR 
        LD IX,WError
        CALL Win
        PUSH AF
        CALL RestBack
        POP AF
        CP #FF
        RET NZ
FFF     LD A,1
        RET 

WError  DEFB 10,7,11,6,2*8+7,7,%00001111,0
        DEFW TxtErr       ; объект-текст
        DEFW SelErr       ; объект-подсветка (выборка)
        DEFW HotOv        ; горячие клавиши
        DEFW #FFFF

TxtErr
_MESS   DEFS 55
request
        DB "  Повторить?",13
        DB "  Yep    Nop",13
        DB 0
req_len=$-request

SelErr  DEFB 1,4,4,1,%11
        DEFB 5,4,5,1,%11
        DEFB #FF

mess_tab
        DEFW _mess0
        DEFW _mess1-_mess0
        DEFW _mess1
        DEFW _mess2-_mess1
        DEFW _mess2
        DEFW _mess3-_mess2
        DEFW _mess3
        DEFW _mess4-_mess3
        DEFW _mess4
        DEFW _mess5-_mess4
        DEFW _hmess
        DEFW _ehmess-_hmess
        DEFW _mess5
        DEFW _mess6-_mess5
        DEFW _mess6
        DEFW _mess7-_mess6
        DEFW _mess7
        DEFW _mess8-_mess7

_mess0  DB "  Нет ошибок"       ;)
_mess1  DB "  Нет файла"
_mess2  DB "  Файл есть"
_mess3  DB "  Диск полон"
_mess4  DB " Каталог полон"
_mess5  DB "   Нет диска"
_mess6  DB "    Ошибка!"
_mess7  DB "  Нажат Break"
_mess8  EQU $
_hmess  DB "Хуйня какая-то"
_ehmess EQU $

DOS     PUSH AF
        LD A,(MODE)
        LD (LMODE),A

        LD A,(23798)
        CP 4
        JR Z,DOS7

        LD A,(MODE)
        AND A
        JR Z,DOS1
DOS3    DI 
        XOR A
        LD (#5D0F),A
        EXX 
        LD A,(#5D16)
        AND #03
        LD HL,RAMDR
        CP (HL)
        JR NZ,DOS6
        XOR A
        LD (MODE),A
        EXX 
        JR DOS1

DOS6    CALL L_DRIVE
        CALL DISK
        EXX 
        LD A,(#5D0F)
        AND A
        JR Z,DSK_PR
        CP 7
        JR NZ,DOS5
        LD A,#05
        CP C
        JR Z,DSK_PR1
        LD A,7
        JR DOS4
DOS5    LD A,6
DOS4    AND A
        CALL D_ERR
        EI 
        AND A
        JR Z,DOS3
        JP FM_EXIT

DSK_PR  LD A,#05
        CP C
        JR Z,DSK_PR1
        LD IX,SAVE_L
        JR DOS2

DSK_PR1 LD IX,LOAD_L
        JR DOS2

DOS7    LD IX,RW
;       LD IX,#3D13
        JR DOS2

DOS1    LD IX,#3D13
DOS2    POP AF
        LD (TRDOS_C),IX
        LD IX,D_ERR
ZA      PUSH AF
        CALL TRDOS
        POP AF
        LD A,#00
LMODE   EQU $-1
        LD (MODE),A
        XOR A
        EI 
        RET 

FM_EXIT LD HL,#5CDD
        LD DE,#5CDE
        LD BC,#0F
        LD (HL),0
        LDIR 
        LD A,(LMODE)
        LD (MODE),A
        RestSpp
        SCF 
;       DEC SP
;       DEC SP
        RET 

;       LD HL,(ERR_EXIT)
;       JP (HL)

LOAD_CAT
        LD HL,CAT
        LD DE,#0000
        LD BC,#0905
        CALL DOS_FUNC
        LD HL,CAT+#0800+End_Disk
        HLFHL
        LD (END_DISK),HL
        LD A,(CAT+#0800+All_File)
        LD (ALL_FILE),A
        LD HL,CAT+#0800+Free_Sec
        HLFHL
        LD (FREE_SEC),HL
        RET 

