
BoxPgn
        DISP PgnAdr

EBOX    LD A,%1111
ebox    LD IX,WBox
        LD (IX+6),A
        CALL Win_
        CP #FF
        JP Z,RES_TSK2
        LD HL,Set_box
more1   LD (set_box+1),HL
        PUSH AF
        CALL NOKEY_
        POP AF
        LD BC,TBBox
        JP TAB_JP

ebox_   CALL CLOSE
        LD A,%1101
        JR ebox

TBBox   DW Tek_Box
        DW Cls_Box
        DW Inv_Box
        DW Inc_Box
        DW Rev_Box
        DW Cop_Box
        DW Co_Box
        DW Pag_Box
        DW Mod_Box

ChBox   CALL ResDBox
        CALL SAVESCR
        LD A,%1111
        LD IX,WBox
        LD (IX+6),A
        CALL Win_
        CP 8
        JP Z,Mod_Box
        CALL CLOSE_
        CP #FF
        JP Z,RES_TSK4
        LD SP,(SPP)
        LD HL,SEt_box
        JR more1

pagbox  LD DE,(ARW_XC)
        CALL RASCH_
        PUSH HL
        LD A,H
        OR #C0
        LD H,A
        CALL RAM7
        LD B,8
        LD DE,boxbuf
        CALL djnz10
        CALL RAM0
        POP HL
        LD B,8
        LD DE,boxbuf
        CALL restcop
        RET

Cop_Box XOR A
        LD (cfbox),A
        LD HL,copbox
        JP set_box

Co_Box  XOR A
        LD (cfbox),A
        LD HL,cobox
        JP set_box

cobox   LD DE,(ARW_XC)
        CALL RASCH_
        LD B,8
        LD DE,boxbuf
        LD A,(cfbox)
        AND A
        JR Z,cobox_
        JR restcop
cobox_  LD A,1
        LD (cfbox),A
        JR djnz10

copbox  LD DE,(ARW_XC)
        CALL RASCH_
        LD B,8
        LD DE,boxbuf
        LD A,0
cfbox   EQU $-1
        CPL
        LD (cfbox),A
        AND A
        JR Z,restcop
djnz10  LD A,(HL)
        LD (DE),A
        INC H
        INC DE
        DJNZ djnz10
        RET

restcop LD A,(DE)
mbox    NOP
        LD (HL),A
        INC H
        INC DE
        DJNZ restcop
        RET

boxbuf  DS 8

revbox  CALL inbox
icbox   LD DE,(ARW_XC)
        CALL RASCHA
        LD A,(HL)
        AND #C0
        LD C,A
        LD A,(HL)
        PUSH AF
        AND #07
         SLA A
         SLA A
         SLA A
        LD D,A
        POP AF
        AND #38
         SRA A
         SRA A
         SRA A
        OR D
        OR C
        LD (HL),A
        RET

inbox   LD DE,(ARW_XC)
        CALL RASCH_
        LD B,8
djnz9   LD A,(HL)
        CPL
        LD (HL),A
        INC H
        DJNZ djnz9
        RET

clbox   LD DE,(ARW_XC)
        CALL RASCH_
        LD B,8
        XOR A
djnz8   LD (HL),A
        INC H
        DJNZ djnz8
        RET

Pag_Box LD HL,pagbox
        JR set_box

Rev_Box LD HL,revbox
        JR set_box

Cls_Box LD HL,clbox
        JR set_box

Inv_Box LD HL,inbox
        JR set_box

Inc_Box LD HL,icbox
        JR set_box

set_box JP Set_box

Tek_Box LD HL,mtbox
Set_box PUSH HL
        CALL SV_UNDO
        CALL LOADSCR
        POP HL
SEt_box LD (boxmode),HL
        CALL ReOLDXY
        LD HL,#FFFF
        LD (NEW_XY),HL
        LD (TSP),SP
