
WinPgn
        DISP PgnAdr

BWINDOW CALL SV_UNDO
         call MiniLoupeSPG
BWindow ; LD SP,(SPP)
        CALL ERASE_ALLW
        CALL LOADSCR
        LD IX,WinCol
        CALL ReRamka
        CALL BoxCol
bbwin   LD A,%1111
bwin    LD IX,WWinCol
        LD (IX+6),A
       ; LD A,ScrPage
       ; CALL RAM
         call ScrRam
        LD SP,(SPP)
        CALL Win_
        CP #FF
       ; JP Z,RES_W8
        jr z,RES_W8
        LD BC,TBWin8
        JP TAB_JP

bwin_   CALL CLOSE
        LD A,%1101
        JR bwin

RES_W8  LD IX,WinCol
        CALL BoxCol
       ; JP RES_TSK
       jp exitSWpgn

WWinCol
;   if rus
;       DEFB 3,0,11,24,6*8,7,%00001111
;   else
        DEFB 3,0,12,24,6*8,7,%00001111
;   endif
; Bit 0 - окно с заголовком/без
; Bit 1 - "перерисовать" окно да/нет
; Bit 2 - тискать окно по экрану да/нет
; Bit 3 - выход из окна-ткнуть только лишь за пределами (CANCEL)
        DEFB 0
        DEFW TWinCol      ; объект-текст
        DEFW SWinCol      ; объект-подсветка (выборка)
        DEFW HWinCol      ; горячие клавиши
        DEFW Nil          ; объект-кнопки (выборка)
        DEFW SwCol8       ; объект-флажки
        DEFW #FFFF

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

SWinCol ; 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
        ; DEFB 1,11,9,1,%11
        ; DEFB 1,12,9,1,%11
        ; DEFB 1,13,9,1,%11
        ; DEFB 1,14,9,1,%11
        ; DEFB 1,15,9,1,%11
        ; DEFB 1,16,9,1,%11
        ; DEFB 1,18,9,1,%11
        ; DEFB 1,17,9,1,%11
        DB 1,3,9,128+16,%11
        DEFB 1,20,9,1,%11
        ; DEFB 1,21,9,1,%10
        ; DEFB 1,22,9,1,%10
        DB 1,21,9,128+2,%10

        DEFB #FF

TWinCol
;    if rus             ; удалил из-за другого способа локализации /DA
;        db #8e,#aa,#ad,#A0,#20,#78,#38,13;DB "Окна x8",13
;        db #82,#eb,#a1,#e0,#a0,#e2,#ec,#20,#ae,#aa,#ad,#ae,13;DB "Выбрать окно",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 #90,#ae,#e2,#a0,#e6,#a8,#ef,#5f,13;"Ротация_",13
;        DB #88,#ad,#a2,#a5,#e0,#e2,#a8,#e0,#ae,#a2,#a0,#e2,#ec,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 #8f,#ae,#a2,#ae,#e0,#ae,#e2,#20,#39,#30,#f8,13;"Поворот 90°",13
;        DB #8c,#a0,#e1,#e8,#e2,#a0,#a1,13;"Масштаб",13
;        DB #9d,#e4,#e4,#a5,#aa,#e2,#eb,#5f,13;"Эффекты_",13
;        DB #92,#a5,#aa,#e3,#e9,#a8,#a9,#20,#e6,#a2,#a5,#e2,13;"Текущий цвет",13
;        DB #87,#a0,#ac,#a5,#ad,#a0,#20,#e6,#a2,#a5,#e2,#a0,13;"Замена цвета",13
;        DB #82,#eb,#a1,#ae,#e0,#20,#e6,#a2,#a5,#e2,#a0,13;"Выбор цветa",13
;        DB 15,13
;        DB #90,#a5,#a6,#a8,#ac,#3a,#20;"Режим: "
;    else
;        db "Windows x8",13
;        db "Define",13
;        db "Whole screen",13
;        DB "Clear",13
;        DB "Copy window",13
;        DB "Copy window+",13
;        DB "Move window",13
;        DB "Scroll_",13
;        DB "Invert",13
;        DB "Flip vertical",13
;        DB "Flip horizontal",13
;        DB "Rotate 90",248,13       ;"Rotate 90°",13
;        DB "Re-Scale",13
;        DB "Effects_",13
;        DB "Current color",13
;        DB "Change color",13
;        DB "Select color",13
;        DB 15,13
;        DB "Mode: "
;    endif

        MSG_WIN_HeadX8 : 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_Scroll_ : DB 13
        MSG_WIN_Invert : DB 13
        MSG_WIN_FlipV : DB 13
        MSG_WIN_FlipH : DB 13
        MSG_WIN_Rot90 : DB 13       ;"Rotate 90°",13
        MSG_WIN_ReScal : DB 13
        MSG_WIN_Effects : DB 13
        MSG_WIN_CurrCol : DB 13
        MSG_WIN_ChangeCol : DB 13
        MSG_WIN_SelCol : DB 13
        DB 15,13
        MSG_WIN_Mode : DB " "

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


;    if rus               ; удалил из-за другого способа локализации /DA
;        DB #8f,#ae,#a2,#e2,#ae,#e0,#20,13;"Повтор ",13
;        DB #96,#a2,#a5,#e2,#20,#20,#20,13;"Цвет   ",13
;    else
;        DB "Multiple",13
;        DB "Color",13
;    endif

        MSG_WIN_Mult : DB 13
        MSG_WIN_Color : DB 13
        DB 0

SwCol8
    if rus
        DEFB 5,21,17,#FF   ; 0 - Включил повторы /DA
    else
        DEFB 7,21,17,#FF   ; 0
    endif
