; new code for RGB select (on bge v 3.12)
; used "Colors.asm" , used parts on old code "RGB1.asm"   /DA

ERGB     call prgb
        jp main

PRGB     call ERASE_ALLW
         call LOADSCR
PRGB2
prgb     ld de, Color            ; addr
         ld bc,PgnPage1*256+5   ; pos. COLORpgn
        jp CALLSWPhl

RgbSTND   ld a,7
RGBdefault  EQU $-1
          ld (REALRGB),a
ReMixRgb  xor a
          ld (MASKRGB),a
         ret

RetBorder push af
          ld a,(BORDER)
          out (#FE),a
          pop af
         ret


setDTRS     ; собираем пиктограммы цвета по маске:        ; /DA
            ; лев.верх. - br. , прав.верх. - flash
            ; лев.нижн. - ink , прав.нижн. - paper
         ld a,PgnPage2 | #10
         call Ram
         ld a,(MASKRGB)
         ld de,(DTRS-1)*32+#DB00
         call .bu
        jp   guiRAM

.bu      ld hl,(DTRMSS-1)*32+#DB00
         ld bc,32
         push de
         ldir
         pop de
         ld hl,(DTRCSS-1)*32+#DB00
         bit 6,a
         call z,.cop
         inc de
         inc hl
         bit 7,a
         call z,.cop
         ld c,15         ; b=0 после цикла
         add hl,bc
         ex de,hl
         add hl,bc
         ex de,hl
         ld c,a
         and 7
         ld a,c
         call z,.cop
         inc de
         inc hl
         and 7*8
         call z,.cop
        ret

.cop     push hl
         push de
         ld c,a
         ld b,8
1        ld a,(hl)
         inc hl
         inc hl
         ld (de),a
         inc de
         inc de
        djnz 1B
         ld a,c
         pop de
         pop hl
        ret






;-----------------------------------------------------------
; -- Мини-RGB меню (по клавише K) -----------------------
;-----------------------------------------------------------

Col       push ix
          ld ix,.Scol
          call POPUP
          call GETBLK
.l        call setDTRS
          ld de,DTRS
          call LoadSPR
          ld a,(REALRGB)
          call setv

1         ld h,255
          ld bc,#BFFE   ; for 'K'
2         in a,(c)
          bit 2,a
         jr z,3F
          dec h
         jr nz,2B
          call CLOSE
          pop ix
         ret

3         ld a,(REALRGB)    ; attr
          ld l,a
          ld a,(MASKRGB)
          ld h,a

          ld b,#F7      ; for '12345'
          in a,(c)
          rra
         jr nc,.im      ; 1 ink minus
          rra
         jr nc,.ip      ; 2 ink plus
          rra
         jr nc,.pm      ; 3 paper minus
          rra
         jr nc,.pp      ; 4 paper plus
          rra
         jr nc,.bs      ; 5 bright swap

          ld b,#EF      ; for '09876'
          in a,(c)
          rra
         jr nc,.st      ; 0  standart
          rra
         jr nc,.tr      ; 9  transparent / last
          rra
     ;    jr nc,         ; 8
          rra
     ;    jr nc,         ; 7
          rra
         jr nc,.fs      ; 6 flash swap
         jr 1B

.st       ld l,7    ; col
          ld h,0    ;mask
.setA     ld a,l
          ld (REALRGB),a
          ld a,h
          ld (MASKRGB),a
1         ld b,#F7
          in a,(c)
          cpl
          and #1F
         jr nz,1B
2         ld b,#EF
          in a,(c)
          cpl
          and #1F
         jr nz,2B
         jr .l

.tr        inc h
          jr z,.setA
           ld h,#FF
          jr .setA

.im         ld a,l
            dec a
           jr 1F
.ip         ld a,l
            inc a
1           and 7
            ld b,a
            ld a,h
            and #F8
            ld h,a
            ld a,l
            and #F8
2           or b
            ld l,a
           jr .setA
.pm         ld a,l
            sub 8
           jr 3F
.pp         ld a,l
            add a,8
3           and #38
            ld b,a
            ld a,h
            and #C7
            ld h,a
            ld a,l
            and #C7
           jr 2B

.bs         res 6,h
            ld a,l
            xor #40
1           ld l,a
           jr .setA
.fs         res 7,h
            ld a,l
            xor #80
           jr 1B

.Scol    DB 0,0,2,2


GetATR  LD A,(REALRGB)
        RET
endRGB

     display "RGB: ",/a,endRGB-ERGB