tek_box LD HL,IntBox
        CALL ARW_SCN_
        CALL ResDBox
        JP C,RES_TSK4
        LD HL,(NEW_XY)
        LD DE,(ARW_XC)
        AND A
        SBC HL,DE
        JR Z,was
        LD HL,(ARW_XC)
        LD (NEW_XY),HL
        LD DE,(ARW_XC)
        CALL RASCHA
        CALL 0
boxmode EQU $-2
was     LD A,STOP_ARW
        CALL GUI
        JP tek_box

mtbox   LD A,(HL)
        CALL MIXCOL
        LD (HL),A
        RET

BoxRgb  CALL ResDBox
        CALL PRGB2
mudak   CALL NOKEY_
        LD SP,0
TSP     EQU $-2
        JP tek_box

SwpBox  CALL ResDBox
        CALL SAVESCR
        CALL swapscr
        CALL SV_UNDO
        JR mudak

IntBox  LD A,REDEF
        CALL GUI_
        LD A,(KEY1)
        CP "L"
        JR Z,SwpBox
        CP "C"
        JR Z,BoxRgb
        CP "J"
        JP Z,ChBox
        CP "K"
        CALL Z,Col

        LD A,(DIRECT)
        AND #10
        JR Z,was3
        LD HL,(NEW_XY)
        LD DE,(ARW_XC)
        AND A
        SBC HL,DE
        JR Z,was2
was3    LD HL,#FFFF
        LD (NEW_XY),HL
was2    LD HL,(OLD_XY)
        LD DE,(ARW_XC)
        AND A
        SBC HL,DE
        RET Z
        PUSH DE
        CALL ResDBox
        POP DE
        CALL DrwBox
        LD HL,(ARW_XC)
        LD (OLD_XY),HL
        RET

ResDBox PUSH AF
        LD HL,(OLD_XY)
        LD DE,#FFFF
        AND A
        SBC HL,DE
        LD DE,(OLD_XY)
        CALL NZ,DrwBox
        LD HL,#FFFF
        LD (OLD_XY),HL
        POP AF
        RET

DrwBox  CALL RASCH_
        LD A,(HL)
        XOR %11111111
        LD (HL),A
        INC H
        LD B,6
djnz7   LD A,(HL)
        XOR %10000001
        LD (HL),A
        INC H
        DJNZ djnz7
        LD A,(HL)
        XOR %11111111
        LD (HL),A
        RET

WBox    DEFB 20,2,11,14,5*8,5,%00001111
; Bit 0 - окно с заголовком/без
; Bit 1 - "перерисовать" окно да/нет
; Bit 2 - тискать окно по экрану да/нет
; Bit 3 - выход из окна-ткнуть только лишь за пределами (CANCEL)
        DEFB 0
        DEFW TBox         ; объект-текст
        DEFW SBox         ; объект-подсветка (выборка)
        DEFW #FFFF

TBox
;    if rus                    ; удалил из-за другого способа локализации /DA
;        DB #9f,#e7,#a5,#a9,#aa,#a8," 8x8",13;Ячейки
;        DB #92,#a5,#aa,#e3,#e9,#a8,#a9,#20,#e6,#a2,#a5,#e2,13;"Текущий цвет",13
;        DB #93,#a4,#a0,#ab,#A8,#e2,#ec,13;"Удалить",13
;        DB #88,#ad,#a2,#a5,#e0,#e2,#a8,#e0,#ae,#a2,#a0,#e2,#ec,13;"Инвертировать",13
;        DB #88,#ad,#a2,#a5,#e0,#e2,#a8,#e0,#ae,#a2,#a0,#e2,#ec,'+',13;"Инвертировать+",13
;        DB #90,#a5,#a2,#a5,#e0,#e1,13;"Реверс",13
;        DB #91,#aa,#ae,#af,#a8,#e0,#Ae,#a2,#A0,#e2,#ec,13;"Скопировать",13
;        DB #91,#aa,#ae,#af,#a8,#e0,#Ae,#a2,#A0,#e2,#ec,#2b,13;"Скопировать+",13
;        DB #91,#e2,#e0,#a0,#ad,#a8,#e6,#a0,13;"Страница",13
;        DB 15,13
;        DB #90,#a5,#a6,#a8,#ac,':';Режим: "
;    else
;        DB "Cells",13
;        DB "Current color",13
;        DB "Clear",13
;        DB "Invert",13
;        DB "Invert+",13
;        DB "Reverse",13
;        DB "Copy cell",13
;        DB "Copy cell+",13
;        DB "Screen 2",13
;        DB 15,13
;        DB "Mode: "
;    endif

        MSG_BOX_Head : DB 13
        MSG_BOX_CurrCol : DB 13
        MSG_BOX_Clear : DB 13
        MSG_BOX_Inv : DB 13
        MSG_BOX_InvP : DB 13
        MSG_BOX_Reverse : DB 13
        MSG_BOX_Copy : DB 13
        MSG_BOX_CopyP : DB 13
        MSG_BOX_Scr2 : DB 13
        DB 15,13
        MSG_BOX_Mode : DB " "

