
WinP
        DISP PgnAdr

BWinPix CALL SV_UNDO
         call MiniLoupeSPG
WINPIX  LD SP,(SPP)
        CALL LOADSCR
.mgnS   LD IX,Winp
        CALL Resize_WinP
        CALL BoxPix
        CALL ERASE_ALLW
winpp   LD A,%1111
winpix  LD IX,WWinPix
        LD (IX+6),A
        LD SP,(SPP)
        CALL Win_
        CP #FF
     ;   JP Z,RES_TSK
       jp z,exitSWpgn
        PUSH AF
        CALL SuxRam
        LD HL,#C000
        LD DE,#C001
        LD BC,6143
        LD (HL),L
        LDIR
        POP AF
        LD BC,TBWin1
        JP TAB_JP

bwin1_  CALL CLOSE
        LD A,%1101
;        JP winpix
         jr winpix

;WWinPix              ; перенёс в основной файл для экономии памяти в сегменте /DA
                      ; вернул назад (ниже) в v 3.12 /DA
;   if rus
;       DEFB 5,0,11,20,6*8,7,%00001111
;   else
;       DEFB 5,0,12,20,6*8,7,%00001111
;   endif
;; Bit 0 - окно с заголовком/без
;; Bit 1 - "перерисовать" окно да/нет
;; Bit 2 - тискать окно по экрану да/нет
;; Bit 3 - выход из окна-ткнуть только лишь за пределами (CANCEL)
;        DEFB 0
;        DEFW TWinPix      ; объект-текст
;        DEFW SWinPix      ; объект-подсветка (выборка)
;        DEFW HWinPix      ; горячие клавиши
;        DEFW Nil          ; объект-кнопки (выборка)
;        DEFW SwPix1       ; объект-флажки
;        DEFW #FFFF

WWinPix
        DEFB 5,0,12,20,6*8,7,%00001111
; Bit 0 - окно с заголовком/без
; Bit 1 - "перерисовать" окно да/нет
; Bit 2 - тискать окно по экрану да/нет
; Bit 3 - выход из окна-ткнуть только лишь за пределами (CANCEL)
        DEFB 0
        DEFW TWinPix      ; объект-текст
        DEFW SWinPix      ; объект-подсветка (выборка)
        DEFW HWinPix      ; горячие клавиши
        DEFW Nil          ; объект-кнопки (выборка)
        DEFW SwPix1       ; объект-флажки
        DEFW #FFFF

TWinPix
        MSG_WIN_HeadX1 : DB 13
        MSG_WIN_Def :DB 13
        MSG_WIN_WhSCR : DB 13
        MSG_WIN_Clear : DB 13
        MSG_WIN_Copy : DB 13
       MSG_WIN_CopySh : DB 13 ; MSG_WIN_CopyP : DB 13
        MSG_WIN_Move : DB 13
        MSG_WIN_Invert : DB 13
        MSG_WIN_ReScal : DB 13
       MSG_WIN_ReScal : DB 13  ; MSG_WIN_ReScalP : DB 13
        MSG_WIN_FlipV : DB 13
        MSG_WIN_FlipH : DB 13
        DB 15,13
        MSG_WIN_Mode : DB " "

;PUTWP   DB "Put",13
         DB #0A
PUTWP    DW mPut

        MSG_WIN_Brush : DB 13
        MSG_WIN_Mult : DB 13
        MSG_WIN_Color : DB 13
        DB 0

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

SWinPix ; DEFB 1,3,9,1,%11  ; раскомментил /DA
        ; 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
        ; DEFB 1,11,9,1,%11
        ; DEFB 1,12,9,1,%11
        ; DEFB 1,13,9,1,%11
        DB 1,3,9,128+11,%11

        DEFB 1,15,9,1,%11
        ; DEFB 1,16,9,1,%10
        ; DEFB 1,17,9,1,%10
        ; DEFB 1,18,9,1,%10
        DB 1,16,9,128+3,%10
        DEFB #FF


;TWinPix
;   if rus
;       DB #8e,#aa,#ad,#A0,#20,#78,#31,13;"Окна x1",13
;        DB #82,#eb,#a1,#e0,#a0,#e2,#ec,#20,#ae,#aa,#ad,#ae,13;"Выбрать окно",13
;        db #82,#a5,#e1,#ec,#20,#ed,#aa,#E0,#a0,#ad,13; ;DB "Весь экран",13
;        DB #93,#a4,#a0,#ab,#A8,#e2,#ec,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 #8f,#a5,#e0,#a5,#ac,#a5,#e1,#e2,#a8,#e2,#ec,13;"Переместить",13
;        DB #88,#ad,#a2,#a5,#e0,#e2,#a8,#e0,#ae,#a2,#a0,#e2,#ec,13;"Инвертировать",13
;        DB #8c,#a0,#e1,#e8,#e2,#a0,#a1,13;"Масштаб",13
;        DB #8c,#a0,#e1,#e8,#e2,#a0,#a1,'+',13;"Масштаб+",13
;        DB #8f,#ae,#20,#a2,#a5,#e0,#e2,#a8,#aa,#a0,#ab,#a8,13;"По вертикали",13
;        DB #8f,#ae,#20,#a3,#ae,#e0,#a8,#a7,#ae,#ad,#e2,#a0,#ab,#a8,13;"По горизонтали",13
;        DB 15,13
;        DB #90,#a5,#a6,#a8,#ac,#3a,#20;"Режим: "
;   else
;       DB "Windows x1",13
;        DB "Define",13
;        db "Whole screen",13
;        DB "Clear",13
;        DB "Copy window",13
;        DB "Copy window+",13
;        DB "Move window",13
;        DB "Invert",13
;        DB "Re-Scale",13
;        DB "Re-Scale+",13
;        DB "Flip vertical",13
;        DB "Flip horizontal",13
;        DB 15,13
;        DB "Mode: "
;   endif
;PUTWP   DB "Put",13
;   if rus
;        DB #8a,#a8,#e1,#e2,#ec,13;"Кисть",13
;        DB #8f,#ae,#a2,#e2,#ae,#e0,13;"Повтор",13
;        DB #96,#a2,#a5,#e2,#20,#20,#20,13;"Цвет   ",13
;   else
;        DB "Brush",13
;        DB "Multiple",13
;        DB "Color",13
;   endif
;        DB 0

