?login_element?

Subversion Repositories NedoOS

Rev

Rev 631 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.         DEVICE ZXSPECTRUM128
  2.         ;device pentagon1024
  3.  
  4.         include "../_sdk/sys_h.asm"
  5.  
  6. MAXCMDSZ=COMMANDLINE_sz-1 ;не считая терминатора
  7.  
  8.         include "windowsh.asm"
  9.      
  10. scrwid=320
  11. scrwid8=scrwid/8
  12. scrhgt=200
  13.  
  14. scrbase=0x8000
  15. scrbase16k=0x4000
  16.  
  17. tempc000=0x4000 ;круглое!
  18. tempe000=0x6000
  19.  
  20. editpal_c0=0x80
  21. editpal_e0=editpal_c0+0x20
  22. tabclippal=0xc000
  23.  
  24. titlehgt=8
  25.  
  26. workzonex8=4
  27. workzoney=8
  28. workzonewid8=scrwid/8-workzonex8-4
  29. workzonehgt=scrhgt-workzoney
  30.  
  31. rightpanelx8=workzonex8+workzonewid8
  32.  
  33. colorx8=0
  34. colory=scrhgt-16
  35. colorhgt=16
  36.  
  37. palettey=workzoney
  38. palettex8=rightpanelx8
  39.  
  40. navigatorx=rightpanelx8*8
  41. navigatory=palettey+(8*4)
  42. navigatorhgt=31 ;лучше не увеличивать, чтобы не было переполнения при умножении на bitmapwid (max 2048)
  43. navigatorwid=31
  44.  
  45. coordsx=navigatorx
  46. coordsy=navigatory+navigatorhgt+1
  47. coordswindowx=coordsx
  48. coordswindowy=coordsy+16
  49. coordswindowwid=32
  50. coordswindowhgt=32
  51.  
  52. ZONE_NO=0
  53. ZONE_TOP=1
  54. ZONE_LEFT=2
  55. ZONE_RIGHT=3
  56. ZONE_WORK=4
  57. ZONE_PAL=5
  58. ZONE_NAVIGATOR=6
  59.  
  60. TOOL_WINDOW=0
  61. TOOL_PENCIL=1
  62. TOOL_BRUSH=2
  63. TOOL_LINE=3
  64. TOOL_FILL=4
  65. TOOL_TEXT=5
  66. NTOOLS=6
  67.  
  68. ;backcolor=0x3f;%00111111
  69.  
  70. bmpmaxpages=251
  71. maxbitmaps=4
  72.        
  73. nofocuskey=0xff
  74.  
  75.         macro SHAPESPROC name
  76. ;_=$
  77.         ;org _curorg
  78. name
  79.         ;call setpgshapes
  80.         ;jp _
  81. ;_curorg=$
  82.         ;org _
  83.         endm
  84.  
  85.         macro SETPGBITMAPLOW
  86.         ld ($+4),a
  87.         ld a,(tbitmappages)
  88.         SETPG32KLOW
  89.         endm
  90.        
  91.         ;macro SETPGBITMAPHIGH
  92.         ;ld ($+4),a
  93.         ;ld a,(tbitmappages)
  94.         ;SETPG32KHIGH
  95.         ;endm
  96.  
  97.         org PROGSTART
  98. gfxeditor_begin
  99. main_go
  100. ;        jp main_go2
  101. ;        ds 256
  102. ;main_go2
  103.         ld sp,0x4000 ;не должен опускаться ниже 0x3b00! иначе возможна порча OS
  104.         OS_HIDEFROMPARENT
  105.         ld e,0 ;EGA
  106.         OS_SETGFX
  107.         ;OS_GETSCREENPAGES
  108. ;de=страницы 0-го экрана (d=старшая), hl=страницы 1-го экрана (h=старшая)
  109.         ;ld a,e
  110.         ;ld (setpgs_scr_low),a
  111.         ;ld a,d
  112.         ;ld (setpgs_scr_high),a
  113.        
  114.         OS_GETMAINPAGES
  115. ;dehl=номера страниц в 0000,4000,8000,c000
  116.         ld a,e
  117.         ld (curpgshapes),a
  118.         ld a,h
  119.         ld (curpgpal),a
  120.         ld a,l
  121.         ld (curpgtemp),a
  122.  
  123.         call cls
  124.         ;call setpgs_scr
  125.         ;call setpgshapes
  126.         ;xor a
  127.         ;call shapes_cls
  128.        
  129.         ld hl,COMMANDLINE ;command line
  130.         call skipword
  131.         call skipspaces
  132.         ld a,(hl)
  133.         or a
  134.         jr z,noautoload
  135. ;command line = "scratch <file to load>"
  136.         push hl
  137.         call findlastslash. ;de=after last slash or beginning of path
  138.         pop hl
  139.         push de
  140.         dec de
  141.         ld a,(de)
  142.         cp '/'
  143.         jr nz,$+4
  144.         xor a
  145.         ld (de),a ;отрезать имя файла
  146.         inc de
  147.         ex de,hl;ld de,wordbuf ;ASCIIZ string for parsing (в 0xc000...)
  148.         ;push de
  149.         jr nz,autoload_nopath
  150.         OS_CHDIR
  151. autoload_nopath
  152.         ;pop hl
  153.         ;call findlastslash.
  154.         pop de ;de=after last slash
  155.        
  156.         ld hl,fcb_filename ;Pointer to 11 byte buffer
  157.         OS_PARSEFNAME
  158.         call fcbtoname_temppicname ;de=temppicname
  159.         ;ld de,fcb
  160.         ;OS_FOPEN
  161.         OS_OPENHANDLE
  162.         or a
  163.         jr nz,noautoload;error
  164.         ld a,b
  165.         ld (curhandle),a
  166.         call readbmp ;nz=ошибка (тогда не менять имя файла)
  167.         jr nz,autoloaderror
  168.        
  169.         ld hl,fcb_filename ;Pointer to 11 byte buffer
  170.         ld de,curpicname
  171.         call cpmname_to_dotname
  172.  
  173. autoloaderror
  174.         ld de,fcb
  175.         OS_FCLOSE
  176.         jr autoloadq
  177. noautoload
  178.         ld bc,320 ;wid
  179.         ld de,200 ;hgt
  180.         xor a ;color
  181.         call newbitmap
  182. autoloadq
  183.        
  184.         ld de,pathbuf_forBDOS ;de=pointer to 64 byte (MAXPATH_sz!) buf
  185.         OS_GETPATH
  186.         ld a,(de)
  187.         sub '0'
  188.         ld (curdrive),a
  189.        
  190.         ;call initcontrol
  191.  
  192.         call showworkscreen
  193.        
  194. mainloop
  195.         call setpgs_scr
  196. ;1. всё выводим
  197. ;2. ждём событие
  198. ;3. всё стираем
  199. ;4. обрабатываем событие
  200.         call ahl_coords
  201.         call invarrzone ;инвертируем пункт под стрелкой
  202.         call ahl_coords
  203.         call showline ;рисуем новую линию
  204.         call ahl_coords
  205.         call showwindow ;рисуем новое окно
  206.         call ahl_coords
  207.         call showcopywindow ;рисуем новое окно копирования
  208.         call ahl_coords
  209.         call checkfirezone
  210.         ld (prarr_zone),a
  211.        
  212.         call setpgshapes
  213.  
  214.         call ahl_coords
  215.         call showbitmapcoords
  216.         call ahl_coords
  217.         call shapes_memorizearr
  218.         call ahl_coords
  219.         call shapes_prarr ;рисуем стрелку
  220.        
  221.         call waitsomething ;в это время стрелка видна
  222. ;что-то изменилось - стираем стрелку и старое окно, двигаем стрелку, рисуем новое окно и стрелку
  223.  
  224.         call setpgshapes
  225.        
  226.         call ahl_oldcoords
  227.         call shapes_rearr ;стираем стрелку
  228.         call ahl_oldcoords
  229.         call showcopywindow ;стираем старое окно копирования
  230.         call ahl_oldcoords
  231.         call showwindow ;стираем старое окно
  232.         call ahl_oldcoords
  233.         call showline ;стираем старую линию
  234.         call ahl_oldcoords
  235.         call invarrzone ;восстанавливаем (инвертируем) пункт под стрелкой
  236.  
  237.         ;call window_messages ;TODO
  238.         call control_mousebuttons
  239.         call control_keys
  240.  
  241.         jp mainloop
  242.  
  243. ahl_coords
  244.         ld a,(arry)
  245.         ld hl,(arrx)
  246.         ret
  247. ahl_oldcoords
  248.         ld a,(oldarry)
  249.         ld hl,(oldarrx)
  250.         ret
  251.  
  252. showline
  253. ;hl=x на экране
  254. ;a=y на экране
  255. curlinestate=$+1
  256.         ld c,0
  257.         dec c
  258.         ret nz
  259.         call checkfirezone
  260.         cp ZONE_WORK
  261.         ret nz
  262. ;out: bc=x cur, de=y cur в битмэпе (с клипированием по workzone)          
  263.         ;push bc
  264.         ;push de
  265.         ld (curlinex2),bc
  266.         ld (curliney2),de
  267.        
  268. curlinex=$+1
  269.         ld bc,-1 ;по умолчанию линия через shift недоступна
  270. curliney=$+1
  271.         ld de,0
  272. ;bc=x в bitmap
  273. ;de=y в bitmap
  274.         call calccoords_frombitmapcoords_noclip ;hl=x, de=y
  275.  
  276.         push hl ;x
  277.         push de ;y
  278.        
  279. curlinex2=$+1
  280.         ld bc,0
  281. curliney2=$+1
  282.         ld de,0
  283.         call calccoords_frombitmapcoords_noclip ;hl=x2, de=y2
  284.         ex de,hl ;hl=y2
  285.         push de
  286.         pop ix ;iy=x2
  287.  
  288.         pop de ;y
  289.         pop bc ;x
  290.        
  291.         call setpgshapes
  292. ;bc=x (в плоскости экрана, но может быть отрицательным)
  293. ;de=y (в плоскости экрана, но может быть отрицательным)
  294. ;ix=x2
  295. ;hl=y2
  296.         jp shapes_line
  297.        
  298. invarrzone
  299. ;инвертировать пункт под стрелкой
  300. ;hl=x на экране
  301. ;a=y на экране
  302.         push af ;y
  303.         call checkfirezone
  304.         pop bc ;b=y
  305.         cp ZONE_LEFT
  306.         ret nz
  307.         ld a,b;(arry)
  308.         call calccurtool
  309.         ret nc ;нет такой тулзы
  310.         add a,a
  311.         add a,a
  312.         add a,a
  313.         add a,a
  314.         add a,workzoney
  315.         ld b,a ;y
  316.         ld c,0 ;x/8
  317.         ld de,0x1004 ;d=hgt ;e=wid
  318.         call setpgshapes
  319.         call getcontrastcolors
  320.         jp shapes_invbox
  321.        
  322. control_mousebuttons
  323.         ld a,(mousebuttons)
  324.         cpl
  325.         and 7
  326.         cp 3
  327.         jr nc,mmb ;LMB+RMB или MMB
  328.         rra
  329.         jp c,fire
  330.         rra
  331.         jr c,rmb
  332.         ret ;никогда
  333.  
  334. isitclick
  335.         ld a,(oldmousebuttons)
  336.         cpl
  337.         and 7
  338.         ret ;nz=кнопку уже держали
  339.  
  340. mmb
  341.         call ahl_coords
  342.         call checkfirezone ;out: a=код зоны
  343.         cp ZONE_WORK
  344.         jr z,mmb_work
  345.         cp ZONE_PAL
  346.         ret nz ;не палитра
  347.         call ahl_coords
  348.         sub palettey
  349.         cp 4*8
  350.         ret nc ;не палитра
  351.         rra
  352.         and 0x0c
  353.         ld c,a
  354.         ld a,l
  355.         srl h
  356.         rra
  357.         srl h
  358.         rra
  359.         srl h
  360.         rra
  361.         sub palettex8
  362.         ret c ;не палитра
  363.         ;a=x8-palettex8
  364.         add a,c
  365.         add a,a
  366.         ld l,a
  367.         ld h,0
  368.         ld bc,workpal
  369.         add hl,bc ;hl=указатель на текущий цвет в палитре
  370.         ld (mmb_setpal_coloraddr),hl
  371.         ld a,(hl)
  372.         inc hl
  373.         ld h,(hl)
  374.         ld l,a
  375.         call editpal
  376. mmb_setpal_coloraddr=$+1
  377.         ld (0),hl
  378.         jp showworkscreen
  379. mmb_work
  380. ;рисование сеткой
  381. ;bc=x в bitmap, de=y в bitmap
  382.         ld a,(curcolor1)
  383.         ld (curcolorA),a
  384.         ld a,(curcolor2)
  385.         ld (curcolorB),a
  386.         ld a,(curtool1)
  387.         ld (curtool),a
  388.         xor a
  389.         ld (curmousebutton),a
  390.         jr fire_or_rmb_action_
  391.  
  392. rmb
  393.         ld a,(curcolor2)
  394.         ld (curcolorA),a
  395.         ld (curcolorB),a
  396.         ld a,(curtool2)
  397.         ld (curtool),a
  398.         ld a,1
  399.         ld (curmousebutton),a
  400.        
  401. fire_or_rmb_action_
  402.         call ahl_coords
  403.         call checkfirezone ;out: a=код зоны
  404.         cp ZONE_LEFT
  405.         jp z,setcurtool
  406.         cp ZONE_PAL
  407.         jp z,setcurcolor
  408.         cp ZONE_NAVIGATOR
  409.         jp z,fire_or_rmb_navigator
  410.         cp ZONE_TOP
  411.         jp z,filemenu
  412.         cp ZONE_WORK
  413.         ret nz
  414.         xor a
  415.         ld (windowcopymode),a ;меняем картинку - выключаем режим копирования
  416. ;bc=x в bitmap, de=y в bitmap
  417.         ld a,(curtool)
  418.         cp TOOL_PENCIL
  419.         jp z,fire_or_rmb_pencil
  420.         cp TOOL_LINE
  421.         jp z,fire_or_rmb_line
  422.         cp TOOL_FILL
  423.         jp z,fire_or_rmb_fill
  424.         cp TOOL_WINDOW
  425.         jp z,fire_or_rmb_window
  426.         cp TOOL_BRUSH
  427.         jp z,fire_or_rmb_brush
  428.         ret
  429.  
  430. fire_or_rmb_fill
  431.         ld a,(curcolorA)
  432.         ex af,af'
  433.        ld a,(curcolorB)
  434.        call fillbitmap
  435.        call setpgs_scr
  436.        jp showbitmap
  437.        
  438. fire
  439.        ld a,(curcolor1)
  440.        ld (curcolorA),a
  441.        ld (curcolorB),a
  442.        ld a,(curtool1)
  443.        ld (curtool),a
  444.        xor a
  445.        ld (curmousebutton),a
  446.        jr fire_or_rmb_action_
  447.  
  448. fire_or_rmb_line
  449. ;bc=x в bitmap, de=y в bitmap
  450.        call isitclick
  451.         ret nz ;кнопку уже держали
  452.        ld hl,(curlinestate)
  453.        dec l
  454.        jr z,fire_or_rmb_line_finish
  455.        ld a,1
  456.        ld (curlinestate),a
  457.        ld (curlinex),bc
  458.        ld (curliney),de
  459.        ret
  460. fire_or_rmb_line_finish
  461.        ld hl,(curliney)
  462.        ld ix,(curlinex)
  463.        ld a,(curcolorA)
  464.        ex af,af'
  465.         ld a,(curcolorB)
  466.         call prlinebitmap
  467.         xor a
  468.         ld (curlinestate),a
  469.         jp showbitmap
  470.  
  471. fire_or_rmb_brush
  472. ;bc=x в bitmap, de=y в bitmap
  473.         ld (minx),bc
  474.         ld (maxx),bc
  475.         ld (miny),de
  476.         ld (maxy),de
  477.        
  478.         ;call ahl_oldcoords
  479.         ;call checkfirezone ;out: a=код зоны
  480.         ;cp ZONE_WORK
  481.         ;jr nz,firebrushpixel ;старое положение было вне рабочей зоны - линию нельзя (TODO клипировать линию)
  482.  
  483.         call ahl_oldcoords
  484.         call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  485.         push bc ;x2
  486.         push de ;y2
  487.         call ahl_coords
  488.         call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  489.         ld (curlinex),bc
  490.         ld (curliney),de
  491.         pop hl ;y2
  492.         or a
  493.         sbc hl,de
  494.         ld (brushlinedy),hl
  495.         pop hl ;x2
  496.         or a
  497.         sbc hl,bc
  498.         ld (brushlinedx),hl
  499.        
  500. ;firebrushpixel
  501.         ;call ahl_coords
  502.         ;call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  503. ;bc=x в bitmap, de=y в bitmap
  504.         call firepixelpp
  505.         dec bc
  506.         call firepixelpp
  507.         dec de
  508.         call firepixelpp
  509.         inc bc
  510.         call firepixelpp
  511.         inc bc
  512.         call firepixelpp
  513.         inc de
  514.         call firepixelpp
  515.         inc de
  516.         call firepixelpp
  517.         dec bc
  518.         call firepixelpp
  519.         dec bc
  520.         call firepixelpp
  521.        
  522.         jp fire_scrupdate
  523.        
  524. firepixelpp
  525.         call checkminmaxxy
  526. ;bc=x в bitmap (не портится)
  527. ;de=y в bitmap (не портится)
  528.         ;jr $
  529.         push bc
  530.         push de
  531. brushlinedx=$+2
  532.         ld ix,0
  533.         add ix,bc
  534. brushlinedy=$+1
  535.         ld hl,0
  536.         add hl,de
  537.        
  538.         push bc
  539.         push de
  540.         push ix
  541.         pop bc
  542.         ex de,hl
  543.         call checkminmaxxy ;портит hl
  544.         ex de,hl
  545.         pop de
  546.         pop bc
  547.  
  548.         ld a,(curcolorA)
  549.         ex af,af'
  550.        ld a,(curcolorB)
  551.        ;call setpixel_fast_coloraa
  552.        call prlinebitmap
  553.  
  554.        pop de
  555.        pop bc
  556.        ret
  557.  
  558. fire_or_rmb_pencil        
  559. ;bc=x в bitmap, de=y в bitmap (всегда положительные, т.к. мы в workzone - TODO при удержании режима рисования учесть отрицательные)
  560.        ld (minx),bc
  561.        ld (maxx),bc
  562.        ld (miny),de
  563.        ld (maxy),de
  564.        
  565.        ;call ahl_oldcoords
  566.        ;call checkfirezone ;out: a=код зоны
  567.        ;cp ZONE_WORK
  568.        ;jr nz,firepixel ;старое положение было вне рабочей зоны - линию нельзя
  569. fireline
  570.        ;ld a,0xfe
  571.        ;in a,(0xfe)
  572.         ld a,(cur_cs_halfrow)
  573.        rra ;Caps Shift
  574.        jr c,fireline_noshift
  575.        ld bc,(curlinex)
  576.        ld a,b
  577.        inc a
  578.        ret z ;0xffxx - нет предыдущей точки
  579.        ld de,(curliney)
  580.        jr fireline_noshiftq
  581. fireline_noshift
  582.        call ahl_oldcoords
  583.        call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  584. fireline_noshiftq
  585.        call checkminmaxxy
  586.        push bc ;x2
  587.        push de ;y2
  588.        call ahl_coords
  589.        call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  590.        ld (curlinex),bc
  591.        ld (curliney),de
  592.        call checkminmaxxy
  593.        pop hl ;y2
  594.        pop ix ;x2
  595.        ld a,(curcolorA)
  596.        ex af,af'
  597.         ld a,(curcolorB)
  598.         call prlinebitmap
  599.        
  600.         if 1==0
  601.        
  602.         jr fire_scrupdate
  603.        
  604. firepixel
  605.         call ahl_coords
  606.         call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  607.         call checkminmaxxy
  608. ;bc=x в bitmap (не портится)
  609. ;de=y в bitmap (не портится)
  610.         ld a,(curcolorA)
  611.         ex af,af'
  612.        ld a,(curcolorB)
  613.        call setpixel_fast_coloraa
  614.        
  615.        endif
  616.        
  617. fire_scrupdate
  618. ;обновить часть экрана
  619. ;bc=minx
  620. ;de=miny
  621. ;hl=maxx, maxy
  622.        call setpgs_scr
  623. minx=$+1
  624.        ld bc,0
  625. miny=$+1
  626.        ld de,0
  627.        call calccoords_frombitmapcoords ;hl=x,a=y(min)
  628.        dup 3
  629.        srl h
  630.        rr l
  631.        edup
  632.        push af
  633.        push hl ;x/8(min)
  634. maxx=$+1
  635.        ld bc,0
  636. maxy=$+1
  637.        ld de,0
  638. ;отсекаем координаты сверху, чтобы не делать это каждый раз в checkminmaxxy
  639.        ld hl,(curbitmapwid_edit)
  640.        dec hl
  641.        call minhl_bc_tobc
  642.        ld hl,(curbitmaphgt)
  643.        dec hl
  644.        or a
  645.        sbc hl,de
  646.        add hl,de
  647.        jr nc,$+3 ;de<=hl
  648.        ex de,hl
  649.        call calccoords_frombitmapcoords ;hl=x,a=y(max)
  650.        dup 3
  651.        srl h
  652.        rr l
  653.        edup
  654.        inc hl ;hl=x/8(max) с округлением в большую сторону
  655.        pop de ;x/8(min)
  656.        pop bc ;y(min)
  657.        inc a ;y(max) с округлением в большую сторону
  658.        sub b ;y(max)-y(min)
  659.         ;jr z,$ ;ret z
  660.        ld hy,a ;hy=hgt
  661.        ld a,l ;x/8(max) с округлением в большую сторону
  662.        sub e ;x/8(min)
  663.         ;jr z,$ ;ret z
  664.        ld lx,a ;lx=wid(chr)
  665.        ld l,e
  666.        ld h,b
  667.        push hl ;h=y на экране, l=x на экране
  668.        ex de,hl
  669.        add hl,hl
  670.        add hl,hl
  671.        add hl,hl ;hl=x(min)
  672.        ld a,b ;a=y(min)
  673.        call calcbitmapcoords
  674.        ld h,b
  675.        ld l,c ;hl=x в bitmap ;de=y в bitmap
  676.        pop bc ;b=y на экране, c=x на экране
  677.        jp prbitmapbox
  678.  
  679. setcurcolor
  680.        call isitclick
  681.         ret nz ;кнопку уже держали
  682.        ld a,(curmousebutton)
  683.        or a
  684.        ld de,curcolor1
  685.        jr z,$+5
  686.        ld de,curcolor2
  687.        call ahl_coords
  688.        sub palettey
  689.        rra
  690.        and 0x0c
  691.        ld bc,-palettex8*8
  692.        add hl,bc
  693.        srl l
  694.        srl l
  695.        srl l
  696.        add a,l
  697.        ld (de),a
  698.        jp showcurcolor
  699.        
  700. checkfirecoords
  701. ;hl=x на экране, a=y на экране
  702. ;out: CY=вне битмэпа
  703. ;bc=x в bitmap, de=y в bitmap
  704.        call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  705.        ld hl,(curbitmapwid_edit)
  706.        scf
  707.        sbc hl,bc
  708.        ret c ;x>(bitmapwid-1) => x>=bitmapwid
  709.        ld hl,(curbitmaphgt)
  710.        scf
  711.        sbc hl,de
  712.        ret ;CY: y>(bitmaphgt-1) => y>=bitmaphgt
  713.  
  714. checkminmaxxy
  715. ;bc=x, de=y (могут быть отрицательные) (не портятся)
  716.        bit 7,b
  717.        jr nz,checkminmaxxy_nox
  718.        ld hl,(maxx)
  719.        or a
  720.        sbc hl,bc
  721.        jr nc,$+6
  722.        ld (maxx),bc
  723.        ld hl,(minx)
  724.        or a
  725.        sbc hl,bc
  726.        jr c,$+6
  727.        ld (minx),bc
  728.        jr checkminmaxxy_xq
  729. checkminmaxxy_nox
  730.        ld hl,0
  731.        ld (minx),hl
  732. checkminmaxxy_xq
  733.        bit 7,d
  734.        jr nz,checkminmaxxy_noy
  735.        ld hl,(maxy)
  736.        or a
  737.        sbc hl,de
  738.        jr nc,$+6
  739.        ld (maxy),de
  740.        ld hl,(miny)
  741.        or a
  742.        sbc hl,de
  743.        ret c
  744.        ld (miny),de
  745.        ret
  746. checkminmaxxy_noy
  747.        ld hl,0
  748.        ld (miny),hl
  749.        ret
  750.        
  751. control_keys
  752. key=$+1
  753.        ld a,0
  754.        cp key_left
  755.        jp z,control_keys_left
  756.        cp key_down
  757.        jp z,control_keys_down
  758.        cp key_up
  759.        jp z,control_keys_up
  760.        cp key_right
  761.        jp z,control_keys_right
  762.        cp '+'
  763.        jp z,control_keys_plus
  764.        cp '-'
  765.        jp z,control_keys_minus
  766.        cp 'n'
  767.        jp z,control_keys_new
  768.        cp 'c'
  769.        jp z,control_keys_clear
  770.        cp 'w'
  771.        jp z,window_allpicture
  772.        cp 'v'
  773.        jp z,window_copy
  774.        cp 'V'
  775.        jp z,window_copy
  776.        cp 'z'
  777.        jp z,control_keys_swapcolors
  778.        cp 'x'
  779.        jp z,window_mirrhor
  780.        cp 'y'
  781.        jp z,window_mirrver
  782.        cp key_redraw
  783.        jp z,showworkscreen
  784.        sub '1'
  785.        cp 4
  786.        jp c,control_keys_selectbmp
  787.        
  788.        ret
  789.        
  790. control_keys_new
  791.        ;ld lx,0b00111111 ;background fill color byte 0bRLrrrlll
  792.        ;ld hx,0b00000000 ;11111111 ;brush color byte 0bRLrrrlll
  793.        call getcontrastcolors
  794.        ld iy,win_new
  795.        call window_start
  796.        call window_mainloop
  797. ;restore screen:
  798.        call showworkscreen
  799.        ret
  800.        
  801. getcontrastcolors
  802.        push bc
  803.        push de
  804.        push hl
  805.        ld hl,workpal
  806. ;DDp palette: %grbG11RB(low),%grbG11RB(high), инверсные
  807. ;high B, high b, low B, low b
  808.        ld ix,0x00ff ;hx=current max, lx=current min
  809.        ;ld iy,0x0000 ;hy=current max index, ly=current min index
  810.        ld c,16
  811. getcontrastcolors0
  812.        ld e,(hl)
  813.        inc hl
  814.        ld d,(hl)
  815.        inc hl
  816.        push hl
  817.        ex de,hl
  818.        call calchexcolor
  819. ;b=0xBB
  820. ;d=0xRR
  821. ;e=0xGG
  822.        ld a,b
  823.        and 0x0f
  824.        ld b,a
  825.        ld a,d
  826.        and 0x0f
  827.        ld d,a
  828.        ld a,e
  829.        and 0x0f
  830.        ld e,a
  831.        add a,b
  832.        add a,d
  833.        cp hx ;current max
  834.        jr c,getcontrastcolors_nmax
  835.        ld hx,a
  836.        ld hy,c
  837. getcontrastcolors_nmax
  838.        cp lx ;current min
  839.        jr nc,getcontrastcolors_nmin
  840.        ld lx,a
  841.        ld ly,c
  842. getcontrastcolors_nmin
  843.        pop hl
  844.        dec c
  845.        jr nz,getcontrastcolors0
  846. ;hy=current max index (for background), ly=current min index (for brush)
  847.        ld h,tpixelrecode/256
  848.        ld a,16
  849.        sub hy
  850.        ld l,a
  851.        ld a,(hl)
  852.        ld lx,a
  853.        ld a,16
  854.        sub ly
  855.        ld l,a
  856.        ld a,(hl)
  857.        ld hx,a
  858.        ;ld lx,0b00111111 ;background fill color byte 0bRLrrrlll
  859.        ;ld hx,0b00000000 ;11111111 ;brush color byte 0bRLrrrlll
  860.        pop hl
  861.        pop de
  862.        pop bc
  863.        ret
  864.  
  865. getgreycolor
  866.        ld a,0b00111111
  867.        ret
  868.  
  869. getblackongrey
  870.        call getcontrastcolors
  871.        call getgreycolor
  872.        ld lx,a
  873.        ret
  874.  
  875. buttoncancel_unclick
  876.        jp window_close
  877. buttonok_unclick
  878. ;TODO check sizes
  879.        ld hl,win_new_twid
  880.        call strtoint
  881.        dec hl
  882.        ld bc,2048
  883.        or a
  884.        sbc hl,bc
  885.        add hl,bc
  886.        inc hl
  887.        ret nc ;wrong number
  888.         ld (buttonok_wid),hl
  889.        ld hl,win_new_thgt
  890.        call strtoint
  891.        dec hl
  892.        ld bc,2048
  893.        or a
  894.        sbc hl,bc
  895.        add hl,bc
  896.        inc hl
  897.        ret nc ;wrong number
  898. ;new image:
  899.        push hl
  900.        call delbitmap ;удалить текущую картинку и освободить странички
  901. buttonok_wid=$+1
  902.        ld hl,0
  903.        ld (curbitmapwid_edit),hl
  904.        pop hl
  905.        ld (curbitmaphgt),hl
  906.        call reserve_bmp_pages ;там genmuldewid_ahl
  907.        
  908.        ld bc,0 ;bc=x in bitmap
  909.        ld de,0 ;de=y in bitmap
  910.        ld hl,(curbitmapwid_edit) ;hl=wid
  911.        ld ix,(curbitmaphgt) ;ix=hgt
  912.        
  913.        ld a,(win_new_flag0color_flags)
  914.        bit WINELEMENT_FLAG_CHECKED,a
  915.        ld a,0
  916.        jr nz,newimage_q
  917.        ld a,(win_new_flagbrushcolor_flags)
  918.        bit WINELEMENT_FLAG_CHECKED,a
  919.        ld a,(curcolor1) ;a=color1
  920.        jr nz,$+5
  921.        ld a,(curcolor2) ;a=color1
  922. newimage_q
  923.        call bitmap_fillbox
  924.  
  925.        jp window_close
  926. reter
  927.        ret
  928.      
  929. win_new
  930. ;x/2,y,wid/2,hgt
  931.        db 52,10,64,64
  932.        db 0b1000 ;flags
  933. ; Bit 0 - рамка не рисуется (don't draw frame)
  934. ; Bit 1 - reserved
  935. ; Bit 2 - таскать окно по экрану (movable window)
  936. ; Bit 3 - выход из окна-ткнуть только лишь за пределами (CANCEL by clicking outside the window)
  937.  
  938. ;;window elements (linked list)
  939. ;link16 ;0=end of list
  940. ;x/2,y,wid/2,hgt
  941. ;type
  942. ;checked
  943. ;hidden
  944. ;disabled
  945. ;onclick16
  946. ;onunclick16
  947. ;onmove16
  948. win_new_title
  949.         STARTWINELEMENT
  950.         dw win_new_flagbgcolor ;0=end of list
  951.         db 24,3,9*2,8
  952.         db T_LABEL
  953.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  954.         db 0 ;hotkey
  955.         dw reter ;onclick16
  956.         dw reter ;onunclick16
  957.         dw reter ;onmove16
  958.         PADWINELEMENT
  959.         db "New image",0
  960.        
  961. win_new_flagbgcolor
  962.         STARTWINELEMENT
  963.         dw win_new_flagbrushcolor ;0=end of list
  964.         db 24,14,4,8
  965.         db T_RADIO
  966. win_new_flagbgcolor_flags
  967.         db 0b1001 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  968.         db 0 ;hotkey
  969.         dw reter ;onclick16
  970.         dw reter ;onunclick16
  971.         dw reter ;onmove16
  972.         PADWINELEMENT
  973.         db "Background color",0
  974.        
  975. win_new_flagbrushcolor
  976.         STARTWINELEMENT
  977.         dw win_new_flag0color ;0=end of list
  978.         db 24,22,4,8
  979.         db T_RADIO
  980. win_new_flagbrushcolor_flags
  981.         db 0b1000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  982.         db 0 ;hotkey
  983.         dw reter ;onclick16
  984.         dw reter ;onunclick16
  985.         dw reter ;onmove16
  986.         PADWINELEMENT
  987.         db "Brush color",0
  988.        
  989. win_new_flag0color
  990.         STARTWINELEMENT
  991.         dw win_new_labelhgt ;0=end of list
  992.         db 24,30,4,8
  993.         db T_RADIO
  994. win_new_flag0color_flags
  995.         db 0b1000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  996.         db 0 ;hotkey
  997.         dw reter ;onclick16
  998.         dw reter ;onunclick16
  999.         dw reter ;onmove16
  1000.         PADWINELEMENT
  1001.         db "Color 0",0
  1002.        
  1003. win_new_labelhgt
  1004.         STARTWINELEMENT
  1005.         dw win_new_edithgt ;0=end of list
  1006.         db 8,14,8,8
  1007.         db T_LABEL
  1008.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1009.         db 0 ;hotkey
  1010.         dw reter ;onclick16
  1011.         dw reter ;onunclick16
  1012.         dw reter ;onmove16
  1013.         PADWINELEMENT
  1014.         db "Hgt=",0
  1015.        
  1016. win_new_edithgt
  1017.         STARTWINELEMENT
  1018.         dw win_new_labelwid ;0=end of list
  1019.         db 16,14,8,8
  1020.         db T_EDIT
  1021.         db 0b1000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1022.         db 0 ;hotkey
  1023.         dw reter ;onclick16
  1024.         dw reter ;onunclick16
  1025.         dw reter ;onmove16
  1026.         PADWINELEMENT
  1027. win_new_thgt
  1028.         db "192 ",0
  1029.        
  1030. win_new_labelwid
  1031.         STARTWINELEMENT
  1032.         dw win_new_editwid ;0=end of list
  1033.         db 8,24,8,8
  1034.         db T_LABEL
  1035.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1036.         db 0 ;hotkey
  1037.         dw reter ;onclick16
  1038.         dw reter ;onunclick16
  1039.         dw reter ;onmove16
  1040.         PADWINELEMENT
  1041.         db "Wid=",0
  1042.        
  1043. win_new_editwid
  1044.         STARTWINELEMENT
  1045.         dw win_new_buttonok ;0=end of list
  1046.         db 16,24,8,8
  1047.         db T_EDIT
  1048.         db 0b1000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1049.         db 0 ;hotkey
  1050.         dw reter ;onclick16
  1051.         dw reter ;onunclick16
  1052.         dw reter ;onmove16
  1053.         PADWINELEMENT
  1054. win_new_twid
  1055.         db "256 ",0
  1056.        
  1057. win_new_buttonok
  1058.         STARTWINELEMENT
  1059.         dw win_new_buttoncancel ;0=end of list
  1060.         db 8,40,20,16
  1061.         db T_BUTTON
  1062.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1063.         db 0 ;hotkey
  1064.         dw reter ;onclick16
  1065.         dw buttonok_unclick ;onunclick16
  1066.         dw reter ;onmove16
  1067.         PADWINELEMENT
  1068.         db "OK",0
  1069.        
  1070. win_new_buttoncancel
  1071.         STARTWINELEMENT
  1072.         dw 0 ;0=end of list
  1073.         db 36,40,20,16
  1074.         db T_BUTTON
  1075.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1076.         db 0 ;hotkey
  1077.         dw reter ;onclick16
  1078.         dw buttoncancel_unclick ;onunclick16
  1079.         dw reter ;onmove16
  1080.         PADWINELEMENT
  1081.         db "Cancel",0
  1082.        
  1083.  
  1084.        
  1085. control_keys_swapcolors
  1086.         ld hl,(curcolor1) ;1, 2
  1087.         ld a,l
  1088.         ld l,h
  1089.         ld h,a
  1090.         ld (curcolor1),hl
  1091.         jp showworkscreen
  1092.        
  1093. control_keys_selectbmp
  1094.         call selectbmp
  1095.         call kill_unfinished_shapes
  1096.         jp showworkscreen ;control_scale_checksize
  1097.  
  1098. kill_unfinished_shapes
  1099.         xor a
  1100.         ld (curlinestate),a ;убиваем недоопределённую линию
  1101.         dec a
  1102.         ld (curlinex+1),a ;отменяем начальную точку линии через shift
  1103.          ld a,(curwindowstate)
  1104.          dec a
  1105.          call z,clearwindowstate ;убиваем недоопределённое окно
  1106.         ret
  1107.  
  1108. findcurbitmap
  1109. ;a=номер
  1110.         ld c,a
  1111.         ld b,0
  1112.         ld de,bitmapstruct_sz
  1113.         call mulbcde_ahl
  1114.         ld bc,bitmaps
  1115.         add hl,bc
  1116.         ret
  1117.        
  1118. control_keys_right
  1119.         call control_getscrollvalue ;de=scrollvalue
  1120.         ld hl,(curbitmapxscroll)
  1121.         add hl,de
  1122. control_keys_setxscroll
  1123.         ld (curbitmapxscroll),hl
  1124. control_scroll_emptyqueue_checksize
  1125.          ;call emptykeyqueue
  1126. emptykeyqueue0
  1127.         GET_KEY
  1128.         or a
  1129.         jr nz,emptykeyqueue0
  1130. control_scroll_checksize
  1131.         call control_scroll_checksizepp
  1132.         call shownavigator
  1133.         call showtitle
  1134.         jp showbitmap
  1135. control_scroll_checksizepp
  1136.         ld hl,+(workzonex8+workzonewid8)*8 ;hl=x
  1137.         ld a,workzoney+workzonehgt ;a=y        
  1138.         call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  1139.  
  1140.         ld hl,(curbitmaphgt)
  1141.         or a
  1142.         sbc hl,de
  1143.         jr nc,control_scroll_nocorrecty ;hgt>=y
  1144. ;hl<0 (сколько лишних пикселей bitmap по y)
  1145. ;посчитать bitmaphgt-(workzonehgt/scale) = bitmaphgt+hl
  1146.         ld de,workzonehgt
  1147.         call scalescrcoords
  1148.         ld hl,(curbitmaphgt)
  1149.         call subhldecheck0
  1150.         ld (curbitmapyscroll),hl
  1151. control_scroll_nocorrecty
  1152.         ld hl,(curbitmapwid_edit)
  1153.         or a
  1154.         sbc hl,bc
  1155.         ret nc ;wid>=x
  1156. ;hl<0 (сколько лишних пикселей bitmap по x)
  1157. ;посчитать bitmapwid-(workzonewid/scale) = bitmapwid+hl
  1158.         ld de,workzonewid8*8
  1159.         call scalescrcoords
  1160.         ld hl,(curbitmapwid_edit)
  1161.         call subhldecheck0
  1162.         ld (curbitmapxscroll),hl
  1163.         ret
  1164.        
  1165. control_keys_left
  1166.         call control_getscrollvalue ;de=scrollvalue
  1167.         ld hl,(curbitmapxscroll)
  1168.         ;or a
  1169.         ;sbc hl,de
  1170.         ;jr nc,$+5
  1171.         ;ld hl,0
  1172.         call subhldecheck0
  1173.         jr control_keys_setxscroll
  1174.        
  1175. control_keys_down
  1176.         call control_getscrollvalue ;de=scrollvalue
  1177.         ld hl,(curbitmapyscroll)
  1178.         add hl,de
  1179. control_keys_setyscroll
  1180.         ld (curbitmapyscroll),hl
  1181.         jr control_scroll_emptyqueue_checksize
  1182.  
  1183. control_keys_up
  1184.         call control_getscrollvalue ;de=scrollvalue
  1185.         ld hl,(curbitmapyscroll)
  1186.         ;or a
  1187.         ;sbc hl,de
  1188.         ;jr nc,$+5
  1189.         ;ld hl,0
  1190.         call subhldecheck0
  1191.         jr control_keys_setyscroll
  1192.  
  1193. control_getscrollvalue
  1194.         ld de,64
  1195.         jp scalescrcoords
  1196.        
  1197. control_scale_checksize
  1198.         call control_scroll_checksizepp
  1199.  
  1200.         call setpgshapes
  1201.  
  1202.         ld bc,workzoney*256 + workzonex8 ;b=y ;c=x/8
  1203.         ld de,workzonehgt*256 + workzonewid8 ;d=hgt ;e=wid8
  1204.         ld a,0x3f;%00111111 ;a=%33210210
  1205.         call shapes_fillbox
  1206.         jp control_scroll_checksize;showworkscreen
  1207. control_keys_plus
  1208.         ld a,(curbitmapscale)
  1209.         inc a
  1210.         cp 5+1
  1211.         jr c,$+3
  1212.         dec a
  1213.         ld (curbitmapscale),a
  1214.         jp control_scroll_checksize ;не нужно перепечатывать пустое место
  1215. control_keys_minus
  1216.         ld a,(curbitmapscale)
  1217.         dec a
  1218.         jr nz,$+3
  1219.         inc a
  1220.         ld (curbitmapscale),a
  1221.         jp control_scale_checksize
  1222.  
  1223. control_keys_clear
  1224.         ld a,(curwindowstate)
  1225.         cp 2
  1226.         ret nz
  1227.         ld bc,(curwindowx) ;bc=x в bitmap
  1228.         ld de,(curwindowy) ;de=y в bitmap
  1229.         ld hl,(curwindowwid) ;hl=wid
  1230.         ld ix,(curwindowhgt) ;ix=hgt
  1231.         ld a,(curcolor2)
  1232.         ex af,af'
  1233.        ld a,(curcolor2)
  1234. ;a=color1
  1235. ;a'=color2
  1236.         call bitmap_fillbox
  1237.         jp showbitmap
  1238.  
  1239. checkfirezone
  1240. ;hl=x
  1241. ;a=y
  1242. ;out: a=код зоны и для ZONE_WORK: bc=x в bitmap, de=y в bitmap
  1243.         ld c,a
  1244.         cp workzoney
  1245.         ld a,ZONE_TOP
  1246.         ret c ;top
  1247.         ld a,ZONE_LEFT
  1248.         ld de,workzonex8*8
  1249.         ;or a
  1250.         sbc hl,de
  1251.         add hl,de
  1252.         ret c ;left
  1253.         ld de,+(workzonex8+workzonewid8)*8
  1254.         ;or a
  1255.         sbc hl,de
  1256.         add hl,de
  1257.         ld a,c
  1258.         jr nc,checkfirezone_right ;right
  1259.         call checkfirecoords ;CY=вне битмэпа
  1260.         ld a,ZONE_NO
  1261.         ret c ;bc=x в bitmap, de=y в bitmap
  1262.         ld a,ZONE_WORK
  1263.         ret
  1264. checkfirezone_right
  1265.         cp navigatory
  1266.         ld a,ZONE_PAL
  1267.         ret c ;pal
  1268.         cp navigatory+navigatorhgt
  1269.         ld a,ZONE_NAVIGATOR
  1270.         ret c ;navigator
  1271.         ld a,ZONE_RIGHT
  1272.         ret ;right
  1273.  
  1274. showworkscreen
  1275.         call setpgs_scr
  1276.         call setpgshapes
  1277.         call getgreycolor ;ld a,backcolor
  1278.         call shapes_cls
  1279.  
  1280.         call showtitle
  1281.         call showbitmap
  1282.         call showtools
  1283.         call showcurcolor
  1284.         call showpalette
  1285.  
  1286.         jp shownavigator
  1287.        
  1288. showcurcolor
  1289.         call setpgshapes
  1290.  
  1291.         ld de,256*colorhgt+2
  1292.         push de ;y
  1293.         ld bc,256*colory+colorx8
  1294.         ld a,(curcolor1)
  1295.         call shapes_colortocolormask
  1296.         call shapes_prbox
  1297.         ;ld de,256*colorhgt+2
  1298.         pop de ;y
  1299.         ld bc,256*colory+colorx8+2
  1300.         ld a,(curcolor2)
  1301.         call shapes_colortocolormask
  1302.         jp shapes_prbox
  1303.  
  1304. calccurtool
  1305. ;a=y
  1306. ;определяет номер тулзы по координатам стрелки
  1307. ;out: a=tool, NC: a>=NTOOLS
  1308.         sub 8
  1309.         rra
  1310.         rra
  1311.         rra
  1312.         rra
  1313.         and 0x0f
  1314.         cp NTOOLS
  1315.         ret
  1316.  
  1317. setcurtool
  1318.         call isitclick
  1319.         ret nz ;кнопку уже держали
  1320.         xor a
  1321.         ld (curlinestate),a ;отменить недоопределённую линию
  1322. curmousebutton=$+1 ;0=LMB
  1323.         or 0
  1324.         ld hl,curtool1
  1325.         jr z,$+5
  1326.         ld hl,curtool2
  1327.         ld a,(arry)
  1328.         call calccurtool
  1329.         ret nc ;>=NTOOLS
  1330.         ld (hl),a
  1331.         cp TOOL_WINDOW
  1332.         jr nz,showcurtool
  1333.         ld a,1
  1334.         ld (windowcopymode),a
  1335.         ;jp showcurtool
  1336. showcurtool
  1337.         call setpgshapes
  1338.  
  1339.         ld bc,256*(colory-10)+colorx8+1
  1340.         call calcscr_from_xchr_y        
  1341.         ld de,text_ntool
  1342.         ld a,(curtool1)
  1343.         add a,'0'
  1344.         ld (de),a
  1345.         inc de
  1346.         inc de
  1347.         ld a,(curtool2)
  1348.         add a,'0'
  1349.         ld (de),a
  1350.         dec de
  1351.         dec de
  1352.         call getcontrastcolors ;ld ix,0xff00+backcolor
  1353.         jp shapes_prtext48ega;_oncolor
  1354.  
  1355. text_ntool
  1356.         db "0 0",0
  1357.        
  1358. showtools
  1359.         call setpgshapes
  1360.         call getcontrastcolors ;ld ix,0x0000+backcolor
  1361.         call getgreycolor ;ld a,backcolor
  1362.         ld lx,a
  1363.         ld de,ttools
  1364.         ld bc,256*workzoney+0
  1365. showtools0
  1366.         push bc
  1367.         push de
  1368.         ld de,0x1004
  1369.         call getgreycolor ;ld a,backcolor
  1370.         call shapes_prbox
  1371.         pop de
  1372.         pop bc
  1373.         push bc
  1374.         ld a,b
  1375.         add a,4
  1376.         ld b,a
  1377.         call calcscr_from_xchr_y
  1378.         set 5,h ;на 4 пикселя правее
  1379.         call shapes_prtext48ega;_black
  1380.         pop bc
  1381.         ld a,b
  1382.         add a,0x10
  1383.         ld b,a
  1384.         inc de
  1385.         ld a,(de)
  1386.         inc a
  1387.         jr nz,showtools0
  1388.         ret
  1389.  
  1390. showpalette
  1391.         call setpgshapes
  1392.  
  1393.         xor a
  1394.         ld b,workzoney ;b
  1395.         ld e,4
  1396. prpal0
  1397.         ld c,palettex8
  1398.         ld d,4
  1399. prpal1
  1400.         push af
  1401.         push de
  1402.         ld de,0x0801 ;hgt, wid(chr)
  1403.         push bc
  1404.         call shapes_colortocolormask
  1405.         call shapes_prbox
  1406.         pop bc
  1407.         pop de
  1408.         pop af
  1409.         inc c
  1410.         inc a
  1411.         dec d
  1412.         jr nz,prpal1
  1413.         push af
  1414.         ld a,b
  1415.         add a,8
  1416.         ld b,a ;y
  1417.         pop af
  1418.         dec e
  1419.         jr nz,prpal0
  1420.         ret
  1421.  
  1422. showtitle
  1423.         call setpgshapes
  1424.  
  1425.         ld bc,0 ;b=y ;c=x/8
  1426.         ld de,titlehgt*256 + scrwid8 ;d=hgt ;e=wid8
  1427.         ;xor a ;a=%33210210
  1428.         call getcontrastcolors
  1429.          ld a,hx
  1430.         call shapes_fillbox
  1431.         ;ld hl,prchar48ega_whiteoncolor
  1432.         ;ld (prchar48ega_colorproc),hl
  1433.         ;call getcontrastcolors ;ld ix,0xff00 ;lx=фоновый цвет
  1434.          ld a,lx
  1435.          ld lx,hx
  1436.          ld hx,a
  1437.         ld hl,scrbase ;scr
  1438.         ld a,(curbmp)
  1439.         add a,'1'
  1440.         call shapes_prchar48ega;_oncolor
  1441.         ld a,':'
  1442.         call shapes_prchar48ega;_oncolor
  1443.         ld de,curpicname
  1444.         call shapes_prtext48ega;_oncolor
  1445.         ld a,' '
  1446.         call shapes_prchar48ega;_oncolor
  1447.         ex de,hl
  1448.         ld hl,(curbitmapwid_edit)
  1449.         call shapes_prnum;_oncolor
  1450.         ex de,hl
  1451.         ld a,'x'
  1452.         call shapes_prchar48ega;_oncolor
  1453.         ex de,hl
  1454.         ld hl,(curbitmaphgt)
  1455.         call shapes_prnum;_oncolor
  1456.         ex de,hl
  1457.         ld a,' '
  1458.         call shapes_prchar48ega;_oncolor
  1459.         ex de,hl
  1460.         ld a,(curbitmapscale)
  1461.         ld l,a
  1462.         ld h,0
  1463.         add hl,hl
  1464.         add hl,hl
  1465.         ld bc,tscalesnames-4
  1466.         add hl,bc
  1467.         ex de,hl
  1468.         call shapes_prtext48ega;_oncolor
  1469.        
  1470.         ld a,'%'
  1471.         jp shapes_prchar48ega;_oncolor
  1472.        
  1473.        
  1474. tscalesnames
  1475.         db " 25",0
  1476.         db " 50",0
  1477.         db "100",0
  1478.         db "200",0
  1479.         db "400",0
  1480.        
  1481. showbitmap
  1482.         ld hl,workpal
  1483.         call copytemp_setpal
  1484.         call setpgs_scr
  1485.         ld hl,(curbitmapwid_edit)
  1486.         ld de,(curbitmaphgt)
  1487.         ld a,d
  1488.         or e
  1489.         ret z ;пустой битмэп
  1490.         call scalebitmapcoords ;hl=wid, de=hgt
  1491.         inc hl
  1492.         srl h
  1493.         rr l
  1494.         inc hl
  1495.         srl h
  1496.         rr l
  1497.         inc hl
  1498.         srl h
  1499.         rr l ;wid(chr)
  1500.         ld bc,workzonewid8
  1501.         or a
  1502.         sbc hl,bc
  1503.         add hl,bc
  1504.         jr nc,$+3 ;wid>=workzonewid => берём ширину рабочей зоны
  1505.         ld c,l ;wid<workzonewid => берём wid битмэпа
  1506.         ld lx,c;workzonewid8 ;lx=wid(chr)
  1507.         ex de,hl
  1508.         ld bc,workzonehgt
  1509.         or a
  1510.         sbc hl,bc
  1511.         add hl,bc
  1512.         jr nc,$+3 ;hgt>=workzonehgt => берём ширину рабочей зоны
  1513.         ld c,l ;hgt<workzonehgt => берём hgt битмэпа
  1514.         ld hy,c;workzonehgt ;hy=hgt
  1515.        
  1516.         ld hl,(curbitmapxscroll) ;hl=x в bitmap
  1517.         ld de,(curbitmapyscroll) ;de=y в bitmap
  1518.         ld bc,workzoney*256+workzonex8 ;c=x/8 на экране, b=y на экране
  1519.         jp prbitmapbox
  1520.  
  1521. calcscr_from_xchr_y
  1522. ;b=y
  1523. ;c=x/8
  1524. ;out: hl=scraddr
  1525. ;не портит de
  1526.          ld a,c
  1527. calcscr_from_xchr_ya
  1528.         ld l,b
  1529.         ld h,0
  1530.          ld b,scrbase/256/8
  1531.          ld c,l
  1532.         add hl,hl
  1533.         add hl,hl
  1534.         add hl,bc;de ;y*5
  1535.         add hl,hl
  1536.         add hl,hl
  1537.         add hl,hl ;y*40 + scrbase
  1538.          add a,l
  1539.          ld l,a
  1540.          ret nc
  1541.          inc h
  1542.         ret
  1543.  
  1544. cls
  1545.         call setpgs_scr
  1546.         call setpgshapes
  1547.         xor a
  1548.         jp shapes_cls
  1549.  
  1550.         align 256
  1551. tmirror
  1552. _=0
  1553.         dup 256
  1554. _0=_&1
  1555. _1=_>>1&1
  1556. _2=_>>2&1
  1557. _3=_>>3&1
  1558. _4=_>>4&1
  1559. _5=_>>5&1
  1560. _6=_>>6&1
  1561. _7=_>>7&1
  1562.         db (_0<<7)+(_1<<6)+(_2<<5)+(_3<<4)+(_4<<3)+(_5<<2)+(_6<<1)+(_7)
  1563. _=_+1
  1564.         edup
  1565.  
  1566. ttools
  1567.         db "Window",0
  1568.         db "Pencil",0
  1569.         db "Brush",0
  1570.         db "Line",0
  1571.         db "Fill",0
  1572.         db "Text",0
  1573.         db -1
  1574.        
  1575. curtool
  1576.         db 0
  1577. curtool1
  1578.         db 1
  1579. curtool2
  1580.         db 0
  1581. curcolorA
  1582.         db 0
  1583. curcolorB
  1584.         db 0
  1585. curcolor1
  1586.         db 15
  1587. curcolor2
  1588.         db 0
  1589.    
  1590. prarr_zone
  1591.         db 0
  1592.  
  1593. setpgs_scr
  1594. ;setpgs_scr_low=$+1
  1595. ;        ld a,0;pgscr0_0 ;scr0_0
  1596.         ld a,(user_scr0_low)
  1597.         SETPG32KLOW
  1598. ;setpgs_scr_high=$+1
  1599. ;        ld a,0;pgscr0_1 ;scr0_1
  1600.         ld a,(user_scr0_high)
  1601.         SETPG32KHIGH
  1602.         ret
  1603.  
  1604. setpgshapes
  1605.         push bc
  1606. curpgshapes=$+1
  1607.         ld a,0;pgshapes
  1608.         SETPG16K
  1609.         pop bc
  1610.         ret
  1611.  
  1612. setpgpal
  1613.         push bc
  1614. curpgpal=$+1
  1615.         ld a,0;pgshapes
  1616.         SETPG32KLOW
  1617.         pop bc
  1618.         ret
  1619.  
  1620. setpgtemp
  1621.         push bc
  1622. curpgtemp=$+1
  1623.         ld a,0;pgshapes
  1624.         SETPG32KHIGH
  1625.         pop bc
  1626.         ret
  1627.  
  1628.         include "window.asm"
  1629.         include "navigator.asm"
  1630.        
  1631.         include "pal.asm"
  1632.        
  1633.         include "bitmap.asm"
  1634.  
  1635.         include "prbitmap.asm"
  1636.        
  1637.         include "control.asm"
  1638.         include "math.asm"
  1639.        
  1640.         include "files.asm"
  1641.  
  1642.         include "windows.asm"
  1643.  
  1644. skipword
  1645. ;hl=string
  1646. ;out: hl=terminator/space addr
  1647. getword0
  1648.         ld a,(hl)
  1649.         or a
  1650.         ret z
  1651.         cp ' '
  1652.         ret z
  1653.         inc hl
  1654.         jr getword0
  1655.  
  1656. skipspaces
  1657. ;hl=string
  1658. ;out: hl=after last space
  1659.         ld a,(hl)
  1660.         cp ' '
  1661.         ret nz
  1662.         inc hl
  1663.         jr skipspaces
  1664.  
  1665. ;hl = poi to filename in string
  1666. findlastslash.
  1667. nfopenfnslash.
  1668.         ld d,h
  1669.         ld e,l ;de = after last slash
  1670. ;find last slash
  1671. nfopenfnslash0.
  1672.         ld a,[hl]
  1673.         inc hl
  1674.         or a
  1675.         jr z,nfopenfnslashq.
  1676.         cp '/'
  1677.         jr nz,nfopenfnslash0.
  1678.         jr nfopenfnslash.
  1679. nfopenfnslashq.
  1680. ;de = after last slash or beginning of path
  1681.         ret
  1682.  
  1683. wordbuf
  1684.         ds MAXCMDSZ+1
  1685.        
  1686. pathbuf_forBDOS
  1687.         ds MAXPATH_sz ;сейчас используется только при инициализации (прочитать текущий драйв)
  1688.  
  1689.         ;display "$ before align=",/h,$
  1690.        
  1691.         .align 256
  1692. ;;;;;;;;;;;;;;;;;;; таблицы для prbitmap
  1693. tpixelrecode
  1694. ;%00003210 => %33210210
  1695.         dup 256
  1696. _3=$&8
  1697. _210=$&7
  1698.         db (_3*0x18) + (_210*0x09)
  1699.         edup
  1700.        
  1701. tpixelrecodeLEFT
  1702. ;%00003210 => %.3...210
  1703.         dup 256
  1704. _3=$&8
  1705. _210=$&7
  1706.         db (_3*0x08) + (_210*0x01)
  1707.         edup
  1708.        
  1709. tpixelrecodeRIGHT
  1710. ;%00003210 => %3.210...
  1711.         dup 256
  1712. _3=$&8
  1713. _210=$&7
  1714.         db (_3*0x10) + (_210*0x08)
  1715.         edup
  1716.        
  1717. ;;;;;;;;;;;;;;;;;;; таблицы для палитры
  1718. tsin
  1719.         incbin "tsin200"
  1720. tarcsin
  1721.         incbin "tarcsin"
  1722. tsqr
  1723. ;аргумент +-0..127 (соответствует -1..+1)
  1724. ;результат 0..127 (соответствует -1..+1)
  1725. _=0
  1726.         dup 128
  1727.         db (_*_)/128
  1728. _=_+1
  1729.         edup
  1730. _=128
  1731.         dup 128
  1732.         db (_*_)/128
  1733. _=_-1
  1734.         edup
  1735. tsqrt
  1736. ;аргумент 0..255 (соответствует 0..2)
  1737. ;результат 0..127 (соответствует 0..1) и выше
  1738.         incbin "sqrtmax2"
  1739. tbitmappages
  1740.         ;display "tbitmappages=",tbitmappages
  1741.         ds bmpmaxpages,0x7f
  1742.        
  1743. activeend
  1744.         display "activeend=",activeend
  1745.         ds 0x4000-$
  1746. SHAPES_begin
  1747.         include "prshapes.asm"
  1748.         include "prarrow.asm"
  1749.         include "prtext.asm"
  1750.         .align 256
  1751. font48
  1752.         incbin "64qua.fnt"
  1753. SHAPES_sz=$-SHAPES_begin
  1754.         display "Shapes size ",/d,SHAPES_sz," bytes"
  1755.        
  1756. gfxeditor_end
  1757.  
  1758.         display "Size ",/d,gfxeditor_end-gfxeditor_begin," bytes"
  1759.         ;display "Free (incl. stack) ",/d,0x4000-activeend," bytes"
  1760.  
  1761.         savebin "scratch.com",gfxeditor_begin,gfxeditor_end-gfxeditor_begin
  1762.        
  1763.         LABELSLIST "../../us/user.l"
  1764.