MF      EQU $-1
        DEFW Nil
    if rus
        DEFB 5,22,18,#FF
    else
        DEFB 7,22,18,#FF
    endif
ATRW    EQU $-1
        DEFW Nil
        DEFB #FF

HWinCol 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 "R",0
         DW SCRR
        DB "I",0
         DW 7
        DB SS,"C"
         DW 13
        DB "C",0
         DW 15   ; 14
        DB 13,0
         DW W8L
        DB "E",0
         DW CWin1
        DB "U",0
         DW UCol
        DB "Y",0
         DW SCol
        DB "L",0
         DW SwpCol
        DB #FF

SwpCol ; CALL swapscr
         call SwapSCRS
        JP BWINDOW

UCol    CALL LD_UNDO
        JP BWindow
SCol    CALL SV_UNDO
        JP BWindow

W8L     CALL CLOSE
        CALL NOKEY_
        JP bbwin

TBWin8  DEFW DEFINE8
        DEFW ALLSCR
        DEFW CLSWIN
        DEFW COPYW
        DEFW COPYW_
        DEFW COPYDEL
        DEFW Roll8
        DEFW INVERT
        DEFW MIRR
        DEFW GORIZW
        DEFW TURN90
        DEFW RESCALE8
        DEFW EFF
        DEFW CLSAA
       ; DEFW SetAttr
        DEFW CHA
        DW SetAttr
        DEFW SetMode8

DEFINE8 CALL LOADSCR
        CALL SELWIN
        CALL BoxCol
        JP BWindow

ALLSCR  CALL LOADSCR
        XOR A
        LD (RCOL),A
        LD (RROW),A
        LD A,32
        LD (RLEN),A
        LD A,24
        LD (RHGT),A
        JP BWindow

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

SRoll   ; DEFB 1,3,5,1,%10
        ; DEFB 1,4,5,1,%10
        ; DEFB 1,5,5,1,%10
        DB 1,3,5,128+3,%10
        DEFB 1,7,5,1,%11
        DB #FF

FlRoll  DEFB 5,3,0,#FF
sw1     EQU $-1
        DEFW Nil
        DEFB 5,4,1,#FF
sw2     EQU $-1
        DEFW Ressw3
        DEFB 5,5,2,#00
sw3     EQU $-1
        DEFW Ressw2
        DEFB #FF

Ressw2  XOR A
        LD (sw2),A
        RET

Ressw3  XOR A
        LD (sw3),A
        RET

TRoll
;    if rus              ; удалил из-за другого способа локализации /DA
;        DB #90,#ae,#e2,#a0,#e6,#a8,#ef,13;"Ротация",13
;        DB #96,#a2,#a5,#e2,13;"Цвет",13
;        DB "x8",13
;        DB "x1",13
;        DB 15,13
;        DB #20,#20,#8f,#e3,#e1,#aa,0;"  Пуск",0
;    else
;        DB "Scroll",13
;        DB "Color",13
;        DB "x8",13
;        DB "x1",13
;        DB 15,13
;        DB " Start",0
;    endif

        MSG_WIN_ScrollH : DB 13
        MSG_WIN_ScColor : DB 13
        MSG_WIN_ScrolX8 : DB 13
        MSG_WIN_ScrolX1 : DB 13
        DB 15,13
        MSG_WIN_ScrollRUN : DB 0

Roll8   LD IX,WRoll
        CALL Win_
        INC A
        JP Z,bwin_
        CALL NOKEY_
