; old version for BGE - Not used !
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
    if rus
        DEFB #8a,#a8,#e1,#e2,#a8,13;"Кисти",13
        DEFB #90,#a8,#e1,#ae,#a2,#a0,#e2,#ec,13;"Рисовать",13
        DEFB #90,#a5,#a4,#a0,#aa,#e2,#ae,#e0,13;"Редактор",13
        DEFB #8e,#e2,#aa,#e0,#eb,#e2,#ec,#5f,13;"Открыть_",13
        DEFB #91,#ae,#e5,#e0,#a0,#ad,#a8,#e2,#ec,#5f,13;"Сохранить_",13
        DEFB #84,#a8,#e1,#aa,#ae,#a2,#ae,#a4,13;"Дисковод",13
        DEFB 15,13
        DEFB #98,#a0,#a3,": ";"Шаг"
    else
        DEFB "Brush",13
        DEFB "Draw",13
        DEFB "Editor",13
        DEFB "Load_",13
        DEFB "Save_",13
        DEFB "Drive",13
        DEFB 15,13
        DEFB "Step: "
    endif
tbstep  DEFB "0",13
    if rus
        DEFB #8c,#a5,#e2,#ae,#a4,": ";"Метод"
    else
        DEFB "Mode: "
    endif
tbmet   DEFB "Or ",13
    if rus
        DEFB #8f,#a0,#e3,#a7,#a0,0;"Пауза",0
    else
        DEFB "Pause",0
    endif

SBrs   ; DEFB 1,3,7,1,%11  ; del for new gui /DA
       ; DEFB 1,4,7,1,%11
       ; DEFB 1,5,7,1,%11
       ; DEFB 1,6,7,1,%11
       ; DEFB 1,7,7,1,%11
        DB 1,3,7,128+5,%11

      ;  DEFB 1,9,7,1,%11  ; del for new gui /DA
      ;  DEFB 1,10,7,1,%11
        DB 1,9,7,128+2,%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  ; del for new gui /DA
        ; DEFB 1,2,2,1,%11
        ; DEFB 1,3,2,1,%11
        DB 1,1,2,128+3,%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   ; del for new gui /DA
        ; 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
        DB 1,1,1,128+9,%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,ebrs_      ;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
    if rus
        DB "безимениbrs"
    else
        DB "noname  brs"
    endif
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
    call    XX_PUT
        LD HL,Ret
homo1   EQU $-2
        CALL ARW_SCN_
        RET C
      ;LD A,(brstep)
      ;CP 1
      ;JR Z,metbrs
      ;DEC A
      ;LD HL,ARW_X
      ;AND (HL)
      ;LD (HL),A
      ;LD A,(brstep)
      ;DEC A
      ;LD HL,ARW_Y
      ;AND (HL)
      ;LD (HL),A
metbrs  CALL  OR_PUT
        CALL XX_PUT

        CALL ArwBrs2
        JR prtbrs

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

        DS (-$)&7
fbrs    DS 8,#FF


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

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

       ;JP BruPix

; Попиксельная печать спрайта 1x1
; BC - x,y
; HL - адрес спрайта
BruPix
BrsNum=$+1
       LD A,0
       SUB 8
       CP 16
       JP NC,OutPix ;sprite brushes
;chunk brushes
        LD A,C
        AND 7
        LD (shftB),A

       LD A,L
       XOR B
       AND #F8
       XOR B
       LD L,A

        LD A,B
        RRA
        SCF
        RRA
        RRA
        AND #5F
        LD D,A
        XOR C
        AND #07
        XOR C
        RRCA
        RRCA
        RRCA
        LD E,A
        LD A,B
        XOR D
        AND #07
        XOR D
        LD D,A

        LD A,8
i3B     EX AF,AF'
       ;LD B,0
       ;LD C,(HL)
       LD BC,#00FF
shftB=$+1
        LD A,0
        OR A
        JR Z,jmp1B
i1B     SRL C
        RR B
        DEC A
        JR NZ,i1B
jmp1B  LD A,(HL)
       AND C
       LD C,A
       LD A,(HL)
       AND B
       LD B,A
        LD A,(DE)
OPER1B  NOP
        OR C
        LD (DE),A
        INC DE
        LD A,#1F
        AND E
        JR Z,outsc1B
        LD A,(DE)
OPER2B  NOP
        OR B
        LD (DE),A
outsc1B
        DEC DE
        CALL INC_YD
        LD A,D
        CP #58
        RET NC
       LD A,L
       INC A
       XOR L
       AND #07
       XOR L
       LD L,A
        EX AF,AF'
        DEC A
        JR NZ,i3B
        RET

XX_PUT
        LD HL,(OPER1)
        LD (OPER1B),HL
        LD HL,(OPER2)
        LD (OPER2B),HL
        RET

;------------------------------
BrsSel  LD IX,WBrsel
        CALL Win_
        CP #FF
        JP Z,scf
        LD H,0
        LD L,A
    LD (BrsNum),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
    if rus
        DB "Кисть",13
        DB 22,8,3
        DB "Убрать",13
        DB "Инверт",13
        DB "Отмена",13
    else
        DB "Brush",13
        DB 22,8,3
        DB "Clear",13
        DB "Invert",13
        DB "Undo",13
    endif
        DB 0

BrsSell ; DEFB 8,3,4,1,%11  ; del for new gui /DA
        ; DEFB 8,4,4,1,%11
        ; DEFB 8,5,4,1,%11
        DB 8,3,4,128+3,%11
        DEFB #FF

SBrush
    INCBIN "brush.b"

LBrs    EQU $-MBrs
BBuff   NOP

        ENT

       DISPLAY "Brush len   :",/a,LBrs
