?login_element?

Subversion Repositories NedoOS

Rev

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