        MAIN "",134

BrsPgn
        DISP PgnAdr
MBrs    CALL SV_UNDO
BBrs    LD A,%1111
bbsk    LD SP,(SPP)
        LD IX,WBrs
        LD (IX+6),A
        CALL Win_
        CP #FF
        JP Z,RES_TSK2
        LD BC,TBBrs
        JP TAB_JP

ebrs__  CALL CLOSE
ebrs_   LD A,%1101
        JR bbsk

TBBrs   DW PrtBrs
        DW BEBrs
        DW BrsOpen
        DW BrsSave
        DW BrsDrv
        DW BrsStp
        DW BrsMet

BrsDrv  CALL Driver
        JP ebrs_

WBrs    DEFB 20,2,9,13,6*8,5,%00001111
        DEFB 0
        DEFW TBrs         ; объект-текст
        DEFW SBrs         ; объект-подсветка (выборка)
        DEFW Nil          ; горячие клавиши
        DEFW Nil          ; объект-кнопки (выборка)
        DEFW SwBrs        ; объект-флажки
        DEFW #FFFF

SwBrs   DEFB 5,11,7,0
        DEFW SwBrs_
        DEFB #FF

SwBrs_  LD A,(SwBrs+3)
        AND A
        JR Z,ofha
        LD HL,brhalt
swbrs   LD (homo1),HL
        RET 
ofha    LD HL,Ret
        JR swbrs 

TBrs    DEFB "Кисти",13
        DEFB "Рисовать",13
        DEFB "Редактор",13
        DEFB "Открыть_",13
        DEFB "Сохранить_",13
        DEFB "Дисковод",13
        DEFB 15,13
        DEFB "Шаг: "
tbstep  DEFB "0",13
        DEFB "Метод: "
tbmet   DEFB "And",13
        DEFB "Пауза",0

SBrs    DEFB 1,3,7,1,%11
        DEFB 1,4,7,1,%11
        DEFB 1,5,7,1,%11
        DEFB 1,6,7,1,%11
        DEFB 1,7,7,1,%11

        DEFB 1,9,7,1,%11
        DEFB 1,10,7,1,%11
        DEFB 1,11,7,1,%10
        DEFB #FF

;--- Задание метода ---
BrsMet  LD HL,WBMetK
        CALL PupMnu
        CALL CLOSE_
        CP #FF
        JP Z,ebrs_
        PUSH AF
        ADD A,A
        ADD A,A
        LD BC,TBMetK
        LD H,0
        LD L,A
        ADD HL,BC
        LD DE,tbmet
        LD BC,3
        LDIR 
        POP AF
        LD BC,orpitbr
        CALL TAB_HL
        LD (metbrs+1),HL
        JP ebrs_

orpitbr DW OR_PUT
        DW XOR_PUT
        DW AND_PUT

WBMetK  DEFB 6,11,4,5,7*8,7,%00001110
        DEFB 0
        DEFW TBMetK       ; объект-текст
        DEFW SBMetK       ; объект-подсветка (выборка)
        DEFW #FFFF

TBMetK  DEFB "Or ",13
        DEFB "Xor",13
        DEFB "And",0

SBMetK  DEFB 1,1,2,1,%11
        DEFB 1,2,2,1,%11
        DEFB 1,3,2,1,%11
        DEFB #FF

;--- Задание шага кисти ----
BrsStp  LD HL,WBStep
        CALL PupMnu
        CALL CLOSE_
        CP #FF
        JP Z,ebrs_
        LD (brstep),A
        ADD A,A
        LD BC,TBStep
        LD H,0
        LD L,A
        ADD HL,BC
        LD A,(HL)
        LD (tbstep),A
        JP ebrs_

WBStep  DEFB 0,0,3,11,7*8,7,%00001110
        DEFB 0
        DEFW TBStep       ; объект-текст
        DEFW SBStep       ; объект-подсветка (выборка)
        DEFW #FFFF