SCRR    CALL LOADSCR
SELSC   EI
        HALT
        CALL DIRSCN_
        LD IX,WinCol
    xor a
    in  a,(#fe)
    cpl
    and 31
    jr  nz,key_w
    ld  [key_w+1],a
    jr  1f
key_w   ld  a,0
    cp  13
    adc a,0
    ld  [key_w+1],a
    sub 2
    cp  10
    jr  c,SELSC
1   LD A,(DIRECT)
        DUP 3
        PUSH AF
        EDUP
        BIT 0,A
        CALL NZ,SC_R
        POP AF
        BIT 1,A
        CALL NZ,SC_L
        POP AF
        BIT 2,A
        CALL NZ,SC_D
        POP AF
        BIT 3,A
        CALL NZ,SC_U
        CALL BREAK
        AND A
        JR NZ,OK1
        JR SELSC
OK1     CALL SAVESCR
        JP BWindow

SC_R    LD A,(sw1)
        AND A
        CALL NZ,RGT8A
        LD A,(sw2)
        AND A
        JP NZ,RGT8
        LD A,(sw3)
        AND A
        RET Z
        JP RGT1

SC_L    LD A,(sw1)
        AND A
        CALL NZ,LFT8A
        LD A,(sw2)
        AND A
        JP NZ,LFT8
        LD A,(sw3)
        AND A
        RET Z
        JP LFT1

SC_D    LD A,(sw1)
        AND A
        CALL NZ,DN8A
        LD A,(sw2)
        AND A
        JP NZ,DN8
        LD A,(sw3)
        AND A
        RET Z
        JP DN1

SC_U    LD A,(sw1)
        AND A
        CALL NZ,UP8A
        LD A,(sw2)
        AND A
        JP NZ,UP8
        LD A,(sw3)
        AND A
        RET Z
        JP UP1

RGT1    LD D,(IX+0)
        LD E,(IX+1)
        CALL RASCH
        LD A,(IX+3)
        Amul8
        LD B,A
CL2     PUSH BC
        PUSH HL
        LD B,(IX+2)
        AND A
CL1     RR (HL)
        INC HL
        DJNZ CL1
        POP HL
        JR NC,BP1
        LD A,#80
        OR (HL)
        LD (HL),A
BP1     CALL INC_Y
        POP BC
        DJNZ CL2
        RET

UP1     LD D,(IX+0)
        LD E,(IX+1)

        CALL RASCH
        PUSH HL
        LD DE,BFF
        LD B,0
        LD C,(IX+2)
        LDIR
        POP HL
        LD A,(IX+3)
        Amul8
        DEC A
        LD B,A
K_1     PUSH BC
        PUSH HL
        PUSH HL
        POP DE
        CALL INC_Y
        LD B,0
        LD C,(IX+2)
        LDIR
        POP HL
        CALL INC_Y
        POP BC
        DJNZ  K_1
        EX DE,HL
        LD HL,BFF
        LD B,0
        LD C,(IX+2)
        LDIR
        RET

DN1     LD D,(IX+0)
        LD E,(IX+1)
        LD A,(IX+3)
        ADD A,E
        LD E,A
        DEC E
        CALL RASCH
        DUP 7
        INC H
        EDUP
        PUSH HL
        LD DE,BFF
        LD B,0
        LD C,(IX+2)
        LDIR
        POP HL
        LD A,(IX+3)
        Amul8
        DEC A
        LD B,A
K_3     PUSH BC
        PUSH HL
        PUSH HL
        POP DE
        CALL DEC_Y
        LD B,0
        LD C,(IX+2)
        LDIR
        POP HL
        CALL DEC_Y
        POP BC
        DJNZ K_3
        EX DE,HL
        LD HL,BFF
        LD B,0
        LD C,(IX+2)
        LDIR
        RET

LFT1    LD D,(IX+0)
        LD E,(IX+1)
        CALL RASCH
        LD B,0
        LD C,(IX+2)
        DEC BC
        ADD HL,BC
        LD A,(IX+3)
        Amul8
        LD B,A
U6      PUSH BC
        PUSH HL
        LD B,(IX+2)
        AND A
U5      RL (HL)
        DEC HL
        DJNZ U5
        POP HL
        JR NC,BS2
        LD A,#01
        OR (HL)
        LD (HL),A
BS2     CALL INC_Y
        POP BC
        DJNZ U6
        RET
;.....................
SELWIN  LD IX,WinCol
        CALL R8Sel
        RET
;.................
;.................
MIRR    CALL LOADSCR
        LD IX,WinCol

        LD A,(ATRW)
        AND A
        JR Z,HH

        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

HH      LD D,(IX+0)
        LD E,(IX+1)
        CALL RASCH
        LD B,(IX+3)
        DUP 3
        SLA B
        EDUP
lp7     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)
        PUSH BC
        PUSH HL
lp6     LD A,(HL)
        DUP 8
        RLA
        RR C
        EDUP
        LD (HL),C
        INC HL
        DJNZ lp6
        POP HL
        POP BC
        LD A,1
        CP B
        JR Z,lp8
        SRL B
lp8     LD A,(HL)
        EX AF,AF'
        LD A,(DE)
        LD (HL),A
        EX AF,AF'
        LD (DE),A
        INC HL
        DEC DE
        DJNZ lp8
        POP HL
        POP BC
        CALL INC_Y
        DJNZ lp7
        CALL SAVESCR
        JP BWindow
;.....
GORIZW  CALL LOADSCR
        LD IX,WinCol
        LD B,0
        LD C,(IX+2)
        LD (bc1+1),BC

        LD A,(ATRW)
        AND A
        JP Z,jp6

        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
        LD BC,(bc1+1)
        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     LD D,(IX+0)
        LD E,(IX+1)
        CALL RASCH
        PUSH HL
        LD B,(IX+3)
        SLA B
        SLA B
        SLA B
d_1     CALL INC_Y
        DJNZ d_1
        CALL DEC_Y
        EX DE,HL  ; HL - BEG
        POP HL    ; DE - END

        LD B,(IX+3)
        SLA B
        SLA B
jp4     PUSH BC
        PUSH HL
        PUSH DE

        PUSH HL
        PUSH DE
bc1     LD BC,0
        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
        LD BC,(bc1+1)
        LDIR

        POP DE
        POP HL
        POP BC
        CALL INC_Y
        PUSH HL
        EX DE,HL
        CALL DEC_Y
        EX DE,HL
        POP HL
        DJNZ jp4

        CALL SAVESCR
        JP BWindow

TURN90  CALL LOADSCR

        CALL SuxRam

        LD IX,WinCol
        CALL SAVEW

        LD HL,(massad+1)
        PUSH HL
        LD HL,Ret
        LD (massad+1),HL

        LD B,0
        LD C,(IX+2)
        LD (inc_ys2+1),BC
        LD B,0
        LD C,(IX+3)
        LD (inc_ys3+1),BC

        LD HL,#C000
        LD DE,#C000+6912
        LD B,0
        LD C,(IX+3)
        EX DE,HL
        DEC BC
        ADD HL,BC; КОНЕЦ ПЕРВОЙ СТРОЧКИ МАССИВА
        EX DE,HL

        LD B,(IX+2)
d_7     PUSH BC
        PUSH HL
        PUSH DE

        LD B,(IX+3)
d_6     PUSH BC
        PUSH DE

        EX DE,HL
        LD (Buff1+1),HL

        LD B,8
d_5     PUSH BC
Buff1   LD HL,0
        LD A,(DE)
        DUP 8
        RLA
        RR (HL)
        CALL inc_ys3
        EDUP
        EX DE,HL
        CALL inc_ys2
        EX DE,HL
        POP BC
        DJNZ d_5

        EX DE,HL

        POP DE
        POP BC
        DEC DE
        DJNZ d_6

        POP HL
        LD B,8
d_8     PUSH BC
        CALL inc_ys3
        POP BC
        DJNZ d_8
        EX DE,HL
        POP HL
        POP BC
        INC HL
        DJNZ d_7

        LD HL,ATRSPR
        LD DE,SCRSPR+6912+6144

        LD B,(IX+2)
        INC HL
        DJNZ $-1
        DEC HL

        LD B,(IX+2)
