
X_      DB 0
Y_      DB 0
Ln      DB 0
Hg      DB 0

;...
; Попиксельная рамка

FRamka  CALL INILH
BoxPix  LD D,(IX+1)
        LD E,(IX+0)
        LD (X_),DE
        XOR A
        LD (SMX+1),A
        LD A,(IX+2)
        LD (Ln),A
        AND A
        JR Z,OK_
        ADD A,E
        JR C,BAk_
        JR Z,BAk_
        JR OK_

BAk_    LD A,#FF
        SUB E
        LD (Ln),A

OK_     LD A,E
        AND #07

        LD HL,TBL1
        ADD A,L
        LD L,A
        JR NC,pk1
        INC H
pk1     LD A,(HL)
        LD (JMP1+1),A

;       LD A,(IX+2)
;       LD (Ln),A
        LD A,(Ln)
        ADD A,E
        AND #07
        LD HL,TBL2
        ADD A,L
        LD L,A
        JR NC,pk2
        INC H
pk2     LD A,(HL)
        LD (JMP2+1),A

        PUSH DE
        PUSH DE
        CALL PixHL
        CALL OneLn
        POP DE

        LD A,(IX+3)
        LD (Hg),A
        ADD A,D
        JR C,BAD
        CP 192
        JR NC,BAD
        LD D,A
        JR oK1

BAD     LD A,#BF
        SUB D
        LD (Hg),A
        JR BAD1

oK1     CALL PixHL
        LD A,(Hg)
        AND A
        JR Z,BAD1
        CALL OneLn
BAD1    POP DE
        INC D
        CALL PixHL
        PUSH HL
        LD A,(IX+2);           Ln)
        ADD A,E
        JR C,BAD_
        JR Z,BAD_
        LD E,A
        LD A,(Ln)
        AND A
        JR Z,BAD__
        JR OK2

BAD_    LD A,#FF
        SUB E
        LD (Ln),A
BAD__   LD A,#FF
        LD (SMX+1),A

OK2     CALL PixHL
        LD D,H
        LD E,L
        POP HL
        CALL OneVert
BAD2    RET 

OneVert EXX 
        LD A,(X_)
        AND #07
        LD BC,TBL3
        ADD A,C
        LD C,A
        JR NC,pk3
        INC B
pk3     LD A,(BC)
        EXX 
        LD B,A
        EXX 

SMX     LD A,0
        AND A
        JR Z,OTK
        LD A,0
        JR paz

OTK     LD HL,Ln
        LD A,(X_)
        ADD A,(HL)
        AND #07
        LD BC,TBL3
        ADD A,C
        LD C,A
        JR NC,pk4
        INC B
pk4     LD A,(BC)
paz     EXX 
        LD C,A
        EXX 

        LD A,(Hg)
        AND A
        RET Z
        DEC A
        RET Z

        EX AF,AF'

        LD A,(Y_)
        INC A
        LD D,A
AZ_     CALL MOT
        EXX 
        LD D,0
        OR A
        RET Z
        EX AF,AF'
        JR AZ_

BRA     EX AF,AF'
        LD A,(HL)
        XOR B
        LD (HL),A
        LD A,(DE)
        XOR C
        LD (DE),A
        INC H
        INC D
        EX AF,AF'
        DEC A
        RET Z
        EX AF,AF'
t1      LD A,(HL)
        XOR B
        LD (HL),A
        LD A,(DE)
        XOR C
        LD (DE),A
        INC H
        INC D
        EX AF,AF'
        DEC A
        RET Z
        EX AF,AF'
T2      EX AF,AF'
        INC H
        INC D
        DEC A
        RET Z
        EX AF,AF'
T3      EX AF,AF'
        INC H
        INC D
        DEC A
        RET Z
        EX AF,AF'
T4      LD A,(HL)
        XOR B
        LD (HL),A
        LD A,(DE)
        XOR C
        LD (DE),A
        INC H
        INC D
        EX AF,AF'
        DEC A
        RET Z
        EX AF,AF'
T5      LD A,(HL)
        XOR B
        LD (HL),A
        LD A,(DE)
        XOR C
        LD (DE),A
        INC H
        INC D
        EX AF,AF'
        DEC A
        RET Z
        EX AF,AF'