TmBox   DB "Put",0

SBox    ; DEFB 1,3,9,1,%11
        ; DEFB 1,4,9,1,%11
        ; DEFB 1,5,9,1,%11
        ; DEFB 1,6,9,1,%11
        ; DEFB 1,7,9,1,%11
        ; DEFB 1,8,9,1,%11
        ; DEFB 1,9,9,1,%11
        ; DEFB 1,10,9,1,%11
        DB 1,3,9,128+8,%11
        DEFB 1,12,9,1,%11
        DEFB #FF

Mod_Box LD HL,WMBox
        CALL PupMnu
        CP #FF
        JP Z,ebox_
        PUSH AF
        ADD A,A
        ADD A,A
        LD H,0
        LD L,A
        LD BC,TMBox
        ADD HL,BC
        LD DE,TmBox
        LD BC,3
        LDIR
        POP AF
        LD H,0
        LD L,A
        LD BC,EFSB
        ADD HL,BC
        LD A,(HL)
        LD (mbox),A
        JP ebox_

EFSB    DB #00
        DB #B6
        DB #AE
        DB #A6

WMBox   DEFB 20,2,4,6,7*8,7,%00001110
; Bit 0 - окно с заголовком/без
; Bit 1 - "перерисовать" окно да/нет
; Bit 2 - тискать окно по экрану да/нет
; Bit 3 - выход из окна-ткнуть только лишь за пределами (CANCEL)
        DEFB 0
        DEFW TMBox        ; объект-текст
        DEFW SMBox        ; объект-подсветка (выборка)
        DEFW #FFFF

TMBox   DB "Put",13
        DB "Or ",13
        DB "Xor",13
        DB "And",0

; x, y, длина, высота, флаг
; bit 0 - подсвечивать (да/нет)
; bit 1 - клавиша "заморожена"

SMBox   ; DEFB 1,1,2,1,%11
        ; DEFB 1,2,2,1,%11
        ; DEFB 1,3,2,1,%11
        ; DEFB 1,4,2,1,%11
        DB 1,1,2,128+4,%11
        DEFB #FF

PREPARATION:
        CALL    COORDS_EXCHANGE
EL_PRE01 LD      A,B
        ADD     A,D
        RRA
        LD      B,A
        LD      A,C
        ADD     A,E
        RRA
        LD      C,A
        LD      A,D
        SUB     B
        JR      Z,L49847
        DEC     A
L49847  LD      D,A
        LD      A,E
        SUB     C
        JR      Z,L49853
        DEC     A
L49853  LD      E,A
        RET

COORDS_EXCHANGE:

        LD      A,D
        CP      B
        JR      NC,C_EX01
        LD      D,B
        LD      B,A
C_EX01  LD      A,E
        CP      C
        RET     NC
        LD      E,C
        LD      C,A
        RET