d_17    PUSH BC
        LD B,(IX+3)
        INC DE
        DJNZ $-1
        POP BC
        DJNZ d_17
        DEC DE

        LD B,(IX+2)
d_16    PUSH BC
        PUSH HL
        LD B,(IX+3)
d_15    PUSH BC
        LD A,(HL)
        LD (DE),A
        CALL inc_ys2
        DEC DE
        POP BC
        DJNZ d_15
        POP HL
        POP BC
        DEC HL
        DJNZ d_16

Ok      LD HL,SCRSPR+6912
        LD DE,SCRSPR
        LD BC,6912
        LDIR

        CALL CLSV
        LD A,(ATRW)
        AND A
        CALL NZ,SETV

        LD A,(IX+3)
        EX AF,AF'
        LD A,(IX+2)
        LD (IX+3),A
        EX AF,AF'
        LD (IX+2),A

        CALL LOADW
        CALL SAVESCR

        POP HL
        LD (massad+1),HL
        JP BWindow

inc_ys2 LD BC,0
        ADD HL,BC
        RET

inc_ys3 LD BC,0
        ADD HL,BC
        RET

dec_ys2 LD BC,(inc_ys2+1)
        SBC HL,BC
        RET

dec_ys3 LD BC,(inc_ys3+1)
        SBC HL,BC
        RET

SetAttr CALL LOADSCR
        CALL PRGB
        JP BWindow

CLSWIN  CALL LOADSCR
        CALL CLSV
CLSA    LD IX,WinCol
        CALL SETV
SUDA2   CALL SAVESCR
        JP BWindow

CLSAA   CALL LOADSCR
        LD IX,WinCol
        CALL SETV
        CALL SAVESCR
        JP BWindow

INVERT  CALL LOADSCR
        LD IX,WinCol
        CALL INV
        JP SUDA2
;.......
;***************************
COPYW   CALL LOADSCR
        CALL SuxRam
        LD IX,WinCol
        LD HL,(RCOL)
        LD (xxx2+1),HL
        CALL SAVEW
copyw   CALL SuxRam
        LD A,(TEKNALOZ)
        CP 4
        CALL Z,MAKE_MASK
        CALL SuxRam
        CALL BoxCol
        XOR A
        CALL Ramka8
        JR C,j3
        LD DE,(RCOL)
xxx2    LD HL,0
        LD (RCOL),HL
        PUSH DE
        CALL BoxCol
        LD HL,(RCOL)
        POP DE
        PUSH HL
        LD (RCOL),DE
        LD IX,WinCol
        CALL LOADW
        POP HL
        LD (RCOL),HL
        CALL SAVESCR
        LD A,(MF)
        AND A
        JR NZ,copyw
        JP BWindow
j3      LD HL,(xxx2+1)
        LD (RCOL),HL
        JP BWindow

; на второй экран

COPYW_  CALL LOADSCR
        CALL SuxRam
        LD HL,(RCOL)
        LD (xxx1+1),HL
        LD IX,WinCol
        CALL SAVEW
        LD A,(TEKNALOZ)
        CP 4
        CALL Z,MAKE_MASK
        LD A,RamPage
        CALL RAM
        CALL SwpSRam
mdaa    CALL SuxRam
        LD HL,#C000
        LD (PL),HL
        LD HL,#C000+6912
        LD (M_PL),HL
        CALL BoxCol
        XOR A
        CALL Ramka8
        JR C,j1
        LD DE,(RCOL)
xxx1    LD HL,0
        LD (RCOL),HL
        PUSH DE
        CALL BoxCol
        LD HL,(RCOL)
        POP DE
        PUSH HL
        LD (RCOL),DE
        LD IX,WinCol
        CALL LOADW
        POP HL
        LD (RCOL),HL
        LD A,(MF)
        AND A
        JR NZ,mdaa
j2      LD A,RamPage
        CALL RAM
        CALL SwpSRam
        JP BWindow
j1      CALL BoxCol
        LD HL,(xxx1+1)
        LD (RCOL),HL
        JP j2
;--------------
ReRamka LD A,(IX+0)
        LD B,A
        LD A,(IX+2)
        ADD A,B
        CP 33
        CALL NC,RELEN
        LD A,(IX+1)
        LD B,A
        LD A,(IX+3)
        ADD A,B
        CP 25
        CALL NC,REHGT
        RET
RELEN   LD A,(IX+0)
        LD B,A
        LD A,32
        SUB B
        LD (IX+2),A
        RET
REHGT   LD A,(IX+1)
        LD B,A
        LD A,24
        SUB B
        LD (IX+3),A
        RET
;================
; COPY AND CLEAR
;================
COPYDEL CALL LOADSCR
        CALL SuxRam
        CALL ReRamka
        LD HL,(RCOL)
        LD (xxx3+1),HL
        LD IX,WinCol
        CALL SAVEW
        LD A,(TEKNALOZ)
        CP 4
        CALL Z,MAKE_MASK

        CALL BoxCol
        XOR A
        CALL Ramka8
        JR C,j4

xxx3    LD DE,0
        LD HL,(RCOL)
        PUSH HL
        PUSH DE
        POP DE
        LD (RCOL),DE
        CALL BoxCol
        CALL CLSV
        CALL SETV
        POP HL
        LD (RCOL),HL
        CALL LOADW
        CALL SAVESCR
        CALL ReRamka
        LD A,(MF)
        AND A
        JR NZ,COPYDEL
        JP BWindow

j4      LD HL,(xxx3+1)
        LD (RCOL),HL
        JP BWindow