;SBRP    LD A,(BRP)
;        AND A
;        RET Z
;        LD (MULWP),A
;        RET
;SMU     XOR A
;        LD (BRP),A
;        RET

;SwPix1
;    if rus
;        DEFB 5,16,12,0
;    else
;        DEFB 7,16,12,0
;    endif
;BRP     EQU $-1
;        DEFW SBRP
;    if rus
;        DEFB 5,17,13,0
;    else
;        DEFB 7,17,13,0
;    endif
;MULWP   EQU $-1
;        DEFW SMU
;    if rus
;        DEFB 5,18,14,#FF
;    else
;        DEFB 7,18,14,#FF
;    endif
;ATRWP   EQU $-1
;        DEFW Nil
;        DEFB #FF

;HWinPix DB "W",0
;         DW 0
;        DB "S",0
;         DW 0
;        DB "Z",0
;         DW 1
;        DB "D",0
;         DW 2
;        DB "K",0
;         DW 3
;        DB "J",0
;         DW 4
;        DB "M",0
;         DW 5
;        DB "I",0
;         DW 6
;        DB 13,0
;         DW LP1Z
;        DB "E",0
;         DW CWin8
;        DB "U",0
;         DW UPix
;        DB "Y",0
;         DW SPix
;        DB "L",0
;         DW SwpPix
;        DB #FF


SBRP    LD A,(BRP)
        AND A
        RET Z
        LD (MULWP),A
        RET
SMU     XOR A
        LD (BRP),A
        RET

SwPix1
        DEFB 7,16,12,0
BRP     EQU $-1
        DEFW SBRP

        DEFB 7,17,13,#FF  ; 0  - включил повторы /DA
MULWP   EQU $-1
        DEFW SMU

        DEFB 7,18,14,#FF
ATRWP   EQU $-1
        DEFW Nil
        DEFB #FF

HWinPix DB "W",0
         DW 0
        DB "S",0
         DW 0
        DB "Z",0
         DW 1
        DB "D",0
         DW 2
        DB "K",0
         DW 3
        DB "J",0
         DW 4
        DB "M",0
         DW 5
        DB "I",0
         DW 6
        DB 13,0
         DW LP1Z
        DB "E",0
         DW CWin8
        DB "U",0
         DW UPix
        DB "Y",0
         DW SPix
        DB "L",0
         DW SwpPix
        DB #FF



SwpPix  ; CALL swapscr
         call SwapSCRS
        JP BWinPix

UPix    CALL LD_UNDO
        JP WINPIX
SPix    CALL SV_UNDO
        JP WINPIX

LP1Z    CALL CLOSE
        CALL NOKEY_
        JP winpp

TBWin1  DW DEFINE1
        DW WINPALL
        DW CLSWINPIX
        DW COPYWINP
        DW COPYWINP_
        DW MOVEPIX
        DW INVWINPIX
        DW RESCALE
        DW RESCALE_
        DW PVert
        DW PHoriz
        DW CHWINP

;Winp    DB 0   ; вынес в основной файл для экономии памяти в сегменте /DA
;        DB 0
;        DB 255
;        DB 191

Lscp    CALL LOADSCR
        CALL SuxRam
        LD IX,Winp
        RET

WINPALL CALL Lscp
        XOR A
        LD (IX+0),A
        LD (IX+1),A
        CPL
        LD (IX+2),A
        LD A,191
        LD (IX+3),A
        JP WINPIX

DEFINE1 CALL Lscp
        CALL R1Sel
        JP WINPIX

DATA    DW SCRSPR

CLSWINPIX
        CALL LOADSCR
        LD IX,Winp
        CALL SETVP
        LD IX,Winp
        CALL PCls
        CALL SAVESCR
        JP WINPIX

INVWINPIX
        CALL LOADSCR
        LD IX,Winp
        CALL PInv
        CALL SAVESCR
        JP WINPIX

rel_    LD A,RamPage
        CALL RAM
        CALL SwpSRam
        RET