T6      EX AF,AF'
        INC H
        INC D
        DEC A
        RET Z
        EX AF,AF'
T7      EX AF,AF'
        PUSH AF
        INC H
        INC D
        LD A,L
        ADD A,32
        LD L,A
        LD A,E
        ADD A,32
        LD E,A
        JR C,FUCKER2
        LD A,H
        SUB 8
        LD H,A
        LD A,D
        SUB 8
        LD D,A
FUCKER2 POP AF
        DEC A
        RET 

MOT     LD A,D
        AND #07
        EXX 
        JR Z,T0

        DEC A
        JR Z,t1
        DEC A
        JR Z,T2
        DEC A
        JR Z,T3
        DEC A
        JR Z,T4
        DEC A
        JR Z,T5
        DEC A
        JR Z,T6
        JR T7

T0      EX AF,AF'
        CP #08
        JP C,BRA
        EX AF,AF'
        LD A,(HL)
        XOR B
        LD (HL),A
        LD A,(DE)
        XOR C
        LD (DE),A
        INC H
        INC D
        LD A,(HL)
        XOR B
        LD (HL),A
        LD A,(DE)
        XOR C
        LD (DE),A
        INC H
        INC D
        INC H
        INC D
        INC H
        INC D
        LD A,(HL)
        XOR B
        LD (HL),A
        LD A,(DE)
        XOR C
        LD (DE),A
        INC H
        INC D
        LD A,(HL)
        XOR B
        LD (HL),A
        LD A,(DE)
        XOR C
        LD (DE),A
        INC H
        INC D
        INC H
        INC D
        INC H
        INC D

        LD A,L
        ADD A,32
        LD L,A
        LD A,E
        ADD A,32
        LD E,A
        JR C,FUCKER1
        LD A,H
        SUB 8
        LD H,A
        LD A,D
        SUB 8
        LD D,A

FUCKER1 EX AF,AF'
        SUB #08
        RET 

TBL3    DB #80
        DB #40
        DB #20
        DB #10
        DB #08
        DB #04
        DB #02
        DB #01
        DB #00

OneLn:
JMP1    LD A,0
        AND #CC
        LD B,A
        LD A,(Ln)
        CP 8
        JP C,okz
        LD A,(HL)
        XOR B
        LD (HL),A
        INC L

        LD BC,(Ln)
        LD B,#CC
        LD A,E;       (IX+0)
        AND #07
        ADD A,C
        SUB #08
        SRL A
        SRL A
        SRL A
        NEG 
        ADD A,#1F+1
        ADD A,A
        ADD A,A
        LD DE,Sett
        ADD A,E
        LD E,A
        JR NC,IFOK
        INC D
IFOK    PUSH DE
        RET 

Sett    DUP 32
        LD A,(HL)
        XOR B
        LD (HL),A
        INC L
        EDUP 

OKZ     LD B,#CC
okz_
JMP2    LD A,0
        AND B
        LD B,A
        LD A,(HL)
        XOR B
        LD (HL),A
        RET 

okz     LD A,E;         (IX+0)
        LD DE,(Ln-1)
        AND 7
        ADD A,D
        CP 8
        JR C,okz_
        LD A,(HL)
        XOR B
        LD (HL),A
        INC L
        JR OKZ

TBL1    DB #FF
        DB #7F
        DB #3F
        DB #1F
        DB #0F
        DB #07
        DB #03
        DB #01

TBL2    DB #80
        DB #C0
        DB #E0
        DB #F0
        DB #F8
        DB #FC
        DB #FE
        DB #FF

; Настройка длины исходя из max/min
INILH ;  LD (PLOT_1Y),DE
;        LD (PLOT_2Y),BC
        CALL GET_BIGX
        CALL GET_BIGY
        LD A,(Y2)
        LD (IX+0),A
        LD A,(X2)
        LD (IX+1),A
        LD A,(Y2)
        LD B,A
        LD A,(Y1)
        SUB B
        LD (IX+2),A
        LD A,(X2)
        LD B,A
        LD A,(X1)
        SUB B
        LD (IX+3),A
        RET 