;----------------------
TEKNALOZ DB 0; ФЛАГ НАЛОЖЕНИЯ (NOP,OR,XOR)
;-----------------------
SetMode8
        LD HL,WMWin8
        CALL PupMnu
        CP #FF
        JP Z,bwin_
        LD (TEKNALOZ),A
        PUSH AF
    ;    ADD A,A 
    ;    ADD A,A
    ;    LD H,0
    ;    LD L,A
        LD BC,TMWin8+1
    ;    ADD HL,BC
       ; LD DE,TmWin8
       ; LD BC,3
       ; LDIR
         call mGetModAdr_
         ld (TmWin8),hl
        POP AF
        LD HL,Ret
        LD (massad+1),HL
        LD BC,EFSW
        CALL TAB_HL
        CALL JP_HL
        JP bwin_

EFSW    DW NopWin8
        DW OrWin8
        DW XorWin8
        DW AndWin8
        DW MskWin8

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

TMWin8  ; 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
       

SMWin8  ; 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

NopWin8 XOR A
effo    LD (EFFOR),A
        RET
OrWin8  LD A,#B6
        JR effo
XorWin8 LD A,#AE
        JR effo
AndWin8 LD A,#A6
        JR effo
MskWin8 LD HL,OUTMSK
        LD (massad+1),HL
        LD A,#B6
        JR effo
;.......................
WD      DB 2;ширина спрайта
HG      DB 2;высота спрайта (знак.)
PL      DW #C000;начало блока спрайтов
M_PL    DW #C000+6912;адрес блока маски

MAKEMSK LD IX,(PL)
        LD A,(HG)
        ADD A,A
        ADD A,A
        ADD A,A
        LD (M1-1),A
        LD A,(WD)
        LD (M2+2),A
        LD (M2-1),A
        LD (BF0-1),A
        LD HL,(M_PL)
        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)
        LD (WD),A
        LD A,(IX+3)
        LD (HG),A
        CALL MAKEMSK
        LD HL,#C000
        LD (PL),HL
        LD HL,#C000+6912
        LD (M_PL),HL
        POP IX
        RET
;------------------------------
EFF     LD HL,WEff
        CALL PupMnu
        CP #FF
        JP Z,bwin_
        LD BC,EFTAB
        JP TAB_JP

EFTAB   DW OBVODKA
        DW THINCK
        DW ITHI
        DW CUTT

WEff    DEFB 10,6,7,6,7*8,7,%00001110
        DEFB 0
        DEFW TEff         ; объект-текст
        DEFW SEff         ; объект-подсветка (выборка)
        DEFW #FFFF

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

TEff
;    if rus                ; удалил из-за другого способа локализации /DA
;        DB #8e,#a1,#a2,#ae,#a4,#aa,#a0,13;"Обводка",13
;        DB #92,#ae,#ab,#e9,#a5,13;"Толще",13
;        DB #92,#ae,#ad,#ec,#e8,#a5,13;"Тоньше",13
;        DB #82,#eb,#a5,#ac,#aa,#a0,0;"Выемка",0
;    else
;        DB "Outline",13
;        DB "Grow out",13
;        DB "Grow in",13
;        DB "Take out",0
;    endif

        MSG_WIN_OutLine : DB 13
        MSG_WIN_GrowOut : DB 13
        MSG_WIN_GrowIn : DB 13
        MSG_WIN_TakeOut : DB 0


OBVODKA CALL LOADSCR
        CALL SuxRam

        LD IX,WinCol
        LD HL,(massad+1)
        PUSH HL
        LD A,(EFFOR)
        PUSH AF

        LD A,#B6
        LD (EFFOR),A
        LD HL,OUTNK
        LD (massad+1),HL
        CALL SAVEW
        CALL MAKE_MASK
        CALL LOADW
        CALL SAVEW
        CALL MAKE_MASK
        CALL LOADW

        LD HL,SCRSPR+6912
        LD DE,SCRSPR+6912+6144
        LD (scradrs+1),HL
        LD (atradrs+1),DE
        CALL SAVEW
        LD HL,SCRSPR
        LD DE,ATRSPR
        LD (scradrs+1),HL
        LD (atradrs+1),DE

        CALL LOADSCR
        CALL SuxRam
        CALL SAVEW

        LD HL,SCRSPR+6912
        LD DE,SCRSPR+6912+6144
        LD (scradrl+1),HL
        LD (atradrl+1),DE
        LD HL,Ret
        LD (massad+1),HL
        CALL LOADW
        LD HL,SCRSPR
        LD DE,ATRSPR
        LD (scradrl+1),HL
        LD (atradrl+1),DE

        LD HL,OUTMSK
        LD (massad+1),HL
        CALL MAKE_MASK
        CALL LOADW

        POP AF
        LD (EFFOR),A
        POP HL
        LD (massad+1),HL
        CALL SAVESCR
        JP BWindow

sex     LD HL,SCRSPR
        LD BC,10
sex2    LD A,(HL)
        CPL
        LD (HL),A
        INC HL
        DEC BC
        LD A,C
        OR B
        JR NZ,sex2
        RET

ITHI    LD HL,INV
        JR GJ

THINCK  LD HL,Ret
GJ      LD (G1+1),HL
        LD (G2+1),HL

        CALL LOADSCR
        CALL SuxRam
        LD IX,WinCol
G1      CALL INV
        CALL SAVEW

        LD HL,(massad+1)
        PUSH HL
        LD A,(EFFOR)
        PUSH AF
        LD A,#B6
        LD (EFFOR),A
        LD HL,OUTNK
        LD (massad+1),HL
        CALL MAKE_MASK

        LD IX,WinCol
        CALL LOADW
G2      CALL INV

        POP AF
        LD (EFFOR),A
        POP HL
        LD (massad+1),HL
        CALL SAVESCR
        JP BWindow