ELLIPSE_BODY:
        LD      A,E
        CP      D
        JR      Z,CIRCLE_BODY
        JR      C,L51118

        LD      HL,L51085
        LD      E,D
        LD      D,A
        LD      (L51282),HL
        LD      HL,L51091
        JR      L51_2

L51118  LD      HL,L51091
        LD      (L51282),HL
        LD      HL,L51085

L51_2   LD      (L51179),HL
        LD      (L51318),HL
        LD      L,E
        LD      E,D
        CALL    L51060
        LD      A,205           ; CALL nn
        JR      L51143

CIRCLE_BODY:
        LD      D,A
        LD      A,33            ; LD HL,nn
L51143  LD      (L51178),A
        LD      (L51281),A
        LD      (L51317),A
        LD      A,D
        OR      A
        JP      Z,L50071
        INC     A
        LD      (L51279),BC
        LD      (L51293),BC
        LD      (L51315),BC
        LD      (L51329),BC
        LD      LX,A
        DEC     A
        LD      E,A
        PUSH    IX

L51178  LD      HL,L51091 ; CALL    L51091
L51179  EQU     $-  2

        POP     IX
        LD      A,D
        ADD     A,B
        LD      B,A
        CALL    L50071
        LD      A,B
        SUB     D
        SUB     D
        LD      B,A
        CALL    L50071
        LD      A,B
        ADD     A,D
        LD      B,A
        LD      A,C
        ADD     A,E
        LD      C,A
        CALL    L50071
        LD      A,C
        SUB     E
        SUB     E
        LD      C,A
        CALL    L50071
        LD      D,0
        LD      H,D
        LD      L,D
        LD      E,LX
        LD      IX,255
L51222  INC     D
        LD      C,D
        LD      B,0
        ADD     HL,BC
        LD      A,H
        ADD     A,A
        JR      NZ,L51222
        PUSH    HL
        ADD     HL,HL
        ADD     HL,HL
        XOR     A
        LD      B,A
        LD      C,E
        SBC     HL,BC
        POP     HL
        JR      C,L51222
        LD      B,0
        LD      C,E
        SBC     HL,BC
        DEC     E
        PUSH    HL
        CALL    L51261
        POP     HL
        LD      LX,D
        XOR     A
        XOR     HX
        JR      Z,L51222
        RET
L51261  INC     LX
        LD      A,LX
        CP      E
        JR      Z,L51275
        LD      A,E
        CP      D
        JR      NC,L51275
        LD      HX,D
        RET
L51275  PUSH    DE
        PUSH    IX
        LD      BC,18774
L51279  EQU     $-  2
L51281  LD      HL,L51085 ; CALL    L51085
L51282  EQU     $-  2
        LD      A,B
        ADD     A,E
        LD      B,A
        PUSH    DE
        CALL    L50656
        POP     DE
        LD      BC,18774
L51293  EQU     $-  2
        LD      A,B
        SUB     E
        LD      B,A
        CALL    L50656
        POP     IX
        POP     DE
        LD      A,D
        CP      E
        JR      NZ,L51311
        CP      LX
        RET     Z
L51311  PUSH    DE
        PUSH    IX
        LD      BC,18774
L51315  EQU     $-  2
L51317  LD      HL,L51091 ; CALL    L51091
L51318  EQU     $-  2
        LD      A,C
        ADD     A,E
        LD      C,A
        PUSH    DE
        CALL    L50757
        POP     DE
        LD      BC,18774
L51329  EQU     $-  2
        LD      A,C
        SUB     E
        LD      C,A
        CALL    L50757
        POP     IX
        POP     DE
        RET

L51085  LD      A,E
        CALL    L51038
        LD      E,A
        RET
L51091  LD      A,LX
        CALL    L51038
        LD      LX,A
        LD      A,D
        CALL    L51038
        LD      D,A
        RET

L50071  CALL    L51011
        RLCA
        RLCA
        RLCA
        CPL
        AND     56
        OR      199
        LD      (L50087),A
        XOR     A
        SET     6,A
L50087  EQU     $-  1
E_SET01  XOR     (HL)     ; OR/XOR
        LD      (HL),A
        CALL    SET_COLOUR
        RET