Ramka1P ; PUSH AF        ; нет смысла сохранять, обращение всюду через xor a   /DA
        CALL STOP_ARW_
        LD A,(BRP)
        LD B,A
        ; POP AF
        xor a
        INC B
        JP NZ,Ramka1
        JP Ramka1_



;COPYWINP_                   ; зачем нам почти дубликат   /DA
;        CALL Lscp
;        LD IX,Winp
;        CALL SAVEIX
;        CALL GetPW_
;        CALL rel_
;Copywi_ CALL BoxPixL1
;        XOR A
;        CALL Ramka1P
;        CALL BoxPixL2
;        JP C,Kk
;        CALL SuxRam
;        CALL PutPW_
;        CALL LOADIX
;        LD A,(MULWP)
;        AND A
;        JR NZ,Copywi_
;Kk      CALL rel_
;        JP WINPIX

BoxPixL1
        LD D,(IX+0)
        LD E,(IX+1)
        LD (hbhl),DE
        CALL BoxPix
        RET

BoxPixL2
        PUSH AF
        LD D,(IX+0)
        LD E,(IX+1)
        PUSH DE
        LD HL,0
hbhl    EQU $-2
        LD (IX+0),H
        LD (IX+1),L
        CALL BoxPix
        POP DE
        LD (IX+0),D
        LD (IX+1),E
        POP AF
        RET


COPYWINP_  ld a,#CD   ; call nn   /DA
          jr 1F
COPYWINP  ld a,#01   ; ld bc,nn   /DA
1       ld (COPYWINP.swp),a
        ld (Copywip.swp),a
        CALL Lscp
        LD IX,Winp
        CALL SAVEIX
        CALL GetPW_
.swp    ld bc,SwapSCRS       ; изврат для смены экранов ld bc,nn меняем на call  /DA
        call LOADSCR
Copywip CALL BoxPixL1
;        XOR A
        CALL Ramka1P
        CALL BoxPixL2
       jr c, .swp
        CALL SuxRam
        CALL PutPW_
        CALL SAVESCR
        CALL LOADIX
        CALL SuxRam
        LD A,(MULWP)
        AND A
        JR NZ,Copywip
.swp    ld bc,SwapSCRS       ; изврат для смены экранов ld bc,nn меняем на call  /DA
        JP WINPIX

GetPW_  CALL GetPW
        LD A,(chwp)
        CP 4
        CALL Z,Make_Mask
        LD A,(ATRWP)
        AND A
        CALL NZ,GetPWA
        RET

PutPW_  LD A,(chwp)
        CP 4
        JR NZ,no4
        LD A,3
        LD (chwp),A
        LD HL,SCRSPR+6912
        LD (DATA),HL
        CALL PutPW
        LD HL,SCRSPR
        LD (DATA),HL
        LD A,1
        LD (chwp),A
        CALL PutPW
        LD A,4
        LD (chwp),A
        JR yp4
no4     CALL PutPW
yp4     LD A,(ATRWP)
        AND A
        CALL NZ,PutPWA
        RET

SETVP   LD A,(ATRWP)
        AND A
        RET Z
        CALL Inixat
        JP SETV

MOVEPIX CALL Lscp
        CALL GetPW_
        LD IX,Winp
Movepix CALL SAVEIX
        CALL BoxPix
;        XOR A
        CALL Ramka1P
        JP C,WINPIX
        CALL SuxRam
        LD IX,winp
        CALL BoxPix
        CALL PCls
        CALL SETVP
        LD IX,Winp
        CALL PutPW_
        CALL SAVESCR
        CALL SuxRam
        LD A,(MULWP)
        AND A
        JR NZ,Movepix
        JP WINPIX

SAVEIX  LD HL,Winp
        LD DE,winp
        LD BC,4
        LDIR
        RET

LOADIX  LD HL,winp
        LD DE,Winp
        LD BC,4
        LDIR
        RET

;winp    DS 4      ; вынес в основной файл для экономии памяти в сегменте /DA
;xcoo    DB 0
;ycoo    DB 0
;LENG    DB 0
;HGT     DB 0

NOKIA   LD A,(LENG)
        DEC A
        JR NZ,STRAEX
        LD A,#20
STRAEX  LD (LENG),A
        RET

GetPW   PUSH IX
        CALL getPW
        POP IX
        RET

getPW   LD E,(IX+0)
        LD D,(IX+1)
        LD (xcoo),DE
        LD A,(IX+2)
        INC A
         SRL A
         SRL A
         SRL A
        INC A
        LD (LENG),A
        LD A,(IX+2)
        INC A
        AND 7
        CALL Z,NOKIA

        LD A,(IX+3)
        INC A
        LD (HGT),A

        CALL PixHL
        LD A,(xcoo)
        AND 7
        LD (Shift+1),A
        LD IX,(DATA)
        LD A,(HGT)
        LD B,A
J3      PUSH BC
        PUSH HL
        LD A,(LENG)
        LD B,A
J2      PUSH BC
        LD B,0
        LD A,(HL)
        LD C,A
Shift   LD A,0
        OR A
        JR Z,contR
J1      SLA C
        DEC A
        JR NZ,J1
        INC L
        LD A,(HL)
        DEC L
        LD E,A
        LD A,(Shift+1)