INVSP   LD HL,#C000
        LD BC,6144
FERMA   LD A,(HL)
        XOR #FF
        LD (HL),A
        INC HL
        DEC BC
        LD A,C
        OR B
        JR NZ,FERMA
        RET
;..
CUTT    CALL LOADSCR
        CALL SuxRam

        LD IX,WinCol
        CALL SAVEW
        CALL INVSP
        LD HL,(massad+1)
        PUSH HL
        LD A,(EFFOR)
        PUSH AF

        LD A,#AE
        LD (EFFOR),A
        LD HL,OUTNKN
        LD (massad+1),HL
        CALL MAKE_MASK
        LD IX,WinCol
        CALL LOADW

        POP AF
        LD (EFFOR),A
        POP HL
        LD (massad+1),HL
        CALL SAVESCR
        JP BWindow

OUTNK   PUSH DE
        PUSH HL
        LD DE,(M_PL)
        LD A,(DE)
        CPL
        OR (HL)
        LD (HL),A
        INC DE
        LD (M_PL),DE
        POP HL
        POP DE
        RET

OUTNKN  PUSH DE
        PUSH HL
        LD DE,(M_PL)
        LD A,(DE)
        CPL
        LD (HL),A
        INC DE
        LD (M_PL),DE
        POP HL
        POP DE
        RET
;................
OUTMSK  PUSH DE
        PUSH HL
        LD DE,(M_PL)
        LD A,(DE)
        AND (HL)
        LD (HL),A
        INC DE
        LD (M_PL),DE
        POP HL
        POP DE
        RET

; ПРОЦЕДУРЫ РАБОТЫ СО СПРАЙТАМИ

SAVEW   LD D,(IX+1)
        LD E,(IX+0)
        CALL RASCHA

atradrs LD DE,ATRSPR
        LD B,(IX+3)
U7      PUSH BC
        PUSH HL
        LD B,(IX+2)
U8      LD A,(HL)
        LD (DE),A
        INC HL
        INC DE
        DJNZ U8
        POP HL
        PUSH DE
        LD DE,32
        ADD HL,DE
        POP DE
        POP BC
        DJNZ U7

        LD D,(IX+0)
        LD E,(IX+1)
        CALL RASCH
scradrs LD DE,SCRSPR
        LD A,(IX+3)
        ADD A,A
        ADD A,A
        ADD A,A
        LD B,A
U9      PUSH BC
        LD B,(IX+2)
        PUSH HL
u1      LD A,(HL)
        LD (DE),A
        INC HL
        INC DE
        DJNZ u1
        POP HL
        CALL INC_Y
        POP BC
        DJNZ U9
        RET
;................
EXS:    POP AF
        POP AF
        JP TS1

EXA:    POP AF
        POP AF
        JP TS2

GRAN1   LD HL,(M_PL)
        DEC HL
grl1    INC DE
        INC HL
        DJNZ grl1
        LD (M_PL),HL
        JR TS3

GRAN2   INC DE
        DJNZ GRAN2
        JR TS4
;................
; СПРАЙТ=>ЭКРАН
;................
LOADW   LD E,(IX+1)
        LD D,(IX+0)
        CALL RASCH

scradrl LD DE,SCRSPR
        LD A,(IX+3)
        ADD A,A
        ADD A,A
        ADD A,A
        LD B,A
u2      PUSH BC
        PUSH HL
        LD B,(IX+2)
u3      LD A,H
        CP #58
        JP NC,EXS
massad  CALL Ret
        LD A,(DE)
EFFOR   NOP
        LD (HL),A
        INC HL
        LD A,#1F
        AND L
        JR Z,GRAN1
        INC DE
        DJNZ u3
TS3     POP HL
        CALL INC_Y
        POP BC
        DJNZ u2

TS1     LD A,(ATRW)
        AND A
        RET Z
        LD D,(IX+1)
        LD E,(IX+0)
        CALL RASCHA
atradrl LD DE,ATRSPR
        LD B,(IX+3)
u4      PUSH BC
        PUSH HL
        LD B,(IX+2)
u5      LD A,H
        CP #5B
        JR NC,EXA
        LD A,(DE)
        LD (HL),A
        INC HL
        LD A,#1F
        AND L
        JR Z,GRAN2
        INC DE
        DJNZ u5
TS4     POP HL
        LD BC,#20
        ADD HL,BC
        POP BC
        DJNZ u4
TS2     RET

CLSV    LD IX,WinCol
        JP CLSVV
;----------------------------------
ACO     DB 0
CCO     DB 0

_s       LD A,(Ch)
        AND A
        JR Z,in
        LD IX,TL
        LD B,8
1       PUSH BC
        CALL iP
        POP BC
        INC IX
        DJNZ 1b
        RET

iP      LD A,8
        SUB B
        LD B,A
        LD A,(HL)
        AND #38
        SRA A
        SRA A
        SRA A
        CP B
        RET NZ
        LD A,(IX+0)
         SLA A
         SLA A
         SLA A
        LD B,A
        LD A,(HL)
        AND #FF-#38
        OR B
        LD (HL),A
        POP AF
        POP AF
        RET

in      LD IX,TL
        LD B,8
        PUSH BC
        CALL iN
        POP BC
        INC IX
        DJNZ in+6
        RET

iN      LD A,8
        SUB B
        LD B,A
        LD A,(HL)
        AND #07
        CP B
        RET NZ
        LD A,(IX+0)
        LD B,A
        LD A,(HL)
        AND #FF-#07
        OR B
        LD (HL),A
        POP AF
        POP AF
        RET