L50656  PUSH    BC
        PUSH    DE
        LD      A,C
        SUB     D
        EX      AF,AF'
        LD      A,C
        SUB     LX
        LD      D,A
        EX      AF,AF'
        LD      C,A
        CALL    L50681
        POP     DE
        POP     BC
        LD      A,C
        ADD     A,D
        LD      D,A
        LD      A,C
        ADD     A,LX
        LD      C,A
        LD      A,83
L50680  EQU     $-  1
L50681  LD      A,D
        CP      C
        JR      NC,L50687
        LD      D,C
        LD      C,A
L50687  LD      A,C
        AND     #F8
        LD      E,A
        LD      A,D
        AND     #F8
        CP      E
        JR      NZ,L50726
        CALL    L51011
        LD      B,A
        LD      A,255
        JR      Z,L50709
L50705  SRL     A
        DJNZ    L50705
L50709  LD      C,A
L50710  LD      A,D
        AND     7
        LD      B,A
        LD      A,128
        JR      Z,L50722
L50718  SCF
        RRA
        DJNZ    L50718
L50722  AND     C
E_SET02 XOR     (HL)    ; OR/XOR
        LD      (HL),A
        CALL    SET_COLOUR
        RET

L50726  SUB     E
        RRCA
        RRCA
        RRCA
        LD      E,A
        CALL    L51011
        LD      B,A
        LD      A,255
        JR      Z,E_SET03
L50739  SRL     A
        DJNZ    L50739
E_SET03  XOR     (HL)      ; OR/XOR
        LD      (HL),A
        CALL    SET_COLOUR
        LD      B,C
        LD      C,255
L50748  INC     L
        DEC     E
        JR      Z,L50710
        LD      A,(HL)
E_SET04 CPL             ; OR/XOR !!!
        LD      (HL),A
        CALL    SET_COLOUR
        JR      L50748

L50757  PUSH    BC
        PUSH    DE
        LD      A,B
        SUB     D
        EX      AF,AF'
        LD      A,B
        SUB     LX
        LD      D,A
        EX      AF,AF'
        LD      B,A
        CALL    L50780
        POP     DE
        POP     BC
        LD      A,B
        ADD     A,D
        LD      D,A
        LD      A,B
        ADD     A,LX
        LD      B,A
L50780  LD      A,D
        CP      B
        JR      NC,L50786
        LD      D,B
        LD      B,A
L50786  LD      A,D
        SUB     B
        RET     C
        INC     A
        LD      D,A
        CALL    L51011
        RLCA
        RLCA
        RLCA
        CPL
        AND     56
        OR      195
        LD      (L50808),A
        LD      E,0
        SET     6,E
L50808  EQU     $-  1
        LD      A,B
L50810  CPL
        AND     7
        INC     A
        LD      B,A
L50815  LD      A,(HL)
E_SET05 XOR     E       ; OR/XOR
        LD      (HL),A
        CALL    SET_COLOUR
        INC     H
        DEC     D
        RET     Z
        DJNZ    L50815
        LD      B,8
        LD      A,32
        ADD     A,L
        LD      L,A
        JR      C,L50815
        LD      A,#F8
        ADD     A,H
        LD      H,A
        JR      L50815
        LD      A,D
        CP      B
        JR      NC,L50846
        LD      D,B
        LD      B,A
        LD      A,E
        LD      E,C
        LD      C,A
L50846  LD      A,C
        CP      E
        SBC     A,A
        AND     8
        LD      L,45            ; DEC L
        JR      Z,L50856
        DEC     L               ; INC L
L50856  INC     A
        LD      (L50925),A
        LD      (L50975),A
        LD      A,L
        LD      (L50935),A
        LD      (L50990),A
        CALL    L51011
        RLCA
        RLCA
        RLCA
        CPL
        OR      199
        LD      (L50895),A
        LD      A,D
        SUB     B
        LD      D,A
        LD      A,E
        SUB     C
        LD      E,A
        JR      NC,L50893
        NEG
        LD      E,A