JJ1     SLA E
        RL B
        DEC A
        JR NZ,JJ1
contR   XOR A
        OR C
        OR B
        LD (IX),A
        INC L
        INC IX
        POP BC
        DJNZ J2
        POP HL
        CALL INC_Y
        POP BC
        DJNZ J3
        RET
;....................
Len     DB 0
LL      DB 0

IXAT    DS 4
;..............................
PutPW   PUSH IX
        CALL Initwp
        CALL putPW
        POP IX
        RET

PutPWA  PUSH IX
        CALL InixatX
        CALL LoadWA
        POP IX
        RET

GetPWA  PUSH IX
        CALL Inixat
        CALL SaveWA
        POP IX
        RET

InixatX
        LD A,(IX+0)
        CALL SRL3
        LD (IXAT+0),A
        LD A,(IX+1)
        CALL SRL3
        LD (IXAT+1),A
        LD IX,IXAT
        LD DE,#C000+6912+6912
        RET

Inixat  LD A,(IX+0)
        CALL SRL3
        LD (IXAT+0),A
        LD A,(IX+1)
        CALL SRL3
        LD (IXAT+1),A

        LD A,(IX+2)
        CALL SRL3
        INC A
        LD (IXAT+2),A
        LD A,(IX+3)
        CALL SRL3
        INC A
        LD (IXAT+3),A
        LD IX,IXAT
        LD DE,#C000+6912+6912
        RET

SRL3     SRL A
         SRL A
         SRL A
        RET

PUTIN   LD HL,PUTEF1
        LD (PUTEF1_+1),HL
        LD HL,PUTEF2
        LD (PUTEF2_+1),HL
        LD HL,PUTEF3
        LD (PUTEF3_+1),HL
        LD HL,PUTEF4
        LD (PUTEF4_+1),HL
        RET

PUTNO   LD HL,Ret
        LD (PUTEF1_+1),HL
        LD (PUTEF2_+1),HL
        LD (PUTEF3_+1),HL
        LD (PUTEF4_+1),HL
        RET

METWP   DW #B0B1
        DW #B0B1
        DW #A8A9
        DW #A8A9

Initwp  LD A,(chwp)
        LD BC,METWP
        CALL TAB_HL
        LD A,L
        LD (operc1),A
        LD (operc2),A
        LD A,H
        LD (operb1),A
        LD (operb2),A
        LD A,(chwp)
        AND A
        CALL Z,PUTIN
        CALL NZ,PUTNO
        CP 3
        CALL Z,PUTNOO
        RET

PUTNOO  LD HL,AN1
        LD (PUTEF2_+1),HL
        LD (PUTEF4_+1),HL
        INC HL
        INC HL
        LD (PUTEF1_+1),HL
        LD (PUTEF3_+1),HL
        RET

AN1     OR B
        RET
AN2     OR C
        RET

PUTEF4  EX AF,AF'
        LD A,(MASK2+1)
        CPL
        LD E,A
        EX AF,AF'
        AND E
        RET

PUTEF3  EX AF,AF'
        LD A,(MASK1+1)
        CPL
        PUSH AF
        LD A,0
maskor  EQU $-1
        LD D,A
        POP AF
        OR D
        LD D,A
        EX AF,AF'
        AND D
        RET

PUTEF2  EX AF,AF'
        LD A,(maskor)
        CPL
        LD E,A
        EX AF,AF'
        AND E
        RET

PUTEF1  EX AF,AF'
        LD A,(maskor)
        LD E,A
        EX AF,AF'
        AND E
        RET

putPW   CALL INICOOR
        LD DE,(xcoo)
        CALL PixHL
        LD A,(xcoo)
        AND 7
        LD (SHIFT+1),A

        PUSH HL
        LD BC,MTAB
        LD H,0
        LD L,A
        ADD HL,BC
        LD A,(HL)
        LD (maskor),A
        POP HL

        LD IX,(DATA)

        LD A,(HGT)
        LD B,A
C3      PUSH BC
        PUSH HL

        LD A,(LENG)
        LD B,A
        DEC B
        JR Z,SP8
C2      PUSH BC
        LD B,0
        LD C,(IX+0)
SHIFT   LD A,0
        OR A
        JR Z,CONT
C1      SRL C
        RR B
        DEC A
        JR NZ,C1

CONT    LD A,(HL)
PUTEF1_ CALL Ret
operc1  OR C
        LD (HL),A
        INC L

        LD A,#1F
        AND L
        JR Z,ovk2

        LD A,(HL)
PUTEF2_ CALL Ret
operb1  OR B
        LD (HL),A
        INC IX
        POP BC
        DJNZ C2

SP8     LD B,0
clsf2   LD C,(IX+0)
        LD A,(SHIFT+1)
        OR A
        JR Z,cont
CC1     SRL C
        RR B
        DEC A
        JR NZ,CC1

cont    LD A,C
MASK1   AND #FF
        LD C,A

        LD A,(HL)
PUTEF3_ CALL Ret
operc2  OR C
        LD (HL),A
        INC L

        LD A,#1F
        AND L
        JR Z,sortir

        LD A,B
MASK2   AND #FF
        LD B,A
        LD A,(HL)