rs      LD IX,TL
        LD B,8
        PUSH BC
        LD A,8
        SUB B
        LD (IX+0),A
        LD BC,ACOL
        PUSH AF
        CALL TAB_HL
        POP AF
        AND A
        CALL Z,zr
        LD (HL),A
        POP BC
        INC IX
        DJNZ rs+6
        JP e_

zr      LD A,7*8
        RET

Ac      LD (ACO),A
        LD HL,AW
        EX AF,AF'
        LD A,9
        CALL ofa
        JP e_

TL      DB 0,1,2,3,4,5,6,7
;--- Замена аттрибутов ----------------------
WChange DEFB 6,6,18,9,5*8,5,%00001110
        DEFB 0
        DEFW TChange      ; объект-текст
        DEFW SChange      ; объект-подсветка (выборка)
        DEFW Nil          ; горячие клавиши
        DEFW BChange      ; объект-кнопки (выборка)
        DEFW Nil          ; объект-флажки
        DEFW RChange      ; объект-радио кнопки
        DEFW #FFFF

RChange DEFB 6,6,0,2,0
Ch      EQU $-1
        DEFW Nil
        DEFB #FF

SChange ; DEFB 1,6,6,1,%10
        ; DEFB 1,7,6,1,%10
        DB 1,6,6,18+2,%10
        ; DEFB 12,6,5,1,%11
        ; DEFB 12,7,5,1,%11
        DB 12,6,5,128+2,%11
        DEFB #FF

TChange DB 22,1,6
;    if rus                    ; удалил из-за другого способа локализации /DA
;        DB #97,#a5,#e0,#ad,#a8,#ab,#a0,13;"Чернила",13
;        DB #81,#e3,#ac,#a0,#a3,#a0,13;"Бумага",13
;        DB 22,12,6
;        DB #87,#a0,#ac,#a5,#ad,#a8,#e2,#ec,13;"Заменить",13
;        DB #8e,#e2,#ac,#a5,#ad,#a8,#e2,#ec,0;"Отменить",0
;    else
;        DB "Ink",13
;        DB "Paper",13
;        DB 22,12,6
;        DB "Change",13
;        DB "Undo",0
;    endif

        MSG_WIN_Ink : DB 13
        MSG_WIN_Paper : DB 13
        DB 22,12,6
        MSG_WIN_Change : DB 13
        MSG_WIN_Undo : DB 0

BChange DB 1,1,2,2,7*8,%10
AW      DW ONS
        DB 3,1,2,2,1,%10
        DW OFFS
        DB 5,1,2,2,2,%10
        DW OFFS
        DB 7,1,2,2,3,%10
        DW OFFS
        DB 9,1,2,2,4,%10
        DW OFFS
        DB 11,1,2,2,5,%10
        DW OFFS
        DB 13,1,2,2,6,%10
        DW OFFS
        DB 15,1,2,2,7,%10
        DW OFFS

Aw      DB 1,3,2,2,7*8,%10
        DW OFFS
        DB 3,3,2,2,1,%10
        DW OFFS
        DB 5,3,2,2,2,%10
        DW OFFS
        DB 7,3,2,2,3,%10
        DW OFFS
        DB 9,3,2,2,4,%10
        DW OFFS
        DB 11,3,2,2,5,%10
        DW OFFS
        DB 13,3,2,2,6,%10
        DW OFFS
        DB 15,3,2,2,7,%10
        DW OFFS
        DB #FF

ACOL
    dw  Aw+4
    dw  Aw+4+8
    dw  Aw+4+16
    dw  Aw+4+24
    dw  Aw+4+32
    dw  Aw+4+40
    dw  Aw+4+48
    dw  Aw+4+56

;-------------------------
e_  LD A,%1100
        JR j0

CHA     CALL LOADSCR
        LD IX,WinCol
        CALL BoxCol
        LD A,%1110
j0      LD IX,WChange
        LD (IX+6),A
        CALL Win_
        PUSH AF
        CP #FF
        JP Z,BWindow
KJ      POP AF
        CP 2
        JR Z,ZP
        CP 3
        JP Z,rs
        LD A,(But)
        CP 8
        JP C,Ac
        SUB 8
        PUSH AF
        LD H,0
        LD L,A
        LD BC,TL
        ADD HL,BC
        LD A,(ACO)
        LD (HL),A
        POP AF
        LD BC,ACOL
        CALL TAB_HL
        LD A,(ACO)
        AND A
        CALL Z,zr
        LD (HL),A
        JR e_

ZP      CALL CLOSE
        LD IX,WinCol
        CALL BoxCol
        LD DE,#5800
        LD C,(IX+2)
        LD B,(IX+3)
        LD H,0
        LD L,(IX+1)
        DUP 5
        ADD HL,HL
        EDUP
        ADD HL,DE
        LD A,(IX+0)
        ADD A,L
        LD L,A

R1      PUSH BC
        PUSH HL
R2      CALL _s
        INC HL
        LD A,H
        CP #5B
        JR NC,EZ
        LD A,#1F
        AND L
        JR Z,KL
        DEC C
        JR NZ,R2
KL      POP HL
        POP BC
        LD DE,#20
        ADD HL,DE
        DJNZ R1
        CALL SAVESCR
        JP CHA

EZ      POP AF
        POP BC
        CALL SAVESCR
        JP CHA
;...................
DN8     LD A,(IX+3)
        DEC A
        RET Z
        HALT
        LD D,(IX+0)
        LD E,(IX+1)
        PUSH DE
        ADD A,E
        LD E,A
        CALL RASCH
        PUSH HL
        PUSH DE
        CALL TBF
        POP DE
        POP HL
        LD BC,#0700
        ADD HL,BC
        PUSH HL
        DEC E
        CALL RASCH
        ADD HL,BC
        POP DE
        LD B,0
        LD A,(IX+3)
        DEC A
        Amul8
