?login_element?

Subversion Repositories NedoOS

Rev

Rev 657 | 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*5)
  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.       cp 0x10
  691.       jr c,$+4
  692.       ld a,0x10 ;transparent color 16
  693.        and 0x1c;0x0c
  694.        ld bc,-palettex8*8
  695.        add hl,bc
  696.        srl l
  697.        srl l
  698.        srl l
  699.        add a,l
  700.        ld (de),a
  701.        jp showcurcolor
  702.        
  703. checkfirecoords
  704. ;hl=x на экране, a=y на экране
  705. ;out: CY=вне битмэпа
  706. ;bc=x в bitmap, de=y в bitmap
  707.        call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  708.        ld hl,(curbitmapwid_edit)
  709.        scf
  710.        sbc hl,bc
  711.        ret c ;x>(bitmapwid-1) => x>=bitmapwid
  712.        ld hl,(curbitmaphgt)
  713.        scf
  714.        sbc hl,de
  715.        ret ;CY: y>(bitmaphgt-1) => y>=bitmaphgt
  716.  
  717. checkminmaxxy
  718. ;bc=x, de=y (могут быть отрицательные) (не портятся)
  719.        bit 7,b
  720.        jr nz,checkminmaxxy_nox
  721.        ld hl,(maxx)
  722.        or a
  723.        sbc hl,bc
  724.        jr nc,$+6
  725.        ld (maxx),bc
  726.        ld hl,(minx)
  727.        or a
  728.        sbc hl,bc
  729.        jr c,$+6
  730.        ld (minx),bc
  731.        jr checkminmaxxy_xq
  732. checkminmaxxy_nox
  733.        ld hl,0
  734.        ld (minx),hl
  735. checkminmaxxy_xq
  736.        bit 7,d
  737.        jr nz,checkminmaxxy_noy
  738.        ld hl,(maxy)
  739.        or a
  740.        sbc hl,de
  741.        jr nc,$+6
  742.        ld (maxy),de
  743.        ld hl,(miny)
  744.        or a
  745.        sbc hl,de
  746.        ret c
  747.        ld (miny),de
  748.        ret
  749. checkminmaxxy_noy
  750.        ld hl,0
  751.        ld (miny),hl
  752.        ret
  753.        
  754. control_keys
  755. key=$+1
  756.        ld a,0
  757.        cp key_left
  758.        jp z,control_keys_left
  759.        cp key_down
  760.        jp z,control_keys_down
  761.        cp key_up
  762.        jp z,control_keys_up
  763.        cp key_right
  764.        jp z,control_keys_right
  765.        cp '+'
  766.        jp z,control_keys_plus
  767.        cp '-'
  768.        jp z,control_keys_minus
  769.        cp 'n'
  770.        jp z,control_keys_new
  771.        cp 'c'
  772.        jp z,control_keys_clear
  773.        cp 'w'
  774.        jp z,window_allpicture
  775.        cp 'v'
  776.        jp z,window_copy
  777.        cp 'V'
  778.        jp z,window_copy
  779.        cp 'z'
  780.        jp z,control_keys_swapcolors
  781.        cp 'x'
  782.        jp z,window_mirrhor
  783.        cp 'y'
  784.        jp z,window_mirrver
  785.        cp key_redraw
  786.        jp z,showworkscreen
  787.        sub '1'
  788.        cp 4
  789.        jp c,control_keys_selectbmp
  790.        
  791.        ret
  792.        
  793. control_keys_new
  794.        ;ld lx,0b00111111 ;background fill color byte 0bRLrrrlll
  795.        ;ld hx,0b00000000 ;11111111 ;brush color byte 0bRLrrrlll
  796.        call getcontrastcolors
  797.        ld iy,win_new
  798.        call window_start
  799.        call window_mainloop
  800. ;restore screen:
  801.        call showworkscreen
  802.        ret
  803.        
  804. getcontrastcolors ;out: lx=background fill color byte 0bRLrrrlll, hx=brush color byte 0bRLrrrlll
  805.        push bc
  806.        push de
  807.        push hl
  808.        ld hl,workpal
  809. ;DDp palette: %grbG11RB(low),%grbG11RB(high), инверсные
  810. ;high B, high b, low B, low b
  811.        ld ix,0x00ff ;hx=current max, lx=current min
  812.        ;ld iy,0x0000 ;hy=current max index, ly=current min index
  813.        ld c,16
  814. getcontrastcolors0
  815.        ld e,(hl)
  816.        inc hl
  817.        ld d,(hl)
  818.        inc hl
  819.        push hl
  820.        ex de,hl
  821.        call calchexcolor
  822. ;b=0xBB
  823. ;d=0xRR
  824. ;e=0xGG
  825.        ld a,b
  826.        and 0x0f
  827.        ld b,a
  828.        ld a,d
  829.        and 0x0f
  830.        ld d,a
  831.        ld a,e
  832.        and 0x0f
  833.        ld e,a
  834.        add a,b
  835.        add a,d
  836.        cp hx ;current max
  837.        jr c,getcontrastcolors_nmax
  838.        ld hx,a
  839.        ld hy,c
  840. getcontrastcolors_nmax
  841.        cp lx ;current min
  842.        jr nc,getcontrastcolors_nmin
  843.        ld lx,a
  844.        ld ly,c
  845. getcontrastcolors_nmin
  846.        pop hl
  847.        dec c
  848.        jr nz,getcontrastcolors0
  849. ;hy=current max index (for background), ly=current min index (for brush)
  850.        ld h,tpixelrecode/256
  851.        ld a,16
  852.        sub hy
  853.        ld l,a
  854.        ld a,(hl)
  855.        ld lx,a
  856.        ld a,16
  857.        sub ly
  858.        ld l,a
  859.        ld a,(hl)
  860.        ld hx,a
  861.        ;ld lx,0b00111111 ;background fill color byte 0bRLrrrlll
  862.        ;ld hx,0b00000000 ;11111111 ;brush color byte 0bRLrrrlll
  863.        pop hl
  864.        pop de
  865.        pop bc
  866.        ret
  867.  
  868. getgreycolor ;TODO не самый яркий и не самый тёмный, если возможно
  869.        ld a,0b00111111
  870.        ret
  871.  
  872. getblackongrey
  873.        call getcontrastcolors
  874.        call getgreycolor
  875.        ld lx,a
  876.        ret
  877.  
  878. buttoncancel_unclick
  879.        jp window_close
  880. buttonok_unclick
  881. ;TODO check sizes
  882.        ld hl,win_new_twid
  883.        call strtoint
  884.        dec hl
  885.        ld bc,2048
  886.        or a
  887.        sbc hl,bc
  888.        add hl,bc
  889.        inc hl
  890.        ret nc ;wrong number
  891.         ld (buttonok_wid),hl
  892.        ld hl,win_new_thgt
  893.        call strtoint
  894.        dec hl
  895.        ld bc,2048
  896.        or a
  897.        sbc hl,bc
  898.        add hl,bc
  899.        inc hl
  900.        ret nc ;wrong number
  901. ;new image:
  902.        push hl
  903.        call delbitmap ;удалить текущую картинку и освободить странички
  904. buttonok_wid=$+1
  905.        ld hl,0
  906.        ld (curbitmapwid_edit),hl
  907.        pop hl
  908.        ld (curbitmaphgt),hl
  909.        call reserve_bmp_pages ;там genmuldewid_ahl
  910.        
  911.        ld bc,0 ;bc=x in bitmap
  912.        ld de,0 ;de=y in bitmap
  913.        ld hl,(curbitmapwid_edit) ;hl=wid
  914.        ld ix,(curbitmaphgt) ;ix=hgt
  915.        
  916.        ld a,(win_new_flag0color_flags)
  917.        bit WINELEMENT_FLAG_CHECKED,a
  918.        ld a,0
  919.        jr nz,newimage_q
  920.        ld a,(win_new_flagbrushcolor_flags)
  921.        bit WINELEMENT_FLAG_CHECKED,a
  922.        ld a,(curcolor1) ;a=color1
  923.        jr nz,$+5
  924.        ld a,(curcolor2) ;a=color1
  925. newimage_q
  926.        call bitmap_fillbox
  927.  
  928.        jp window_close
  929. reter
  930.        ret
  931.      
  932. win_new
  933. ;x/2,y,wid/2,hgt
  934.        db 52,10,64,64
  935.        db 0b1000 ;flags
  936. ; Bit 0 - рамка не рисуется (don't draw frame)
  937. ; Bit 1 - reserved
  938. ; Bit 2 - таскать окно по экрану (movable window)
  939. ; Bit 3 - выход из окна-ткнуть только лишь за пределами (CANCEL by clicking outside the window)
  940.  
  941. ;;window elements (linked list)
  942. ;link16 ;0=end of list
  943. ;x/2,y,wid/2,hgt
  944. ;type
  945. ;checked
  946. ;hidden
  947. ;disabled
  948. ;onclick16
  949. ;onunclick16
  950. ;onmove16
  951. win_new_title
  952.         STARTWINELEMENT
  953.         dw win_new_flagbgcolor ;0=end of list
  954.         db 24,3,9*2,8
  955.         db T_LABEL
  956.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  957.         db 0 ;hotkey
  958.         dw reter ;onclick16
  959.         dw reter ;onunclick16
  960.         dw reter ;onmove16
  961.         PADWINELEMENT
  962.         db "New image",0
  963.        
  964. win_new_flagbgcolor
  965.         STARTWINELEMENT
  966.         dw win_new_flagbrushcolor ;0=end of list
  967.         db 24,14,4,8
  968.         db T_RADIO
  969. win_new_flagbgcolor_flags
  970.         db 0b1001 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  971.         db 0 ;hotkey
  972.         dw reter ;onclick16
  973.         dw reter ;onunclick16
  974.         dw reter ;onmove16
  975.         PADWINELEMENT
  976.         db "Background color",0
  977.        
  978. win_new_flagbrushcolor
  979.         STARTWINELEMENT
  980.         dw win_new_flag0color ;0=end of list
  981.         db 24,22,4,8
  982.         db T_RADIO
  983. win_new_flagbrushcolor_flags
  984.         db 0b1000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  985.         db 0 ;hotkey
  986.         dw reter ;onclick16
  987.         dw reter ;onunclick16
  988.         dw reter ;onmove16
  989.         PADWINELEMENT
  990.         db "Brush color",0
  991.        
  992. win_new_flag0color
  993.         STARTWINELEMENT
  994.         dw win_new_labelhgt ;0=end of list
  995.         db 24,30,4,8
  996.         db T_RADIO
  997. win_new_flag0color_flags
  998.         db 0b1000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  999.         db 0 ;hotkey
  1000.         dw reter ;onclick16
  1001.         dw reter ;onunclick16
  1002.         dw reter ;onmove16
  1003.         PADWINELEMENT
  1004.         db "Color 0",0
  1005.        
  1006. win_new_labelhgt
  1007.         STARTWINELEMENT
  1008.         dw win_new_edithgt ;0=end of list
  1009.         db 8,14,8,8
  1010.         db T_LABEL
  1011.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1012.         db 0 ;hotkey
  1013.         dw reter ;onclick16
  1014.         dw reter ;onunclick16
  1015.         dw reter ;onmove16
  1016.         PADWINELEMENT
  1017.         db "Hgt=",0
  1018.        
  1019. win_new_edithgt
  1020.         STARTWINELEMENT
  1021.         dw win_new_labelwid ;0=end of list
  1022.         db 16,14,8,8
  1023.         db T_EDIT
  1024.         db 0b1000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1025.         db 0 ;hotkey
  1026.         dw reter ;onclick16
  1027.         dw reter ;onunclick16
  1028.         dw reter ;onmove16
  1029.         PADWINELEMENT
  1030. win_new_thgt
  1031.         db "192 ",0
  1032.        
  1033. win_new_labelwid
  1034.         STARTWINELEMENT
  1035.         dw win_new_editwid ;0=end of list
  1036.         db 8,24,8,8
  1037.         db T_LABEL
  1038.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1039.         db 0 ;hotkey
  1040.         dw reter ;onclick16
  1041.         dw reter ;onunclick16
  1042.         dw reter ;onmove16
  1043.         PADWINELEMENT
  1044.         db "Wid=",0
  1045.        
  1046. win_new_editwid
  1047.         STARTWINELEMENT
  1048.         dw win_new_buttonok ;0=end of list
  1049.         db 16,24,8,8
  1050.         db T_EDIT
  1051.         db 0b1000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1052.         db 0 ;hotkey
  1053.         dw reter ;onclick16
  1054.         dw reter ;onunclick16
  1055.         dw reter ;onmove16
  1056.         PADWINELEMENT
  1057. win_new_twid
  1058.         db "256 ",0
  1059.        
  1060. win_new_buttonok
  1061.         STARTWINELEMENT
  1062.         dw win_new_buttoncancel ;0=end of list
  1063.         db 8,40,20,16
  1064.         db T_BUTTON
  1065.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1066.         db 0 ;hotkey
  1067.         dw reter ;onclick16
  1068.         dw buttonok_unclick ;onunclick16
  1069.         dw reter ;onmove16
  1070.         PADWINELEMENT
  1071.         db "OK",0
  1072.        
  1073. win_new_buttoncancel
  1074.         STARTWINELEMENT
  1075.         dw 0 ;0=end of list
  1076.         db 36,40,20,16
  1077.         db T_BUTTON
  1078.         db 0b0000 ;b0:checked, b1:hidden, b2:disabled, b3:invertible
  1079.         db 0 ;hotkey
  1080.         dw reter ;onclick16
  1081.         dw buttoncancel_unclick ;onunclick16
  1082.         dw reter ;onmove16
  1083.         PADWINELEMENT
  1084.         db "Cancel",0
  1085.        
  1086.  
  1087.        
  1088. control_keys_swapcolors
  1089.         ld hl,(curcolor1) ;1, 2
  1090.         ld a,l
  1091.         ld l,h
  1092.         ld h,a
  1093.         ld (curcolor1),hl
  1094.         jp showworkscreen
  1095.        
  1096. control_keys_selectbmp
  1097.         call selectbmp
  1098.         call kill_unfinished_shapes
  1099.         jp showworkscreen ;control_scale_checksize
  1100.  
  1101. kill_unfinished_shapes
  1102.         xor a
  1103.         ld (curlinestate),a ;убиваем недоопределённую линию
  1104.         dec a
  1105.         ld (curlinex+1),a ;отменяем начальную точку линии через shift
  1106.          ld a,(curwindowstate)
  1107.          dec a
  1108.          call z,clearwindowstate ;убиваем недоопределённое окно
  1109.         ret
  1110.  
  1111. findcurbitmap
  1112. ;a=номер
  1113.         ld c,a
  1114.         ld b,0
  1115.         ld de,bitmapstruct_sz
  1116.         call mulbcde_ahl
  1117.         ld bc,bitmaps
  1118.         add hl,bc
  1119.         ret
  1120.        
  1121. control_keys_right
  1122.         call control_getscrollvalue ;de=scrollvalue
  1123.         ld hl,(curbitmapxscroll)
  1124.         add hl,de
  1125. control_keys_setxscroll
  1126.         ld (curbitmapxscroll),hl
  1127. control_scroll_emptyqueue_checksize
  1128.          ;call emptykeyqueue
  1129. emptykeyqueue0
  1130.         GET_KEY
  1131.         or a
  1132.         jr nz,emptykeyqueue0
  1133. control_scroll_checksize
  1134.         call control_scroll_checksizepp
  1135.         call shownavigator
  1136.         call showtitle
  1137.         jp showbitmap
  1138. control_scroll_checksizepp
  1139.         ld hl,+(workzonex8+workzonewid8)*8 ;hl=x
  1140.         ld a,workzoney+workzonehgt ;a=y        
  1141.         call calcbitmapcoords ;out: bc=x в bitmap, de=y в bitmap
  1142.  
  1143.         ld hl,(curbitmaphgt)
  1144.         or a
  1145.         sbc hl,de
  1146.         jr nc,control_scroll_nocorrecty ;hgt>=y
  1147. ;hl<0 (сколько лишних пикселей bitmap по y)
  1148. ;посчитать bitmaphgt-(workzonehgt/scale) = bitmaphgt+hl
  1149.         ld de,workzonehgt
  1150.         call scalescrcoords
  1151.         ld hl,(curbitmaphgt)
  1152.         call subhldecheck0
  1153.         ld (curbitmapyscroll),hl
  1154. control_scroll_nocorrecty
  1155.         ld hl,(curbitmapwid_edit)
  1156.         or a
  1157.         sbc hl,bc
  1158.         ret nc ;wid>=x
  1159. ;hl<0 (сколько лишних пикселей bitmap по x)
  1160. ;посчитать bitmapwid-(workzonewid/scale) = bitmapwid+hl
  1161.         ld de,workzonewid8*8
  1162.         call scalescrcoords
  1163.         ld hl,(curbitmapwid_edit)
  1164.         call subhldecheck0
  1165.         ld (curbitmapxscroll),hl
  1166.         ret
  1167.        
  1168. control_keys_left
  1169.         call control_getscrollvalue ;de=scrollvalue
  1170.         ld hl,(curbitmapxscroll)
  1171.         ;or a
  1172.         ;sbc hl,de
  1173.         ;jr nc,$+5
  1174.         ;ld hl,0
  1175.         call subhldecheck0
  1176.         jr control_keys_setxscroll
  1177.        
  1178. control_keys_down
  1179.         call control_getscrollvalue ;de=scrollvalue
  1180.         ld hl,(curbitmapyscroll)
  1181.         add hl,de
  1182. control_keys_setyscroll
  1183.         ld (curbitmapyscroll),hl
  1184.         jr control_scroll_emptyqueue_checksize
  1185.  
  1186. control_keys_up
  1187.         call control_getscrollvalue ;de=scrollvalue
  1188.         ld hl,(curbitmapyscroll)
  1189.         ;or a
  1190.         ;sbc hl,de
  1191.         ;jr nc,$+5
  1192.         ;ld hl,0
  1193.         call subhldecheck0
  1194.         jr control_keys_setyscroll
  1195.  
  1196. control_getscrollvalue
  1197.         ld de,64
  1198.         jp scalescrcoords
  1199.        
  1200. control_scale_checksize
  1201.         call control_scroll_checksizepp
  1202.  
  1203.         call setpgshapes
  1204.  
  1205.         ld bc,workzoney*256 + workzonex8 ;b=y ;c=x/8
  1206.         ld de,workzonehgt*256 + workzonewid8 ;d=hgt ;e=wid8
  1207.         ld a,0x3f;%00111111 ;a=%33210210
  1208.         call shapes_fillbox
  1209.         jp control_scroll_checksize;showworkscreen
  1210. control_keys_plus
  1211.         ld a,(curbitmapscale)
  1212.         inc a
  1213.         cp 5+1
  1214.         jr c,$+3
  1215.         dec a
  1216.         ld (curbitmapscale),a
  1217.         jp control_scroll_checksize ;не нужно перепечатывать пустое место
  1218. control_keys_minus
  1219.         ld a,(curbitmapscale)
  1220.         dec a
  1221.         jr nz,$+3
  1222.         inc a
  1223.         ld (curbitmapscale),a
  1224.         jp control_scale_checksize
  1225.  
  1226. control_keys_clear
  1227.         ld a,(curwindowstate)
  1228.         cp 2
  1229.         ret nz
  1230.         ld bc,(curwindowx) ;bc=x в bitmap
  1231.         ld de,(curwindowy) ;de=y в bitmap
  1232.         ld hl,(curwindowwid) ;hl=wid
  1233.         ld ix,(curwindowhgt) ;ix=hgt
  1234.         ld a,(curcolor2)
  1235.         ex af,af'
  1236.        ld a,(curcolor2)
  1237. ;a=color1
  1238. ;a'=color2
  1239.         call bitmap_fillbox
  1240.         jp showbitmap
  1241.  
  1242. checkfirezone
  1243. ;hl=x
  1244. ;a=y
  1245. ;out: a=код зоны и для ZONE_WORK: bc=x в bitmap, de=y в bitmap
  1246.         ld c,a
  1247.         cp workzoney
  1248.         ld a,ZONE_TOP
  1249.         ret c ;top
  1250.         ld a,ZONE_LEFT
  1251.         ld de,workzonex8*8
  1252.         ;or a
  1253.         sbc hl,de
  1254.         add hl,de
  1255.         ret c ;left
  1256.         ld de,+(workzonex8+workzonewid8)*8
  1257.         ;or a
  1258.         sbc hl,de
  1259.         add hl,de
  1260.         ld a,c
  1261.         jr nc,checkfirezone_right ;right
  1262.         call checkfirecoords ;CY=вне битмэпа
  1263.         ld a,ZONE_NO
  1264.         ret c ;bc=x в bitmap, de=y в bitmap
  1265.         ld a,ZONE_WORK
  1266.         ret
  1267. checkfirezone_right
  1268.         cp navigatory
  1269.         ld a,ZONE_PAL
  1270.         ret c ;pal
  1271.         cp navigatory+navigatorhgt
  1272.         ld a,ZONE_NAVIGATOR
  1273.         ret c ;navigator
  1274.         ld a,ZONE_RIGHT
  1275.         ret ;right
  1276.  
  1277. showworkscreen
  1278.         call setpgs_scr
  1279.         call setpgshapes
  1280.         call getgreycolor ;ld a,backcolor
  1281.         call shapes_cls
  1282.  
  1283.         call showtitle
  1284.         call showbitmap
  1285.         call showtools
  1286.         call showcurcolor
  1287.         call showpalette
  1288.  
  1289.         jp shownavigator
  1290.        
  1291. showcurcolor
  1292.         call setpgshapes
  1293.  
  1294.         ld de,256*colorhgt+2
  1295.         push de ;y
  1296.         ld bc,256*colory+colorx8
  1297.         ld hl,(curcolor1)
  1298.         ld h,tpixelrecode/256
  1299.         ld a,(hl)
  1300.         ;call shapes_colortocolormask
  1301.         call shapes_prbox
  1302.         ;ld de,256*colorhgt+2
  1303.         pop de ;y
  1304.         ld bc,256*colory+colorx8+2
  1305.         ld hl,(curcolor2)
  1306.         ld h,tpixelrecode/256
  1307.         ld a,(hl)
  1308.         ;call shapes_colortocolormask
  1309.         jp shapes_prbox
  1310.  
  1311. calccurtool
  1312. ;a=y
  1313. ;определяет номер тулзы по координатам стрелки
  1314. ;out: a=tool, NC: a>=NTOOLS
  1315.         sub 8
  1316.         rra
  1317.         rra
  1318.         rra
  1319.         rra
  1320.         and 0x0f
  1321.         cp NTOOLS
  1322.         ret
  1323.  
  1324. setcurtool
  1325.         call isitclick
  1326.         ret nz ;кнопку уже держали
  1327.         xor a
  1328.         ld (curlinestate),a ;отменить недоопределённую линию
  1329. curmousebutton=$+1 ;0=LMB
  1330.         or 0
  1331.         ld hl,curtool1
  1332.         jr z,$+5
  1333.         ld hl,curtool2
  1334.         ld a,(arry)
  1335.         call calccurtool
  1336.         ret nc ;>=NTOOLS
  1337.         ld (hl),a
  1338.         cp TOOL_WINDOW
  1339.         jr nz,showcurtool
  1340.         ld a,1
  1341.         ld (windowcopymode),a
  1342.         ;jp showcurtool
  1343. showcurtool
  1344.         call setpgshapes
  1345.  
  1346.         ld bc,256*(colory-10)+colorx8+1
  1347.         call calcscr_from_xchr_y        
  1348.         ld de,text_ntool
  1349.         ld a,(curtool1)
  1350.         add a,'0'
  1351.         ld (de),a
  1352.         inc de
  1353.         inc de
  1354.         ld a,(curtool2)
  1355.         add a,'0'
  1356.         ld (de),a
  1357.         dec de
  1358.         dec de
  1359.         call getcontrastcolors ;ld ix,0xff00+backcolor
  1360.         jp shapes_prtext48ega;_oncolor
  1361.  
  1362. text_ntool
  1363.         db "0 0",0
  1364.        
  1365. showtools
  1366.         call setpgshapes
  1367.         call getcontrastcolors ;ld ix,0x0000+backcolor
  1368.         call getgreycolor ;ld a,backcolor
  1369.         ld lx,a
  1370.         ld de,ttools
  1371.         ld bc,256*workzoney+0
  1372. showtools0
  1373.         push bc
  1374.         push de
  1375.         ld de,0x1004
  1376.         call getgreycolor ;ld a,backcolor
  1377.         call shapes_prbox
  1378.         pop de
  1379.         pop bc
  1380.         push bc
  1381.         ld a,b
  1382.         add a,4
  1383.         ld b,a
  1384.         call calcscr_from_xchr_y
  1385.         set 5,h ;на 4 пикселя правее
  1386.         call shapes_prtext48ega;_black
  1387.         pop bc
  1388.         ld a,b
  1389.         add a,0x10
  1390.         ld b,a
  1391.         inc de
  1392.         ld a,(de)
  1393.         inc a
  1394.         jr nz,showtools0
  1395.         ret
  1396.  
  1397. showpalette
  1398.         call setpgshapes
  1399.  
  1400.         xor a
  1401.         ld b,workzoney ;b
  1402.         ld e,4
  1403. prpal0
  1404.         ld c,palettex8
  1405.         ld d,4
  1406. prpal1
  1407.         push af
  1408.         push de
  1409.         ld de,0x0801 ;hgt, wid(chr)
  1410.         push bc
  1411.         ld l,a
  1412.         ld h,tpixelrecode/256
  1413.         ld a,(hl)
  1414.         ;call shapes_colortocolormask
  1415.         call shapes_prbox
  1416.         pop bc
  1417.         pop de
  1418.         pop af
  1419.         inc c
  1420.         inc a
  1421.         dec d
  1422.         jr nz,prpal1
  1423.         push af
  1424.         ld a,b
  1425.         add a,8
  1426.         ld b,a ;y
  1427.         pop af
  1428.         dec e
  1429.         jr nz,prpal0
  1430.         ret
  1431.  
  1432. showtitle
  1433.         call setpgshapes
  1434.  
  1435.         ld bc,0 ;b=y ;c=x/8
  1436.         ld de,titlehgt*256 + scrwid8 ;d=hgt ;e=wid8
  1437.         ;xor a ;a=%33210210
  1438.         call getcontrastcolors
  1439.          ld a,hx
  1440.         call shapes_fillbox
  1441.         ;ld hl,prchar48ega_whiteoncolor
  1442.         ;ld (prchar48ega_colorproc),hl
  1443.         ;call getcontrastcolors ;ld ix,0xff00 ;lx=фоновый цвет
  1444.          ld a,lx
  1445.          ld lx,hx
  1446.          ld hx,a
  1447.         ld hl,scrbase ;scr
  1448.         ld a,(curbmp)
  1449.         add a,'1'
  1450.         call shapes_prchar48ega;_oncolor
  1451.         ld a,':'
  1452.         call shapes_prchar48ega;_oncolor
  1453.         ld de,curpicname
  1454.         call shapes_prtext48ega;_oncolor
  1455.         ld a,' '
  1456.         call shapes_prchar48ega;_oncolor
  1457.         ex de,hl
  1458.         ld hl,(curbitmapwid_edit)
  1459.         call shapes_prnum;_oncolor
  1460.         ex de,hl
  1461.         ld a,'x'
  1462.         call shapes_prchar48ega;_oncolor
  1463.         ex de,hl
  1464.         ld hl,(curbitmaphgt)
  1465.         call shapes_prnum;_oncolor
  1466.         ex de,hl
  1467.         ld a,' '
  1468.         call shapes_prchar48ega;_oncolor
  1469.         ex de,hl
  1470.         ld a,(curbitmapscale)
  1471.         ld l,a
  1472.         ld h,0
  1473.         add hl,hl
  1474.         add hl,hl
  1475.         ld bc,tscalesnames-4
  1476.         add hl,bc
  1477.         ex de,hl
  1478.         call shapes_prtext48ega;_oncolor
  1479.        
  1480.         ld a,'%'
  1481.         jp shapes_prchar48ega;_oncolor
  1482.        
  1483.        
  1484. tscalesnames
  1485.         db " 25",0
  1486.         db " 50",0
  1487.         db "100",0
  1488.         db "200",0
  1489.         db "400",0
  1490.        
  1491. setpal_de
  1492.         OS_SETPAL
  1493.         ret
  1494. showbitmap
  1495.         ld de,workpal
  1496.         call setpal_de
  1497.         call setpgs_scr
  1498.         ld hl,(curbitmapwid_edit)
  1499.         ld de,(curbitmaphgt)
  1500.         ld a,d
  1501.         or e
  1502.         ret z ;пустой битмэп
  1503.         call scalebitmapcoords ;hl=wid, de=hgt
  1504.         inc hl
  1505.         srl h
  1506.         rr l
  1507.         inc hl
  1508.         srl h
  1509.         rr l
  1510.         inc hl
  1511.         srl h
  1512.         rr l ;wid(chr)
  1513.         ld bc,workzonewid8
  1514.         or a
  1515.         sbc hl,bc
  1516.         add hl,bc
  1517.         jr nc,$+3 ;wid>=workzonewid => берём ширину рабочей зоны
  1518.         ld c,l ;wid<workzonewid => берём wid битмэпа
  1519.         ld lx,c;workzonewid8 ;lx=wid(chr)
  1520.         ex de,hl
  1521.         ld bc,workzonehgt
  1522.         or a
  1523.         sbc hl,bc
  1524.         add hl,bc
  1525.         jr nc,$+3 ;hgt>=workzonehgt => берём ширину рабочей зоны
  1526.         ld c,l ;hgt<workzonehgt => берём hgt битмэпа
  1527.         ld hy,c;workzonehgt ;hy=hgt
  1528.        
  1529.         ld hl,(curbitmapxscroll) ;hl=x в bitmap
  1530.         ld de,(curbitmapyscroll) ;de=y в bitmap
  1531.         ld bc,workzoney*256+workzonex8 ;c=x/8 на экране, b=y на экране
  1532.         jp prbitmapbox
  1533.  
  1534. calcscr_from_xchr_y
  1535. ;b=y
  1536. ;c=x/8
  1537. ;out: hl=scraddr
  1538. ;не портит de
  1539.          ld a,c
  1540. calcscr_from_xchr_ya
  1541.         ld l,b
  1542.         ld h,0
  1543.          ld b,scrbase/256/8
  1544.          ld c,l
  1545.         add hl,hl
  1546.         add hl,hl
  1547.         add hl,bc;de ;y*5
  1548.         add hl,hl
  1549.         add hl,hl
  1550.         add hl,hl ;y*40 + scrbase
  1551.          add a,l
  1552.          ld l,a
  1553.          ret nc
  1554.          inc h
  1555.         ret
  1556.  
  1557. cls
  1558.         call setpgs_scr
  1559.         call setpgshapes
  1560.         xor a
  1561.         jp shapes_cls
  1562.  
  1563.         align 256
  1564. tmirror
  1565. _=0
  1566.         dup 256
  1567. _0=_&1
  1568. _1=_>>1&1
  1569. _2=_>>2&1
  1570. _3=_>>3&1
  1571. _4=_>>4&1
  1572. _5=_>>5&1
  1573. _6=_>>6&1
  1574. _7=_>>7&1
  1575.         db (_0<<7)+(_1<<6)+(_2<<5)+(_3<<4)+(_4<<3)+(_5<<2)+(_6<<1)+(_7)
  1576. _=_+1
  1577.         edup
  1578.  
  1579. ttools
  1580.         db "Window",0
  1581.         db "Pencil",0
  1582.         db "Brush",0
  1583.         db "Line",0
  1584.         db "Fill",0
  1585.         db "Text",0
  1586.         db -1
  1587.        
  1588. curtool
  1589.         db 0
  1590. curtool1
  1591.         db 1
  1592. curtool2
  1593.         db 0
  1594. curcolorA
  1595.         db 0
  1596. curcolorB
  1597.         db 0
  1598. curcolor1
  1599.         db 15
  1600. curcolor2
  1601.         db 0
  1602.    
  1603. prarr_zone
  1604.         db 0
  1605.  
  1606. setpgs_scr
  1607. ;setpgs_scr_low=$+1
  1608. ;        ld a,0;pgscr0_0 ;scr0_0
  1609.         ld a,(user_scr0_low)
  1610.         SETPG32KLOW
  1611. ;setpgs_scr_high=$+1
  1612. ;        ld a,0;pgscr0_1 ;scr0_1
  1613.         ld a,(user_scr0_high)
  1614.         SETPG32KHIGH
  1615.         ret
  1616.  
  1617. setpgshapes
  1618.         push bc
  1619. curpgshapes=$+1
  1620.         ld a,0;pgshapes
  1621.         SETPG4000
  1622.         pop bc
  1623.         ret
  1624.  
  1625. setpgpal
  1626.         push bc
  1627. curpgpal=$+1
  1628.         ld a,0;pgshapes
  1629.         SETPG32KLOW
  1630.         pop bc
  1631.         ret
  1632.  
  1633. setpgtemp
  1634.         push bc
  1635. curpgtemp=$+1
  1636.         ld a,0;pgshapes
  1637.         SETPG32KHIGH
  1638.         pop bc
  1639.         ret
  1640.  
  1641.         include "window.asm"
  1642.         include "navigator.asm"
  1643.        
  1644.         ;include "pal.asm"
  1645.        
  1646.         include "bitmap.asm"
  1647.  
  1648.         include "prbitmap.asm"
  1649.        
  1650.         include "control.asm"
  1651.         include "math.asm"
  1652.        
  1653.         include "files.asm"
  1654.  
  1655.         include "windows.asm"
  1656.  
  1657. skipword
  1658. ;hl=string
  1659. ;out: hl=terminator/space addr
  1660. getword0
  1661.         ld a,(hl)
  1662.         or a
  1663.         ret z
  1664.         cp ' '
  1665.         ret z
  1666.         inc hl
  1667.         jr getword0
  1668.  
  1669. skipspaces
  1670. ;hl=string
  1671. ;out: hl=after last space
  1672.         ld a,(hl)
  1673.         cp ' '
  1674.         ret nz
  1675.         inc hl
  1676.         jr skipspaces
  1677.  
  1678. ;hl = poi to filename in string
  1679. findlastslash.
  1680. nfopenfnslash.
  1681.         ld d,h
  1682.         ld e,l ;de = after last slash
  1683. ;find last slash
  1684. nfopenfnslash0.
  1685.         ld a,[hl]
  1686.         inc hl
  1687.         or a
  1688.         jr z,nfopenfnslashq.
  1689.         cp '/'
  1690.         jr nz,nfopenfnslash0.
  1691.         jr nfopenfnslash.
  1692. nfopenfnslashq.
  1693. ;de = after last slash or beginning of path
  1694.         ret
  1695.  
  1696. wordbuf
  1697.         ds MAXCMDSZ+1
  1698.        
  1699. pathbuf_forBDOS
  1700.         ds MAXPATH_sz ;сейчас используется только при инициализации (прочитать текущий драйв)
  1701.  
  1702.         ;display "$ before align=",/h,$
  1703.        
  1704.         .align 256
  1705. ;;;;;;;;;;;;;;;;;;; таблицы для prbitmap
  1706. tpixelrecode ;для увеличенных масштабов (где оба пикселя в байте одинаковые)
  1707. ;%00003210 => %33210210
  1708.         dup 16
  1709. _3=$&8
  1710. _210=$&7
  1711.         db (_3*0x18) + (_210*0x09)
  1712.         edup
  1713.         dup 256-16
  1714.         db 0b10111000 ;TODO patched maxbrightL+minbrightR/minbrightL+maxbrightR
  1715.         edup
  1716.  
  1717. ;эти две таблицы - для 100% и уменьшенных масштабов
  1718. tpixelrecodeLEFT
  1719. ;%00003210 => %.3...210
  1720.         dup 16
  1721. _3=$&8
  1722. _210=$&7
  1723.         db (_3*0x08) + (_210*0x01)
  1724.         edup
  1725.         dup 256-16
  1726.         db 0 ;TODO patched maxbrightL/minrightL
  1727.         edup
  1728.  
  1729. tpixelrecodeRIGHT
  1730. ;%00003210 => %3.210...
  1731.         dup 16
  1732. _3=$&8
  1733. _210=$&7
  1734.         db (_3*0x10) + (_210*0x08)
  1735.         edup
  1736.         dup 256-16
  1737.         db 0b10111000 ;TODO patched minbrightR/maxbrightR
  1738.         edup
  1739.  
  1740. tbitmappages
  1741.         ;display "tbitmappages=",tbitmappages
  1742.         ds bmpmaxpages,0x7f
  1743.        
  1744. activeend
  1745.         display "activeend=",activeend
  1746.         ds 0x4000-$
  1747. SHAPES_begin
  1748.         include "prshapes.asm"
  1749.         include "prarrow.asm"
  1750.         include "prtext.asm"
  1751.         include "pal.asm"
  1752.         .align 256
  1753. ;;;;;;;;;;;;;;;;;;; таблицы для палитры
  1754. tsin
  1755.         incbin "tsin200"
  1756. tarcsin
  1757.         incbin "tarcsin"
  1758. tsqr
  1759. ;аргумент +-0..127 (соответствует -1..+1)
  1760. ;результат 0..127 (соответствует -1..+1)
  1761. _=0
  1762.         dup 128
  1763.         db (_*_)/128
  1764. _=_+1
  1765.         edup
  1766. _=128
  1767.         dup 128
  1768.         db (_*_)/128
  1769. _=_-1
  1770.         edup
  1771. tsqrt
  1772. ;аргумент 0..255 (соответствует 0..2)
  1773. ;результат 0..127 (соответствует 0..1) и выше
  1774.         incbin "sqrtmax2"
  1775.         .align 256
  1776. font48
  1777.         incbin "64qua.fnt"
  1778. SHAPES_sz=$-SHAPES_begin
  1779.         display "Shapes size ",/d,SHAPES_sz," bytes"
  1780.        
  1781. gfxeditor_end
  1782.  
  1783.         display "Size ",/d,gfxeditor_end-gfxeditor_begin," bytes"
  1784.         ;display "Free (incl. stack) ",/d,0x4000-activeend," bytes"
  1785.  
  1786.         savebin "scratch.com",gfxeditor_begin,gfxeditor_end-gfxeditor_begin
  1787.        
  1788.         LABELSLIST "../../us/user.l"
  1789.