PUTEF4_ CALL Ret
operb2  OR B
        LD (HL),A
sortir  INC IX
        POP HL
        CALL INC_Y
        POP BC
        LD A,H
        CP #58
        RET NC
        DJNZ C3
        RET
;..
ovk2    POP BC
ovk2_   INC IX
        DJNZ ovk2_
        JR sortir

AKZA    LD A,(Len)
        DEC A
        LD (Len),A
        LD A,#20
        JR RESTt
SIMM    LD A,(Len)
         SRL A
         SRL A
         SRL A
        AND A
        JR Z,AKZA
        JR RESTt

INICOOR LD A,(IX+3)
        INC A
        LD (HGT),A
        LD C,(IX+0)
        LD B,(IX+1)
        LD (xcoo),BC
        LD A,(IX+2)
        INC A
        LD (Len),A
        AND 7
        JR Z,SIMM
        LD A,(Len)
        AND A
        JR Z,AKZA
         SRL A
         SRL A
         SRL A
        INC A
RESTt   LD (LENG),A
SLEN    LD A,(IX+0)
        LD B,A
        LD A,(Len)
        ADD A,B
        LD (LL),A
        JR C,MUSK
        LD A,(xcoo)
         SRL A
         SRL A
         SRL A
        LD B,A
        LD A,(LENG)
        ADD A,B
        LD B,A

        LD A,(xcoo)
        LD C,A
        LD A,(Len)
        ADD A,C
         SRL A
         SRL A
         SRL A
        CP B
        JP C,K1

MUSK    LD A,#FF
        LD (MASK1+1),A
        LD A,(LL)
        AND 7
        LD BC,MTAB
        LD H,0
        LD L,A
        ADD HL,BC
        LD A,(HL)
        LD (MASK2+1),A
        RET

K1      XOR A
        LD (MASK2+1),A
        LD A,(LL)
        AND 7
        LD BC,MTAB
        LD H,0
        LD L,A
        ADD HL,BC
        LD A,(HL)
        LD (MASK1+1),A
        RET

MTAB    DB #00
        DB #80
        DB #C0
        DB #E0
        DB #F0
        DB #F8
        DB #FC
        DB #FE
        DB #FF

chwp    DB 0

WMWin1  DEFB 0,0,4,7,7*8,7,%00001110
        DEFB 0
        DEFW TMWin1       ; объект-текст
        DEFW SMWin1       ; объект-подсветка (выборка)
        DEFW #FFFF

TMWin1  ; DB "Put",13
        ; DB "Or ",13
        ; DB "Xor",13
        ; DB "And",13
        ; DB "Msk",0
         DB #0A : DW mPut
         DB #0A : DW mOR
         DB #0A : DW mXOR
         DB #0A : DW mAND
         DB #0A : DW mMSK
         DB 0



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

CHWINP  LD HL,WMWin1
        CALL PupMnu
        CP #FF
        JP Z,bwin1_
        LD (chwp),A
     ;   ADD A,A
     ;   ADD A,A
     ;   LD H,0
     ;   LD L,A
        LD BC,TMWin1+1
     ;   ADD HL,BC
      ;  LD DE,PUTWP
      ;  LD BC,3
      ;  LDIR
         call mGetModAdr_
         ld (PUTWP),hl
        JP bwin1_
;.......................
Resize_WinP
        LD A,(IX+0)
        LD B,(IX+2)
        ADD A,B
        CALL C,rsw
        LD A,(IX+1)
        LD B,(IX+3)
        ADD A,B
        CALL C,rsha
        CP 191
        CALL NC,rsh
        RET

rsw     LD A,#FF
        LD B,(IX+0)
        SUB B
        LD (IX+2),A
        RET

rsha    POP AF
rsh     LD A,#BF
        LD B,(IX+1)
        SUB B
        LD (IX+3),A
        RET

Xorik   LD A,(HL)
        XOR B
        LD (HL),A
        INC L

Andik   LD A,(HL)
        AND B
        LD (HL),A
        INC L

SLABO   DS 6
PCls    PUSH IX
        PUSH IX
        POP HL
        LD DE,SLABO
        PUSH DE
        POP IX
        LD BC,6
        LDIR
        CALL Resize_WinP
        XOR A
        LD HL,Andik
        CALL InstPX
        LD A,(RMP1+1)
        CPL
        LD H,A
        LD L,#E6
        LD (METH1_),HL
        LD H,A
        LD (METH2_),HL
        LD A,#FF
        LD (MODUS1+1),A
        LD A,(RMP2+1)
        CPL
        LD H,A
        LD (METH3_),HL
        LD A,#B0
        CALL Modus
        POP IX
        RET

InstPX  LD DE,Buffer
        LD BC,4
        LDIR
        LD (MODUS1+1),A
        LD (MODUS2+1),A
        LD (MODUS3+1),A

        LD HL,Buffer
        LD DE,Buffer+4
        LD BC,4*31
        LDIR
        LD A,#C9
        LD (DE),A

        LD D,(IX+1)
        LD E,(IX+0)
        LD (X_),DE

        LD A,(IX+2)
        LD (LLn),A

        LD A,E
        AND #07
        LD HL,TBL1
        ADD A,L
        LD L,A
        JR NC,Mk1
        INC H