dn8     PUSH AF
        PUSH HL
        PUSH DE
        LD C,(IX+2)
        LDIR
        POP DE
        POP HL
        CALL DEC_Y
        CALL DEC_YD
        POP AF
        DEC A
        JR NZ,dn8
        POP DE
        CALL RASCH
        EX DE,HL
        CALL RBF
        RET

DN8A    LD A,(IX+3)
        DEC A
        RET Z
        LD D,(IX+1)
        LD E,(IX+0)
        ADD A,D
        LD D,A
        CALL RASCHA
        PUSH HL
        LD DE,Buffer
        LD B,0
        LD C,(IX+2)
        LDIR
        POP HL
        EX DE,HL
        LD H,D
        LD L,E
        AND A
        LD BC,32
        SBC HL,BC
        LD B,0

        LD B,(IX+3)
        DEC B
dn8a    PUSH BC
        PUSH HL
        PUSH DE
        LD B,0
        LD C,(IX+2)
        LDIR
        LD BC,32
        POP DE
        EX DE,HL
        SBC HL,BC
        EX DE,HL
        POP HL
        SBC HL,BC
        POP BC
        DJNZ dn8a
        LD HL,Buffer
        LD B,0
        LD C,(IX+2)
        LDIR
        RET

UP8A    LD A,(IX+3)
        DEC A
        RET Z
        LD D,(IX+1)
        LD E,(IX+0)
        CALL RASCHA
        PUSH HL
        PUSH HL
        LD DE,Buffer
        LD B,0
        LD C,(IX+2)
        LDIR
        POP HL
        LD BC,32
        ADD HL,BC
        POP DE

        LD A,(IX+3)
        DEC A
up8a    PUSH HL
        PUSH DE
        LD C,(IX+2)
        LDIR
        LD C,32
        POP HL
        ADD HL,BC
        EX DE,HL
        POP HL
        ADD HL,BC
        DEC A
        JR NZ,up8a
        LD HL,Buffer
        LD B,0
        LD C,(IX+2)
        LDIR
        RET

TBF     LD DE,Buffer
        LD B,0
        LD A,8
up8     PUSH AF
        PUSH HL
        LD C,(IX+2)
        LDIR
        POP HL
        CALL INC_Y
        POP AF
        DEC A
        JR NZ,up8
        RET

RBF     LD HL,Buffer
        LD B,0
        LD A,8
Up8     PUSH AF
        PUSH DE
        LD C,(IX+2)
        LDIR
        POP DE
        CALL INC_YD
        POP AF
        DEC A
        JR NZ,Up8
        RET

UP8     LD A,(IX+3)
        DEC A
        RET Z
        HALT
        LD D,(IX+0)
        LD E,(IX+1)
        CALL RASCH
        PUSH HL
        CALL TBF
        POP DE
        LD A,(IX+3)
        DEC A
        Amul8
up8_    PUSH AF
        PUSH HL
        PUSH DE
        LD C,(IX+2)
        LDIR
        POP DE
        POP HL
        CALL INC_YD
        CALL INC_Y
        POP AF
        DEC A
        JR NZ,up8_
        CALL RBF
        RET

LFT8A   LD A,(IX+2)
        DEC A
        RET Z
        LD D,(IX+1)
        LD E,(IX+0)
        CALL RASCHA
        LD B,(IX+3)
lft8a   PUSH BC
        PUSH HL
        LD A,(HL)
        LD D,H
        LD E,L
        INC HL
        LD B,0
        LD C,(IX+2)
        DEC C
        LDIR
        LD (DE),A
        POP HL
        LD BC,32
        ADD HL,BC
        POP BC
        DJNZ lft8a
        RET

LFT8    LD A,(IX+2)
        DEC A
        RET Z
        HALT
        LD D,(IX+0)
        LD E,(IX+1)
        CALL RASCH
        LD A,(IX+3)
        Amul8
        LD B,A
lft8    PUSH BC
        PUSH HL
        LD A,(HL)
        LD D,H
        LD E,L
        INC HL
        LD B,0
        LD C,(IX+2)
        DEC C
        LDIR
        LD (DE),A
        POP HL
        CALL INC_Y
        POP BC
        DJNZ lft8
        RET

RGT8    LD A,(IX+2)
        DEC A
        RET Z
        HALT
        LD D,(IX+0)
        LD E,(IX+1)
        CALL RASCH
        LD B,0
        LD C,(IX+2)
        DEC C
        ADD HL,BC
        LD A,(IX+3)
        Amul8
        LD B,A
rgt8    PUSH BC
        PUSH HL
        LD D,H
        LD E,L
        LD A,(HL)
        DEC HL
        LD B,0
        LD C,(IX+2)
        DEC C
        LDDR
        LD (DE),A
        POP HL
        CALL INC_Y
        POP BC
        DJNZ rgt8
        RET

RGT8A   LD A,(IX+2)
        DEC A
        RET Z
        LD D,(IX+1)
        LD E,(IX+0)
        CALL RASCHA
        LD B,0
        LD C,(IX+2)
        DEC C
        ADD HL,BC
        LD B,(IX+3)
rgt8a   PUSH BC
        PUSH HL
        LD A,(HL)
        LD D,H
        LD E,L
        DEC HL
        LD B,0
        LD C,(IX+2)
        DEC C
        LDDR
        LD (DE),A
        POP HL
        LD BC,32
        ADD HL,BC
        POP BC
        DJNZ rgt8a
        RET

WinCol
RCOL    DB 0  ;+0
RROW    DB 0  ;+1
RLEN    DB 32 ;+2
RHGT    DB 24 ;+3

LWin8=$-BWINDOW
BFF
     DISPLAY "WinCOL len   :",/a,LWin8
        ENT