L50893  XOR     A
        SET     3,A
L50895  EQU     $-  1
        LD      C,A
        LD      A,E
        CP      D
        JR      NC,L50952
        LD      B,D
        INC     B
        LD      A,E
        SUB     D
        LD      E,A
        XOR     A
        XOR     D
        RRA
L50909  EX      AF,AF'
        LD      A,C
        CALL    E_SET01
        INC     H
        LD      A,H
        AND     7
        JR      Z,L50939
L50920  EX      AF,AF'
        ADD     A,E
        JR      NC,L50931
        RLC     C
L50925  EQU     $-  1
        JR      C,L50935
        DJNZ    L50909
        RET
L50931  ADD     A,D
        DJNZ    L50909
        RET
L50935  DEC     L
        DJNZ    L50909
        RET

L50939  LD      A,32
        ADD     A,L
        LD      L,A
        JR      C,L50920
        LD      A,#F8
        ADD     A,H
        LD      H,A
        JP      L50920
L50952  LD      B,E
        INC     B
        LD      A,E
        SUB     D
        LD      D,A
        XOR     A
        XOR     E
        RRA
        EX      AF,AF'
        JR      L50970

L50963  EX      AF,AF'
        INC     H
        LD      A,H
        AND     7
        JR      Z,L50998
L50970  LD      A,C
        CALL    E_SET01
        RLC     C
L50975  EQU     $-  1
        JR      C,L50990
        EX      AF,AF'
        SUB     D
        JR      C,L50985
        DJNZ    L50963
        RET
L50985  ADD     A,E
        EX      AF,AF'
        DJNZ    L50970
        RET
L50990  DEC     L
        EX      AF,AF'
        SUB     D
        JR      C,L50985
        DJNZ    L50963
        RET
L50998  LD      A,32
        ADD     A,L
        LD      L,A
        JR      C,L50970
        LD      A,#F8
        ADD     A,H
        LD      H,A
        JP      L50970

L51011  LD      A,B
        AND     A
        RRA
        SCF
        RRA
        AND     A
        RRA
        XOR     B
        AND     #F8
        XOR     B
        LD      H,A
        LD      A,C
        RLCA
        RLCA
        RLCA
        XOR     B
        AND     199
        XOR     B
        RLCA
        RLCA
        LD      L,A
        LD      A,C
        AND     7
        RET


L51038  PUSH    BC
        PUSH    DE
        PUSH    HL
        LD      DE,162
L51042  EQU     $-  2
        LD      B,8
        LD      H,D
        LD      L,D
L51048  ADD     HL,HL
        ADD     A,A
        JR      NC,L51053
        ADD     HL,DE
L51053  DJNZ    L51048
        LD      A,H
        POP     HL
        POP     DE
        POP     BC
        RET


L51060  PUSH    BC
        PUSH    DE
        LD      B,9
        XOR     A
        LD      H,A
        LD      D,A
L51067  AND     A
        SBC     HL,DE
        CCF
        JR      C,L51075
        ADD     HL,DE
        AND     A
L51075  ADC     A,A
        ADD     HL,HL
        DJNZ    L51067
        LD      (L51042),A
        POP     DE
        POP     BC
        RET

SET_COLOUR:
        NOP

; ЕСЛИ СМЕНА АТРИБУТОВ НЕ НУЖНА - ЭТУ
; ПРОЦЕДУРУ, А ТАКЖЕ ВСЕ К НЕЙ ОБРАЩЕНИЯ
; МОЖНО УБРАТЬ.

        LD      A,H
        RRCA
        RRCA
        RRCA
        AND     3
        OR      88
        PUSH    HL,DE
        LD      H,A
        LD A,(HL)
        CALL MIXCOL
elcol   LD (HL),A
        POP     DE,HL
        RET

        ENT
LBox=$-BoxPgn

        DISPLAY "Box len   :",/a,LBox