Mk1     LD A,(HL)
        LD (RMP1+1),A

        LD A,(LLn)
        ADD A,E
        AND #07
        LD HL,TBL2
        ADD A,L
        LD L,A
        JR NC,Mk2
        INC H
Mk2     LD A,(HL)
        LD (RMP2+1),A
        LD (RMP3+1),A
        RET

PInv    LD A,#FF
        LD HL,Xorik
        CALL InstPX
        LD HL,#00A8
        LD (METH1_),HL
        LD (METH2_),HL
        LD (METH3_),HL
        XOR A
Modus   LD (METH4_),A
        CALL PixHL
        LD B,(IX+3)
        INC B
mf      PUSH BC
        PUSH HL
        PUSH DE
        CALL OOneLn
        POP DE
        POP HL
        POP BC
        CALL INC_Y
        DJNZ mf
        RET

OOneLn:
RMP1    LD A,0
MODUS1  AND 0
        LD B,A
        LD A,(LLn)
        CP 8
        JP C,Mkz
        LD A,(HL)
METH1_  AND 0
;METH1   XOR B
        LD (HL),A
        INC L

        LD BC,(LLn)
MODUS2  LD B,0
        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,Buffer
        ADD A,E
        LD E,A
        JR NC,ESOK
        INC D
ESOK    EXX
        LD DE,MKZ
        PUSH DE
        EXX
        PUSH DE
        RET

SEtt    CALL Buffer
MKZ
MODUS3  LD B,0
RMP2    LD A,0
        AND B
        LD B,A
        LD A,(HL)
METH3_  AND 0
        LD (HL),A
        RET

Mkz_
RMP3    LD A,0
        AND B
        LD B,A
        LD A,(HL)
METH4_  NOP
        XOR B
        LD (HL),A
        RET

Mkz     LD A,E;         (IX+0)
        LD D,0
LLn     EQU $-1
        AND 7
        ADD A,D
        CP 8
        JR C,Mkz_
        LD A,(HL)
METH2_  AND 0
;       XOR B
        LD (HL),A
        INC L
        JR MKZ

PHoriz  CALL LOADSCR
        CALL AHoriz
        CALL INSTL
        LD A,(IX+3)
        LD E,(IX+1)
        ADD A,E
        LD E,A
        LD D,(IX+0)
        LD H,(IX+0)
        LD L,(IX+1)
        LD B,(IX+3)
        INC B
Sy_     PUSH BC
        PUSH DE
        PUSH HL
        LD B,(IX+2)
        INC B
Sx_     PUSH BC
        PUSH HL
        PUSH DE
        LD D,H
        LD E,L
        LD L,E
        LD H,high PLOTC0
        LD A,(HL)
        INC H
        LD B,(HL)
        INC H
        LD L,D
        ADD A,(HL)
        LD C,A
        INC H
        LD A,(BC)
        AND (HL)
        POP DE
        CALL PSet
        INC D
        POP HL
        INC H
        POP BC
        DJNZ Sx_
        POP HL
        INC L
        POP DE
        DEC E
        POP BC
        DJNZ Sy_
        JR MuMu

PVert   CALL LOADSCR
        CALL AVert
        CALL INSTL
        LD A,(IX+2)
        LD D,(IX+0)
        ADD A,D
        LD D,A
        LD E,(IX+1)
        LD H,(IX+0)
        LD L,(IX+1)
        LD B,(IX+3)
        INC B
Sy      PUSH BC
        PUSH DE
        PUSH HL
        LD B,(IX+2)
        INC B
Sx      PUSH BC
        PUSH HL
        PUSH DE
        LD D,H
        LD E,L
        LD L,E
        LD H,high PLOTC0
        LD A,(HL)
        INC H
        LD B,(HL)
        INC H
        LD L,D
        ADD A,(HL)
        LD C,A
        INC H
        LD A,(BC)
        AND (HL)
        POP DE
        CALL PSet
        DEC D
        POP HL
        INC H
        POP BC
        DJNZ Sx
        POP HL
        INC L
        POP DE
        INC E
        POP BC
        DJNZ Sy
MuMu    CALL SAVESCR
        JP WINPIX

PSet    JR Z,PRes
        LD L,E
        LD H,high PLOT40
        LD A,(HL)
        INC H
        LD B,(HL)
        INC H
        LD L,D
        ADD A,(HL)
        LD C,A
        INC H
        LD A,(BC)
        OR (HL)
        LD (BC),A
        RET

PRes    LD L,E
        LD H,high PLOT40
        LD A,(HL)
        INC H
        LD B,(HL)
        INC H
        LD L,D
        ADD A,(HL)
        LD C,A
        INC H
        LD A,(BC)
        OR (HL)
        XOR (HL)
        LD (BC),A
        RET

AVert   LD A,(ATRWP)
        AND A
        RET Z
        CALL Inixat
        LD D,(IX+1)
        LD E,(IX+0)
        CALL RASCHA
        LD B,(IX+3)
Lp10    PUSH BC
        PUSH HL
        PUSH HL
        POP DE
        EX DE,HL
        LD B,0
        LD C,(IX+2)
        DEC C
        ADD HL,BC
        EX DE,HL
        LD B,(IX+2)
        LD A,1
        CP B
        JR Z,Lp9
        SRL B