TBStep  DEFB "0",13
        DEFB "1",13
        DEFB "2",13
        DEFB "3",13
        DEFB "4",13
        DEFB "5",13
        DEFB "6",13
        DEFB "7",13
        DEFB "8",0

SBStep  DEFB 1,1,1,1,%11
        DEFB 1,2,1,1,%11
        DEFB 1,3,1,1,%11
        DEFB 1,4,1,1,%11
        DEFB 1,5,1,1,%11
        DEFB 1,6,1,1,%11
        DEFB 1,7,1,1,%11
        DEFB 1,8,1,1,%11
        DEFB 1,9,1,1,%11
        DEFB #FF  

;--- Открытие файла ----
BrsOpen LD HL,SORTbrs
        CALL FilerE
        JP C,ebrs_
        LD HL,SBrush
        LD DE,(START_SEC)
        LD BC,#0105
        CALL DOS_FUNC_
        JP C,efnt
        LD DE,FnBrs
        CALL ToName
        JP ebrs_

BrsSave LD HL,FnBrs
        CALL FNEdit
        JP C,ebrs_
        LD HL,FnBrs
        CALL FromName
        LD HL,SBrush
        LD DE,256
        LD BC,#010B
        CALL DOS_FUNC_
        JP ebrs_

FnBrs   DB "безимениbrs"
SORTbrs DB #00,#01,#FF
;--- Рисование --------------
PrtBrs  CALL BrsSel
        CALL CLOSE_
        JP C,ebrs_
managa  CALL prtbrsK
        CALL NormSpd
        CALL SAVESCR
        LD A,ARW_OLD
        CALL GUI
        CALL ReWin
        JP BBrs
prtbrsK LD A,0
brstep  EQU $-1
        AND A
        JR Z,nostp
        LD (SPEED),A
        LD A,1
        LD (LEVEL),A
        LD (STEP),A

nostp   LD HL,ArwBrs1
        LD DE,ArwBrs2
        LD A,ARW_NEW
        CALL GUI
        LD HL,(BrsAdr)
        LD DE,fbrs
        LD BC,8
        LDIR 
        CALL NOKEY_
        CALL LOADSCR
prtbrs  CALL XOR_PUT
        LD HL,Ret
homo1   EQU $-2
        CALL ARW_SCN_
        RET C
metbrs  CALL AND_PUT
        CALL ArwBrs2
        JR prtbrs

brhalt  LD A,PUTARW
        CALL GUI_
        HALT 
        LD A,GETARW
        JP GUI_

ArwBrs1 LD HL,fbrs
        LD BC,(ARW_X)
        LD (ArwXB),BC
        JP OutPix

ArwBrs2 LD HL,fbrs
        LD BC,0
ArwXB   EQU $-2
        JP OutPix

fbrs    DS 8,#FF
;------------------------------
BrsSel  LD IX,WBrsel
        CALL Win_
        CP #FF
        JP Z,scf
        LD H,0
        LD L,A
        ADD HL,HL
        ADD HL,HL
        ADD HL,HL
        LD BC,SBrush
        ADD HL,BC
        LD (BrsAdr),HL
        XOR A
        RET 

BrsAdr  DW 0

WBrsel  DEFB 10,4,17,9,6*8,5,%00001110
        DEFB 0
        DEFW Nil          ; объект-текст
        DEFW Nil          ; объект-подсветка (выборка)
        DEFW Nil
        DEFW BBrsel
        DEFW #FFFF