Lp9     LD A,(HL)
        EX AF,AF'
        LD A,(DE)
        LD (HL),A
        EX AF,AF'
        LD (DE),A
        INC HL
        DEC DE
        DJNZ Lp9
        POP HL
        LD BC,32
        ADD HL,BC
        POP BC
        DJNZ Lp10
        RET

AHoriz  LD A,(ATRWP)
        AND A
        RET Z
        CALL Inixat

        LD B,0
        LD C,(IX+2)
        LD (Bc1+1),BC

        LD D,(IX+1)
        LD E,(IX+0)
        CALL RASCHA
        PUSH HL
        LD DE,32
        LD B,(IX+3)
        LD A,1
        CP B
        JR Z,Jp5
        DEC B
D_3     ADD HL,DE
        DJNZ D_3
Jp5     EX DE,HL
        POP HL

        LD B,(IX+3)
        LD A,1
        CP B
        JR Z,jp6_

        SRL B
D_2     PUSH BC
        PUSH HL
        PUSH DE

        PUSH HL
        PUSH DE
        LD BC,(Bc1+1)
        LD DE,Buffer
        LDIR
        POP DE
        POP HL
        PUSH HL
        PUSH DE
        EX DE,HL
        LD BC,(Bc1+1)
        LDIR
        POP DE
        POP HL
        LD HL,Buffer
Bc1     LD BC,0
        LDIR
        POP DE
        POP HL
        LD BC,32
        ADD HL,BC
        EX DE,HL
        SBC HL,BC
        EX DE,HL
        POP BC
        DJNZ D_2
jp6_    RET

PLOTC0  EQU #C000+6912+6912
PLOT40  EQU PLOTC0+#400

INSTL   LD A,ScrPage
        CALL RAM
        LD HL,PLOTC0
        LD DE,#C000
        CALL install_plot
        LD HL,PLOT40
        LD DE,#4000
        CALL install_plot
        LD IX,Winp
        RET

RESCALE_
        CALL INSTL
        CALL LOADSCR
        LD IX,Winp
        CALL BoxPix
        LD IX,WDEST
        CALL R1Sel
        JP C,WINPIX
        LD IX,Winp
        CALL BoxPix
        LD IX,Winp
        CALL PCls
        JR resc

RESCALE CALL INSTL
        CALL LOADSCR
        LD IX,Winp
        CALL BoxPix
        LD IX,WDEST
        CALL R1Sel
        JP C,WINPIX
        LD IX,Winp
        CALL BoxPix
resc    LD IX,Winp
        CALL INIresc
        CALL Rescale
        CALL SAVESCR
        JP WINPIX

INIresc ;LD IX,Winp
        XOR A
        LD H,A
        LD L,(IX+0)
        LD (XSOURCE),HL
        LD L,(IX+1)
        CALL MULT16_
        LD (YSOURCE),HL
        LD H,A
        LD L,(IX+2)
        INC L
        LD (LSOURCE),HL
        LD L,(IX+3)
        INC L
        LD (HSOURCE),HL
        LD IX,WDEST
        LD L,(IX+0)
        LD (XDEST),HL
        LD L,(IX+1)
        LD (YDEST),HL
        LD L,(IX+2)
        INC L
        LD (LDEST),HL
        LD L,(IX+3)
        INC L
        LD (HDEST),HL

        XOR A
        LD HL,#0000
        LD (MMA),A
        LD (MMA+1),HL

        LD HL,(LSOURCE)
        LD A,L
        OR H
        JR NZ,NXS1
        LD HL,#0100
        LD (LSOURCE),HL

        LD A,#21
        LD HL,#FFFF
        LD (MMA),A
        LD (MMA+1),HL

NXS1    LD HL,(LDEST)
        LD A,L
        OR H
        RET NZ
        LD HL,#0100
        LD (LDEST),HL
        RET

XSOURCE DW 0
YDEST   DW 0
XDEST   DW 0
HSOURCE DW 0
LDEST   DW 0
HDEST   DW 0

Rescale LD HL,0
LSOURCE EQU $-2
        CALL MULT16_
MMA     LD HL,0
        LD DE,(LDEST)
        CALL DIV
        LD (STEPX),HL

        LD HL,(HSOURCE)
        CALL MULT16_
        LD DE,(HDEST)
        CALL DIV
        LD (STEPY),HL

        LD A,(HDEST)
        LD B,A
Hgt     PUSH BC

        LD HL,(XSOURCE)
        CALL MULT16_
        LD (XFLOATS),HL
        LD A,(XDEST)
        LD (XFLOATD),A

        LD A,(LDEST)
        LD B,A
Len_    PUSH BC

        LD HL,(XFLOATS)
        CALL DIV16_
        LD D,L
        LD HL,(YSOURCE)
        CALL DIV16_
;       LD E,L
;       LD L,E
        LD H,high PLOTC0
        LD A,(HL)
        INC H
        LD B,(HL)
        INC H
        LD L,D
        ADD A,(HL)
        LD C,A
        INC H
        LD A,(BC)
        AND (HL)
        CALL SETP

        LD HL,0