BBrsel  DB 1,1,1,1,7,%11
        DW SBrush
        DB 3,1,1,1,7,%11
        DW SBrush+8
        DB 5,1,1,1,7,%11
        DW SBrush+16
        DB 7,1,1,1,7,%11
        DW SBrush+24
        DB 9,1,1,1,7,%11
        DW SBrush+32
        DB 11,1,1,1,7,%11
        DW SBrush+40
        DB 13,1,1,1,7,%11
        DW SBrush+48
        DB 15,1,1,1,7,%11
        DW SBrush+56

        DB 1,3,1,1,7,%11
        DW SBrush+64
        DB 3,3,1,1,7,%11
        DW SBrush+72
        DB 5,3,1,1,7,%11
        DW SBrush+80
        DB 7,3,1,1,7,%11
        DW SBrush+88
        DB 9,3,1,1,7,%11
        DW SBrush+96
        DB 11,3,1,1,7,%11
        DW SBrush+104
        DB 13,3,1,1,7,%11
        DW SBrush+112
        DB 15,3,1,1,7,%11
        DW SBrush+120

        DB 1,5,1,1,7,%11
        DW SBrush+128
        DB 3,5,1,1,7,%11
        DW SBrush+136
        DB 5,5,1,1,7,%11
        DW SBrush+144
        DB 7,5,1,1,7,%11
        DW SBrush+152
        DB 9,5,1,1,7,%11
        DW SBrush+160
        DB 11,5,1,1,7,%11
        DW SBrush+168
        DB 13,5,1,1,7,%11
        DW SBrush+176
        DB 15,5,1,1,7,%11
        DW SBrush+184

        DB 1,7,1,1,7,%11
        DW SBrush+192
        DB 3,7,1,1,7,%11
        DW SBrush+200
        DB 5,7,1,1,7,%11
        DW SBrush+208
        DB 7,7,1,1,7,%11
        DW SBrush+216
        DB 9,7,1,1,7,%11
        DW SBrush+224
        DB 11,7,1,1,7,%11
        DW SBrush+232
        DB 13,7,1,1,7,%11
        DW SBrush+240
        DB 15,7,1,1,7,%11
        DW SBrush+248
        DB #FF     

;--- Редактор ---------------
BEBrs   LD A,%1110
bebrs   LD IX,WBrsel
        LD (IX+6),A
        CALL BrsSel
        JP C,ebrs__
        LD DE,BBuff
        LD BC,8
        LDIR 
bbrs    LD SP,(SPP)
        LD HL,TBBrs1
        CALL SPEdit
        EX AF,AF'
        LD A,(But)
        AND A
        JP Z,PrtBrs_
        EX AF,AF'
        CP #FF
        JP Z,ebrs_K
        LD BC,TBEBrs
        JP TAB_JP

PrtBrs_ LD HL,BBuff
        LD DE,(BrsAdr)
        LD BC,8
        LDIR 
        JP managa

ebrs_K  CALL CLOSE
        LD HL,BBuff
        LD DE,(BrsAdr)
        LD BC,8
        LDIR 
        LD A,%1100
        JR bebrs

bbrs_   LD A,%1101
        LD (IX+6),A
        JR bbrs

TBEBrs  DW DelBrs
        DW InvBrs
        DW UndBrs
;-----------------------
UndBrs  LD HL,(BrsAdr)
        LD DE,BBuff
        LD BC,8
        LDIR 
        JR bbrs_

DelBrs  LD HL,BBuff
        LD DE,BBuff+1
        LD BC,7
        LD (HL),B
        LDIR 
        JR bbrs_

InvBrs  LD HL,BBuff
        LD B,8
invbrs  LD A,(HL)
        CPL 
        LD (HL),A
        INC HL
        DJNZ invbrs
        JR bbrs_

TBBrs1  DB #0C,#03       ; X,Y окна
        DB #0D,#08       ; ширина, высота
        DW BBuff         ; адрес спрайта
        DW #0103         ; X,Y окна редактора
        DW #0101         ; размеры спрайта
        DW #0603         ; X,Y preview
        DW BrsText       ; текст
        DW BrsSell       ; подсветка
        DW Nil           ; горячие клавиши

BrsText DB "Кисть",13
        DB 22,8,3
        DB "Убрать",13
        DB "Инверт",13
        DB "Отмена",13
        DB 0

BrsSell DEFB 8,3,4,1,%11
        DEFB 8,4,4,1,%11
        DEFB 8,5,4,1,%11
        DEFB #FF

SBrush
-       INCBIN "brush.b"

LBrs    EQU $-MBrs
BBuff   NOP 

        ENT 