XFLOATS EQU $-2
        LD DE,0
STEPX   EQU $-2
        ADD HL,DE
        LD (XFLOATS),HL
        LD HL,0
XFLOATD EQU $-2
        INC HL
        LD (XFLOATD),HL

        POP BC
        DJNZ Len_

        LD HL,0
YSOURCE EQU $-2
        LD DE,0
STEPY   EQU $-2
        ADD HL,DE
        LD (YSOURCE),HL
        LD A,(YDEST)
        INC A
        LD (YDEST),A
        POP BC
        DJNZ Hgt
        RET

SETP    JR NZ,ONplot
OFFplot LD A,(XFLOATD)
        LD D,A
;       LD A,(YDEST)
;       LD L,A
        LD HL,(YDEST)
        LD H,high PLOT40
        LD A,(HL)
        INC H
        LD B,(HL)
        INC H
        LD L,D
        ADD A,(HL)
        LD C,A
        INC H
        LD A,(BC)
        OR (HL)
        XOR (HL)
        LD (BC),A
        RET

ONplot  LD A,(XFLOATD)
        LD D,A
;       LD A,(YDEST)
;       LD L,A
        LD HL,(YDEST)

        LD H,high PLOT40
        LD A,(HL)
        INC H
        LD B,(HL)
        INC H
        LD L,D
        ADD A,(HL)
        LD C,A
        INC H
        LD A,(BC)
        OR (HL)
        LD (BC),A
        RET

MULT16_ DUP 8
        ADD HL,HL
        EDUP
        RET

DIV16_  DUP 8
        RR H
        RR L
        EDUP
        RET

Makemsk LD IX,0
Pl      EQU $-2
        LD A,0
Hg_     EQU $-1
        ADD A,A
        ADD A,A
        ADD A,A
        LD (m1-1),A
        LD A,0
Wd      EQU $-1
        LD (m2+2),A
        LD (m2-1),A
        LD (Bf0-1),A
        LD HL,0
M_pl    EQU $-2
        DEC A
        LD E,A
        LD D,0
        ADD HL,DE
        LD (Pr_ln+1),HL
        XOR A
        LD (Tt1),A
        CALL Rl_mask
        LD DE,(Pl)
        LD (Pl),IX
        AND A
        PUSH IX
        POP HL
        SBC HL,DE
        EX DE,HL
        LD HL,(M_pl)
        ADD HL,DE
        LD (M_pl),HL
        RET

Rl_mask LD B,0
m1      PUSH BC
        EX AF,AF'
        XOR A
        EX AF,AF'
        LD HL,Buffer
        EXX
        LD HL,Buffer+32
        EXX
        LD B,0
m2      LD A,(IX+0)
        OR (IX+0)
        INC IX
        LD E,A
        OR (HL)
        LD (HL),E
        INC HL
        EXX
        LD E,A
        LD D,A
        EX AF,AF'
        RR E
        EX AF,AF'
        LD A,E
        OR D
        LD (HL),A
        INC HL
        EXX
        DJNZ m2
        LD (spR+1),IX
        LD (Bf0+1),HL
        CALL Pr_ln
        POP BC
        LD A,B
        DEC A
        CP 1
        JR NZ,StOp
        XOR A
        LD (m2+2),A
        LD A,#36
        LD (Tt1),A
StOp    DJNZ m1
        EXX
        LD HL,10072
        EXX
        RET
Pr_ln   LD HL,0
        PUSH HL
        EXX
        LD B,0
Bf0     LD DE,0
        XOR A
t1_     DEC HL
        DEC DE
        LD A,(HL)
        RL (HL)
        PUSH AF
        OR (HL)
        EX DE,HL
        OR (HL)
Tt1     LD (HL),0
        EX DE,HL
        CPL
        EXX
        PUSH HL
spR     LD HL,0
        DEC HL
        LD (spR+1),HL
        POP HL
        LD (HL),A
        DEC HL
        LD A,C
        EXX
        POP AF
        DJNZ t1_
        EXX
        POP HL
        LD A,(Wd)
        INC HL
        DEC A
        JR NZ,$-2
        LD (Pr_ln+1),HL
        RET

Make_Mask:
        PUSH IX
        LD HL,Buffer
        LD DE,Buffer+1
        LD BC,32+32-1
        LD (HL),0
        LDIR
        LD HL,#C000
        LD (Pl),HL
        LD HL,#C000+6912
        LD (M_pl),HL
        LD A,(IX+2)
         SRL A
         SRL A
         SRL A
        INC A
iza1    LD (Wd),A
        LD A,(IX+3)
         SRL A
         SRL A
         SRL A
        INC A
iza2    LD (Hg_),A
        CALL Makemsk
        LD HL,#C000
        LD (Pl),HL
        LD HL,#C000+6912
        LD (M_pl),HL

        LD HL,#C000+6912
        LD BC,6144
K_66    LD A,(HL)
        CPL
        LD (HL),A
        INC HL
        DEC BC
        LD A,C
        OR B
        JP NZ,K_66
        POP IX
        RET

LWin1   EQU $-BWinPix
        DISPLAY "Win1 len   :",/a,LWin1
        ENT

