?login_element?

Subversion Repositories NedoOS

Rev

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

  1. ;вывод на экран
  2.  
  3.         SHAPESPROC shapes_cls
  4.         ld e,a
  5.         OS_CLS
  6.         ret
  7.  
  8.         SHAPESPROC shapes_copybox
  9. ;hl=экранный адрес левого верхнего угла окна
  10. ;de=экранный адрес, куда копировать окно
  11. ;c=wid8
  12. ;b=hgt
  13.         or a
  14.         sbc hl,de
  15.         add hl,de
  16.         jr c,copyboxrightdown_topleft ;hl < de
  17. copyboxleftup
  18. ;hl=экранный адрес левого верхнего угла окна
  19. ;de=экранный адрес, куда копировать окно (выше или левее hl)
  20. ;c=wid8
  21. ;b=hgt
  22.         ld a,c
  23. copyboxleftup0
  24.         push bc
  25.         ld b,0
  26.         call ldir_a
  27.         set 5,h
  28.         set 5,d
  29.         call ldir_a
  30.         set 6,h
  31.         set 6,d
  32.         call ldir_a
  33.         res 5,h
  34.         res 5,d
  35.         call ldir_a
  36.         res 6,h
  37.         res 6,d
  38.         ld  c,40 ;b=0
  39.         ex de,hl
  40.         add hl,bc
  41.         ex de,hl
  42.         add hl,bc
  43.         pop bc
  44.         djnz copyboxleftup0
  45.         ret
  46. copyboxrightdown_topleft
  47. ;hl=экранный адрес левого верхнего угла окна
  48. ;de=экранный адрес, куда копировать окно (выше или левее hl)
  49. ;c=wid8
  50. ;b=hgt
  51.         push bc
  52.         push hl
  53.         ld a,c ;wid8
  54.         ld c,b ;hgt
  55.         ld b,0
  56.         ld h,b
  57.         ld l,c ;hgt
  58.         add hl,hl
  59.         add hl,hl
  60.         add hl,bc ;*5
  61.         add hl,hl
  62.         add hl,hl
  63.         add hl,hl ;*40
  64.         add a,l
  65.         ld c,a
  66.         adc a,h
  67.         sub c
  68.         ld b,a        
  69.         pop hl
  70.         dec bc
  71. ;bc=hgt*40 + wid8 - 1
  72.         ex de,hl
  73.         add hl,bc
  74.         ex de,hl
  75.         add hl,bc
  76.         pop bc
  77. ;hl=экранный адрес правого нижнего угла окна + 40
  78. ;de=экранный адрес, куда копировать окно + 40 (ниже или правее hl)
  79. ;c=wid8
  80. ;b=hgt
  81.         ld a,c
  82. copyboxrightdown0
  83.         push bc
  84.         ld bc,-40
  85.         ex de,hl
  86.         add hl,bc
  87.         ex de,hl
  88.         add hl,bc
  89.         ld b,0
  90.         call lddr_a
  91.         set 5,h
  92.         set 5,d
  93.         call lddr_a
  94.         set 6,h
  95.         set 6,d
  96.         call lddr_a
  97.         res 5,h
  98.         res 5,d
  99.         call lddr_a
  100.         res 6,h
  101.         res 6,d
  102.         pop bc
  103.         djnz copyboxrightdown0
  104.         ret
  105.        
  106. ldir_a
  107.         ld c,a
  108.         push hl
  109.         push de
  110.         ldir
  111.         pop de
  112.         pop hl  
  113.         ret
  114.        
  115. lddr_a
  116.         ld c,a
  117.         push hl
  118.         push de
  119.         lddr
  120.         pop de
  121.         pop hl  
  122.         ret
  123.        
  124. prpixel
  125. ;de=x (не портится)
  126. ;c=y (bc не портится)
  127. ;lx=color = %33210210
  128.        ld a,b
  129.         ld l,c
  130.         ld h,0
  131.         ld b,scrbase/256/8 ;h
  132.         add hl,hl
  133.         add hl,hl
  134.         add hl,bc
  135.         add hl,hl
  136.         add hl,hl
  137.         add hl,hl ;y*40 + scrbase
  138.        ld b,a
  139. prpixel_cury
  140. ;de=x (не портится)
  141. ;hl=addr(y)
  142. ;lx=color = %33210210
  143.         ld a,d
  144.         rra
  145.         ld a,e
  146.         rra
  147.         jr c,prpixel_r
  148.         rra
  149.         jr nc,$+4
  150.         set 6,h
  151.         rra
  152.         jr nc,$+4
  153.         set 5,h
  154.         and 0x3f;%00111111
  155.         add a,l
  156.         ld l,a
  157.         adc a,h
  158.         sub l
  159.         ld h,a
  160.         ld a,lx
  161.         xor (hl)
  162.         and 0x47;%01000111 ;keep left pixel
  163.         xor (hl) ;right pixel from screen
  164.         ld (hl),a
  165.         ret
  166. prpixel_r
  167.         rra
  168.         jr nc,$+4
  169.         set 6,h
  170.         rra
  171.         jr nc,$+4
  172.         set 5,h
  173.         and 0x3f;%00111111
  174.         add a,l
  175.         ld l,a
  176.         adc a,h
  177.         sub l
  178.         ld h,a
  179.         ld a,lx
  180.         xor (hl)
  181.         and 0xb8;%10111000 ;keep right pixel
  182.         xor (hl) ;left pixel from screen
  183.         ld (hl),a
  184.         ret
  185.  
  186. line_invpixel
  187. ;bc=x (в плоскости экрана относительно рабочей зоны, но может быть отрицательным)
  188. ;de=y (в плоскости экрана относительно рабочей зоны, но может быть отрицательным)
  189.         ld a,c
  190.         sub 255&(workzonewid8*8)
  191.         ld a,b
  192.         sbc a,+(workzonewid8*8)/256
  193.         ret p
  194.         xor b
  195.         ret p ;x было отрицательное
  196.         ld a,e
  197.         sub 255&workzonehgt
  198.         ld a,d
  199.         sbc a,workzonehgt/256
  200.         ret p
  201.         xor d
  202.         ret p ;y было отрицательное
  203.         push bc
  204.         push de
  205.         ld a,e ;y
  206.         ld hl,workzonex8*8
  207.         add hl,bc
  208.         ex de,hl ;de=x
  209.         add a,workzoney
  210.         ld c,a ;c=y
  211.         call invpixel
  212.         pop de
  213.         pop bc
  214.         ret
  215.        
  216. invpixel
  217. ;de=x (не портится)
  218. ;c=y (bc не портится)
  219.        ld a,b
  220.         ld l,c
  221.         ld h,0
  222.        ld b,scrbase/256/8 ;h
  223.         add hl,hl
  224.         add hl,hl
  225.         add hl,bc
  226.         add hl,hl
  227.         add hl,hl
  228.         add hl,hl ;y*40 + scrbase
  229.        ld b,a
  230. invpixel_cury
  231. ;de=x (не портится)
  232. ;hl=addr(y)
  233.         ld a,d
  234.         rra
  235.         ld a,e
  236.         rra
  237.         jr c,invpixel_r
  238.         rra
  239.         jr nc,$+4
  240.         set 6,h
  241.         rra
  242.         jr nc,$+4
  243.         set 5,h
  244.         and 0x3f;%00111111
  245.         add a,l
  246.         ld l,a
  247.         adc a,h
  248.         sub l
  249.         ld h,a
  250.         ld a,(hl)
  251.         xor 0x47;%01000111 ;left pixel from screen
  252.         ld (hl),a
  253.         ret
  254. invpixel_r
  255.         rra
  256.         jr nc,$+4
  257.         set 6,h
  258.         rra
  259.         jr nc,$+4
  260.         set 5,h
  261.         and 0x3f;%00111111
  262.         add a,l
  263.         ld l,a
  264.         adc a,h
  265.         sub l
  266.         ld h,a
  267.         ld a,(hl)
  268.         xor 0xb8;%10111000 ;right pixel from screen
  269.         ld (hl),a
  270.         ret
  271.  
  272.         SHAPESPROC shapes_prpixelbox
  273. ;c=y
  274. ;de=x
  275. ;b=hgt (последний пиксель = y+hgt-1)
  276. ;hl=wid (последний пиксель = x+wid-1)
  277. ;lx=color %rlrrrlll
  278. prpixelbox0
  279.         push bc
  280.         push de
  281.         push hl ;wid
  282.         call prpixelhorline
  283.         pop hl ;wid
  284.         pop de
  285.         pop bc
  286.         inc c
  287.         djnz prpixelbox0
  288.         ret
  289.  
  290.         SHAPESPROC shapes_invpixelframe
  291. ;bc=x
  292. ;de=y
  293. ;hl=hgt (последний пиксель = y+hgt)
  294. ;ix=wid (последний пиксель = x+wid)
  295.         push bc
  296.         push de
  297.         push hl ;wid
  298.         inc bc ;x
  299.         call invpixelhorline
  300.         pop hl ;wid
  301.         pop de
  302.         pop bc
  303.         push bc
  304.         push de
  305.         push hl ;wid
  306.         push ix
  307.         add ix,de
  308.         ld d,hx
  309.         ld e,lx ;de=y+hgt
  310.         pop ix
  311.         call invpixelhorline
  312.         pop hl ;wid
  313.         pop de
  314.         pop bc
  315.         push bc
  316.         push de
  317.         add hl,bc ;x
  318.         ld b,h
  319.         ld c,l ;bc=x+wid
  320.         push ix
  321.         pop hl ;hgt
  322.         inc de ;y
  323.         push hl
  324.         call invpixelverline
  325.         pop hl ;hgt
  326.         pop de
  327.         pop bc
  328. invpixelverline
  329. ;bc=x
  330. ;de=y
  331. ;hl=hgt
  332.         ld a,h
  333.         or l
  334.         ret z
  335. invpixelverline0
  336.         push hl
  337.         bit 0,l
  338.         call nz,line_invpixel
  339.         pop hl
  340.         inc de ;y
  341.         dec hl
  342.         ld a,h
  343.         or l
  344.         jr nz,invpixelverline0
  345.         ret
  346.        
  347. invpixelhorline
  348. ;bc=x
  349. ;de=y
  350. ;hl=wid
  351.         ld a,h
  352.         or l
  353.         ret z
  354. invpixelhorline0
  355.         push hl
  356.         bit 0,l
  357.         call nz,line_invpixel
  358.         pop hl
  359.         inc bc ;x
  360.         dec hl
  361.         ld a,h
  362.         or l
  363.         jr nz,invpixelhorline0
  364.         ret
  365.  
  366.         SHAPESPROC shapes_prpixelframe
  367. ;c=y
  368. ;de=x
  369. ;b=hgt (последний пиксель = y+hgt)
  370. ;hl=wid (последний пиксель = x+wid)
  371. ;lx=color %rlrrrlll
  372.         push bc
  373.         push de
  374.         push hl ;wid
  375.         inc de ;x
  376.         call prpixelhorline
  377.         pop hl ;wid
  378.         pop de
  379.         pop bc
  380.         push bc
  381.         push de
  382.         push hl ;wid
  383.         ld a,c ;y
  384.         add a,b ;hgt
  385.         ld c,a ;c=y+hgt
  386.         call prpixelhorline
  387.         pop hl ;wid
  388.         pop de
  389.         pop bc
  390.         push bc
  391.         push de
  392.         add hl,de ;x
  393.         ex de,hl ;de=x+wid
  394.         inc c ;y
  395.         call prpixelverline
  396.         pop de
  397.         pop bc
  398. prpixelverline
  399. ;c=y
  400. ;de=x
  401. ;b=hgt
  402. ;lx=color
  403.         inc b
  404.         dec b
  405.         ret z
  406. prpixelverline0
  407. prpixelverline_patch=$+1
  408.         call prpixel
  409.         inc c
  410.         djnz prpixelverline0
  411.         ret
  412.        
  413. prpixelhorline
  414. ;c=y
  415. ;de=x
  416. ;hl=wid
  417. ;lx=color
  418.         ld a,h
  419.         or l
  420.         ret z
  421.         push hl
  422.         ld l,c
  423.         ld h,0
  424.         ld b,scrbase/256/8 ;h
  425.         add hl,hl
  426.         add hl,hl
  427.         add hl,bc
  428.         add hl,hl
  429.         add hl,hl
  430.         add hl,hl ;y*40 + scrbase
  431.         pop bc
  432.         ld a,c
  433.         dec bc
  434.         ld c,b
  435.         inc c ;c=(bc-1)/256+1
  436.         ld b,a ;b=bc&0xff
  437. prpixelhorline0
  438.         push hl ;addr(cury)
  439. prpixelhorline_patch=$+1
  440.         call prpixel_cury
  441.         pop hl ;addr(cury)
  442.         inc de ;x
  443.         djnz prpixelhorline0
  444.         dec c
  445.         jr nz,prpixelhorline0
  446.         ret
  447.        
  448.         SHAPESPROC shapes_invbox
  449. ;b=y
  450. ;c=x/8
  451. ;d=hgt
  452. ;e=wid
  453. invbox0
  454.         push de ;d = hgt, e = wid(chr)
  455.         call invhorline
  456.         pop de ;d = hgt, e = wid(chr)
  457.         inc b ;y
  458.         dec d
  459.         jr nz,invbox0
  460.         ret
  461.  
  462. invhorline
  463. ;b=y
  464. ;c=x/8
  465. ;e=wid(chr)
  466.         push bc
  467.         call calcscr_from_xchr_y
  468.          ld a,hx
  469.          xor lx
  470.          ld c,a
  471.         ld b,e
  472. invhorline0
  473.         ld a,(hl)
  474.         xor c;cpl
  475.         ld (hl),a
  476.         set 5,h
  477.         ld a,(hl)
  478.         xor c;cpl
  479.         ld (hl),a
  480.         set 6,h
  481.         ld a,(hl)
  482.         xor c;cpl
  483.         ld (hl),a
  484.         res 5,h
  485.         ld a,(hl)
  486.         xor c;cpl
  487.         ld (hl),a
  488.         res 6,h
  489.         inc hl
  490.         djnz invhorline0
  491.         pop bc
  492.         ret
  493.        
  494.         SHAPESPROC shapes_colortocolormask
  495. ;a=color = %....3210
  496.         push bc
  497.         ld c,a
  498.         ld b,c
  499.         srl b
  500.         rra
  501.         srl b
  502.         rra
  503.         srl b
  504.         rra
  505. ;a=%210...
  506.         srl c
  507.         rra
  508.         srl c
  509.         rra
  510.         srl c
  511.         rra
  512. ;a=%210210...
  513.         rrc c
  514.         rra
  515.         rlc c
  516.         rra
  517.         pop bc
  518.         ret
  519.  
  520.         SHAPESPROC shapes_fillbox
  521. ;b=y
  522. ;c=x/8
  523. ;d=hgt
  524. ;e=wid8
  525. ;a=%33210210
  526. fillbox0
  527.         push de ;d = hgt, e = wid(chr)
  528.         call prhorline
  529.         pop de ;d = hgt, e = wid(chr)
  530.         inc b ;y
  531.         dec d
  532.         jr nz,fillbox0
  533.         ret
  534.        
  535.         SHAPESPROC shapes_prbox
  536. ;b=y
  537. ;c=x/8
  538. ;d=hgt
  539. ;e=wid8
  540. ;a=%33210210 (рамка чёрная)
  541.         push bc ;b = y, c = x
  542.         push de ;d = hgt, e = wid(chr)
  543.         call shapes_fillbox
  544.         pop de ;d = hgt, e = wid(chr)
  545.         pop bc ;b = y, c = x
  546.         jp shapes_prboxframe
  547.        
  548.         SHAPESPROC shapes_prboxframe
  549. ;b=y
  550. ;c=x/8
  551. ;d=hgt
  552. ;e=wid8
  553. ;(рамка чёрная)
  554.         push de ;d = hgt, e = wid(chr)
  555.         call prverline_l
  556.         pop de ;d = hgt, e = wid(chr)
  557.         push bc
  558.         ld a,c ;x/8
  559.         add a,e ;wid(chr)
  560.         dec a
  561.         ld c,a ;x/8+wid(chr)-1
  562.         push de ;d = hgt, e = wid(chr)
  563.         call prverline_r
  564.         pop de ;d = hgt, e = wid(chr)
  565.         pop bc
  566.  
  567.         xor a ;black
  568.         call prhorline                  
  569.         ld a,b ;y
  570.         add a,d ;hgt
  571.         dec a
  572.         ld b,a ;y+hgt-1
  573.         xor a ;black
  574.         ;call prhorline          
  575.         ;ret      
  576. prhorline
  577. ;b=y
  578. ;c=x/8
  579. ;e=wid(chr)
  580. ;a=%rlrrrlll
  581.         push bc
  582.         push af
  583.         call calcscr_from_xchr_y
  584.         pop af
  585.         ld b,e
  586. prhorline0
  587.         ld (hl),a
  588.         set 5,h
  589.         ld (hl),a
  590.         set 6,h
  591.         ld (hl),a
  592.         res 5,h
  593.         ld (hl),a
  594.         res 6,h
  595.         inc hl
  596.         djnz prhorline0
  597.         pop bc
  598.         ret
  599.        
  600. prverline_l
  601. ;b=y
  602. ;c=x/8
  603. ;d=hgt
  604.         push bc
  605.         call calcscr_from_xchr_y
  606.         ld a,0xb8;%10111000
  607.         and (hl)
  608.         ld b,d
  609.         ld de,40
  610. prverline_l0
  611.         ld (hl),a
  612.         add hl,de
  613.         djnz prverline_l0
  614.         pop bc
  615.         ret
  616.        
  617. prverline_r
  618. ;b=y
  619. ;c=x/8
  620. ;d=hgt
  621.         push bc
  622.         call calcscr_from_xchr_y
  623.         ld a,h
  624.         add a,0x60
  625.         ld h,a
  626.         ld a,0x47;%01000111
  627.         and (hl)
  628.         ld b,d
  629.         ld de,40
  630. prverline_r0
  631.         ld (hl),a
  632.         add hl,de
  633.         djnz prverline_r0
  634.         pop bc
  635.         ret
  636.        
  637.         SHAPESPROC shapes_line
  638. ;bc=x (в плоскости экрана, но может быть отрицательным)
  639. ;de=y (в плоскости экрана, но может быть отрицательным)
  640. ;ix=x2
  641. ;hl=y2
  642.         or a
  643.         sbc hl,de
  644.         add hl,de
  645.         jp p,shapes_line_noswap
  646.         ex de,hl ;y <-> y2
  647.         push ix
  648.         push bc
  649.         pop ix
  650.         pop bc ;x <-> x2
  651.         ;ld a,lx
  652.         ;ld lx,c
  653.         ;ld c,a
  654.         ;ld a,hx
  655.         ;ld hx,b
  656.         ;ld b,a ;x <-> x2
  657. shapes_line_noswap
  658.         or a
  659.         sbc hl,de ;dy >= 0
  660.         push hl ;dy
  661.         ;ld a,lx
  662.         ;sub c
  663.         ;ld l,a
  664.         ;ld a,hx
  665.         ;sbc a,b
  666.         ;ld h,a
  667.         push ix
  668.         pop hl
  669.         sbc hl,bc
  670.         push hl ;dx
  671.         exx
  672.         pop bc ;dx
  673.         ld a,0x03 ;inc bc
  674.         jp p,shapes_line_nodec
  675.         xor a
  676.         sub c
  677.         ld c,a
  678.         sbc a,b
  679.         sub c
  680.         ld b,a ;dx >= 0
  681.         ld a,0x0b ;dec bc
  682. shapes_line_nodec
  683.         pop de ;dy
  684. ;a=код inc/dec bc
  685. ;bc'=x (в плоскости экрана, но может быть отрицательным)
  686. ;de'=y (в плоскости экрана, но может быть отрицательным)
  687. ;bc=dx
  688. ;de=dy
  689.         ex de,hl
  690.         or a
  691.         sbc hl,bc
  692.         add hl,bc
  693.         ex de,hl
  694.         jr nc,shapes_linever ;dy>=dx
  695.         ld hy,b
  696.         ld ly,c ;counter=dx
  697.         inc iy ;inc hy ;рисуем, включая последний пиксель (учтено в цикле)
  698.         ld h,b
  699.         ld l,c
  700.         sra h
  701.         rr l ;ym=dx div 2
  702.          ;xor a
  703.          ;sub l
  704.          ;ld l,a
  705.          ;sbc a,h
  706.          ;sub l
  707.          ;ld h,a ;mym=256-(dx div 2)
  708.         exx
  709.         ld (shapes_lineincx),a
  710. ;bc=x
  711. ;de=y
  712. ;hl'=xm
  713. ;bc'=dx
  714. ;de'=dy
  715. shapes_linehor0
  716.         call line_invpixel
  717. shapes_lineincx=$
  718.         inc bc ;x+1        
  719.         exx
  720.         ;add hl,de ;mym+dy
  721.         or a
  722.         sbc hl,de ;ym-dy
  723.         exx
  724.         jr nc,shapes_linehor1
  725.         inc de ;y+1
  726.         exx
  727.         ;or a
  728.         ;sbc hl,bc ;mym-dx
  729.         add hl,bc ;ym+dx
  730.         exx
  731. shapes_linehor1
  732.         dec iy
  733.         ld a,hy
  734.         rla
  735.         jp nc,shapes_linehor0
  736.         ret
  737. shapes_linever
  738.         ld hy,d
  739.         ld ly,e ;counter=dy
  740.         ;inc iy ;inc hy ;рисуем, включая последний пиксель (учтено в цикле)
  741.         ld h,d
  742.         ld l,e
  743.         sra h
  744.         rr l
  745.          ;xor a
  746.          ;sub l
  747.          ;ld l,a
  748.          ;sbc a,h
  749.          ;sub l
  750.          ;ld h,a ;mxm=256-(dy div 2)
  751.         exx
  752.         ld (shapes_lineincx2),a
  753. ;bc=x
  754. ;de=y
  755. ;hl'=xm
  756. ;bc'=dx
  757. ;de'=dy
  758. shapes_linever0
  759.         call line_invpixel
  760.         inc de ;y+1
  761.         exx
  762.         ;add hl,bc ;mxm+dx
  763.         or a
  764.         sbc hl,bc ;xm-dx
  765.         exx
  766.         jr nc,shapes_linever1
  767. shapes_lineincx2=$
  768.         inc bc ;x+1
  769.         exx
  770.         ;or a
  771.         ;sbc hl,de ;mxm-dy
  772.         add hl,de ;xm+dy
  773.         exx
  774. shapes_linever1
  775.         dec iy
  776.         ld a,hy
  777.         rla
  778.         jp nc,shapes_linever0
  779.         ret
  780.  
  781.         macro NEXTCOLUMN
  782.         bit 6,h
  783.         set 6,h
  784.         jr z,1f;shapes_linehorR_incxok
  785.         ld a,h
  786.         xor 0x60
  787.         ld h,a
  788.         and 0x20
  789.         jr nz,1f;shapes_linehorR_incxok
  790.         inc hl
  791. 1;shapes_linehorR_incxok
  792.         endm
  793.  
  794. xytoscraddr
  795. ;l=x/2
  796. ;e=y (не портится)
  797. ;screen pages are mapped in 2 CPU windows
  798. ;addr = tY(y) + tX(x)
  799.         ld h,tx/256
  800.         ld d,ty/256
  801.         ld a,(de) ;(y*40)
  802.         add a,(hl) ;x div 4
  803.         ld (xytoscraddr_l),a
  804.         inc d
  805.         inc h
  806.         ld a,(de) ;'(y*40)
  807.         adc a,(hl) ;f(x mod 4)
  808.         ld h,a
  809. xytoscraddr_l=$+1
  810.         ld l,0
  811.         ret
  812.  
  813.         if 1==0
  814. prpixel
  815. ;bc=x (не портится)
  816. ;e=y (не портится)
  817. ;screen pages are mapped in 2 CPU windows
  818. ;addr = tY(y) + tX(x)
  819.         push bc
  820.         ld a,b
  821.         rra
  822.         ld a,c
  823.         rra
  824.         ld l,a
  825.         ;ld d,ty/256
  826.         ;ld h,tx/256
  827.         ld a,(de) ;(y*40)
  828.         jr c,prpixel_r
  829.         add a,(hl) ;x div 4
  830.         ld c,a
  831.         inc d
  832.         inc h
  833.         ld a,(de) ;'(y*40)
  834.         adc a,(hl) ;f(x mod 4)
  835.         ld b,a
  836.         ld a,(bc)
  837.         and 0xb8 ;keep right pixel ;иначе надо cls перед redraw
  838. prpixel_color_l=$+1
  839.         or 0;lx
  840.         ld (bc),a
  841.         dec h
  842.         dec d
  843.         pop bc
  844.         ret
  845. prpixel_r
  846.         add a,(hl) ;x div 4
  847.         ld c,a
  848.         inc d
  849.         inc h
  850.         ld a,(de) ;'(y*40)
  851.         adc a,(hl) ;f(x mod 4)
  852.         ld b,a
  853.         ld a,(bc)
  854.         and 0x47 ;keep left pixel ;иначе надо cls перед redraw
  855. prpixel_color_r=$+1
  856.         or 0;lx
  857.         ld (bc),a
  858.         dec h
  859.         dec d
  860.         pop bc
  861.         ret
  862.         endif
  863.  
  864.         SHAPESPROC shapes_drawwindow
  865.         push iy
  866. ;hx=brush color byte 0bRLrrrlll
  867. ;lx=background fill color byte 0bRLrrrlll
  868. ;b=hgt
  869. ;c=wid/2
  870. ;l=x/2
  871. ;e=y
  872.         ld hy,e
  873.         ld a,l
  874.         ld ly,a
  875. ;ly=x/2
  876. ;hy=y
  877.         call xytoscraddr
  878. ;hl=screen addr
  879.         dec b
  880.         push bc
  881.         push hl
  882.        
  883. drawwindowfill0
  884.         push bc
  885.         push hl
  886.         ld c,lx ;ld c,0b11111111 ;color byte 0bRLrrrlll
  887.         call drawverline
  888.         pop hl
  889.         NEXTCOLUMN
  890.         pop bc
  891.         dec c
  892.         jr nz,drawwindowfill0
  893.        
  894.         pop hl ;screen addr
  895.         pop bc
  896.  
  897.         push bc
  898.  
  899.         push bc
  900.         push hl
  901.         call drawbox
  902.         pop hl
  903.         pop bc
  904.         NEXTCOLUMN
  905.         ld de,40*2
  906.         add hl,de ;второй бокс внутри первого
  907.         dec c
  908.         dec c
  909.         ld a,b
  910.         sub 4
  911.         ld b,a
  912.         call drawbox
  913.        
  914.         pop bc ;b=hgt-1, c=wid/2
  915.        
  916. ;ly=x/2
  917. ;hy=y
  918.         ld e,hy
  919.         inc e
  920.         call drawwindowhormarks
  921.        
  922.         ld a,hy
  923.         add a,b ;+hgt-1
  924.         dec a
  925.         ld e,a
  926.         call drawwindowhormarks
  927.  
  928.         push bc
  929.         call drawwindowvermarks
  930.         pop bc
  931.         ld a,ly
  932.         add a,c ;wid/2
  933.         dec a
  934.         ld ly,a
  935.         call drawwindowvermarks
  936.         pop iy
  937.         ret
  938.        
  939. drawwindowvermarks
  940. ;ly=x/2
  941. ;hy=y
  942. ;b=hgt-1
  943. ;lx=color byte 0bRLrrrlll
  944.         ld a,ly
  945.         ld l,a
  946.         ld a,hy
  947.         add a,6
  948.         ld e,a
  949. ;l=x/2
  950. ;e=y
  951.         call xytoscraddr
  952.         ld a,hx
  953.         ld (hl),a
  954.         ld a,ly
  955.         ld l,a
  956.         ld a,hy
  957.         add a,b ;+hgt-1
  958.         sub 6
  959.         ld e,a
  960. ;l=x/2
  961. ;e=y        
  962.         call xytoscraddr
  963.         ld a,hx
  964.         ld (hl),a
  965.         ret
  966.  
  967.        
  968. drawwindowhormarks
  969. ;ly=x/2
  970. ;e=y
  971. ;c=wid/2
  972.         ld a,ly
  973.         add a,3
  974.         ld l,a
  975. ;l=x/2
  976. ;e=y
  977.         call xytoscraddr
  978.         ld a,hx
  979.         xor lx
  980.         and 0b01000111 ;color byte 0bRLrrrlll
  981.         xor lx
  982.         ld (hl),a
  983.  
  984.         ld a,ly
  985.         add a,c ;+wid/2
  986.         sub 3+1
  987.         ld l,a
  988. ;l=x/2
  989. ;e=y
  990.         call xytoscraddr
  991.         ld a,hx
  992.         xor lx
  993.         and 0b10111000 ;color byte 0bRLrrrlll
  994.         xor lx
  995.         ld (hl),a
  996.         ret
  997.        
  998.         SHAPESPROC shapes_drawbutton_pressed
  999.         scf
  1000.         jr drawbutton_go
  1001.  
  1002.         SHAPESPROC shapes_drawbutton
  1003.         or a
  1004. drawbutton_go
  1005.        push iy
  1006.  
  1007.         push af
  1008. ;iy=button descriptor (kept)
  1009. ;hx=brush color byte 0bRLrrrlll
  1010. ;lx=background fill color byte 0bRLrrrlll
  1011. ;b=hgt
  1012. ;c=wid/2
  1013. ;l=x/2
  1014. ;e=y
  1015.        ;push iy
  1016.         ld hy,e
  1017.         ld a,l
  1018.         ld ly,a
  1019. ;ly=x/2
  1020. ;hy=y
  1021. ;l=x/2
  1022. ;e=y
  1023.         ;call xytoscraddr
  1024. ;hl=screen addr
  1025.         dec b
  1026.         if 1==0
  1027.         push bc
  1028.         push hl
  1029. drawbuttonfill0
  1030.         push bc
  1031.         push hl
  1032.         ld c,lx ;ld c,0b11111111 ;color byte 0bRLrrrlll
  1033.         call drawverline
  1034.         pop hl
  1035.         NEXTCOLUMN
  1036.         pop bc
  1037.         dec c
  1038.         jr nz,drawbuttonfill0
  1039.         pop hl ;screen addr
  1040.         pop bc
  1041.         endif
  1042.  
  1043.        ;pop de ;"iy"
  1044.        
  1045.         pop af
  1046.         jr c,drawbutton_pressed_go
  1047.  
  1048.          push ix
  1049.          ld a,hx
  1050.          ld hx,lx
  1051.          ld lx,a
  1052.         call drawbutton_pressed_pp
  1053.          pop ix
  1054.         push bc
  1055.         ld e,hy
  1056.         ld a,ly
  1057.         ld l,a
  1058. ;l=x/2
  1059. ;e=y
  1060.         call xytoscraddr
  1061.         call drawbox
  1062.         pop bc
  1063.  
  1064.         call drawbutton_unpressed_pp
  1065.  
  1066.         push bc
  1067. ;ly=x/2
  1068. ;hy=y
  1069.         ld e,hy
  1070.         inc e
  1071.         inc e
  1072.         ld a,ly
  1073.         add a,c
  1074.         dec a
  1075.         ld l,a
  1076. ;l=x/2
  1077. ;e=y
  1078.         call xytoscraddr
  1079. ;hl=scraddr
  1080.         dec b
  1081.         ld c,hx
  1082. ;c=color byte 0bRLrrrlll
  1083. ;b=hgt
  1084.         call drawverline
  1085.         pop bc
  1086.        pop iy
  1087.         ret
  1088.  
  1089. drawbutton_pressed_go
  1090.          push ix
  1091.          ld a,hx
  1092.          ld hx,lx
  1093.          ld lx,a
  1094.         call drawbutton_unpressed_pp
  1095.          pop ix
  1096.         push bc
  1097.         ld e,hy
  1098.         ld a,ly
  1099.         ld l,a
  1100. ;l=x/2
  1101. ;e=y
  1102.         call xytoscraddr
  1103.         call drawbox
  1104.         pop bc
  1105.         call drawbutton_pressed_pp
  1106.  
  1107.         push bc
  1108. ;ly=x/2
  1109. ;hy=y
  1110.         ld e,hy
  1111.         inc e
  1112.         ld a,ly
  1113.         ld l,a
  1114. ;l=x/2
  1115. ;e=y
  1116.         call xytoscraddr
  1117. ;hl=scraddr
  1118.         ld c,hx
  1119. ;c=color byte 0bRLrrrlll
  1120. ;b=hgt
  1121.         dec b
  1122.         call drawverline
  1123.         pop bc
  1124.        pop iy
  1125.         ret
  1126.  
  1127. drawbutton_pressed_pp
  1128. ;bc=hgtwid/2
  1129.         push bc
  1130. ;ly=x/2
  1131. ;hy=y
  1132.         ld e,hy
  1133.         inc e
  1134.         ld a,ly
  1135.         ld l,a
  1136. ;l=x/2
  1137. ;e=y
  1138.         call xytoscraddr
  1139. ;hl=scraddr
  1140.         ld b,c
  1141.         ld c,hx
  1142. ;c=color byte 0bRLrrrlll
  1143. ;b=wid/2
  1144.         call drawhorline
  1145.         pop bc
  1146.         ret
  1147.  
  1148. drawbutton_unpressed_pp
  1149. ;bc=hgtwid/2
  1150.         push bc
  1151. ;ly=x/2
  1152. ;hy=y
  1153.         ld a,hy
  1154.         add a,b
  1155.         dec a
  1156.         ld e,a
  1157.         ld a,ly
  1158.         inc a
  1159.         ld l,a
  1160. ;l=x/2
  1161. ;e=y
  1162.         call xytoscraddr
  1163. ;hl=scraddr
  1164.         ld b,c
  1165.         dec b
  1166.         ld c,hx
  1167. ;c=color byte 0bRLrrrlll
  1168. ;b=wid/2
  1169.         call drawhorline
  1170.         pop bc
  1171.         ret
  1172.  
  1173.  
  1174. drawbox
  1175. ;hl=screen addr
  1176. ;hx=brush color byte 0bRLrrrlll
  1177. ;lx=background fill color byte 0bRLrrrlll
  1178. ;b=hgt-1
  1179. ;c=wid/2
  1180.         push bc
  1181.         push hl
  1182.         push bc
  1183.         ld a,hx
  1184.         xor lx
  1185.         and 0b01000111 ;color byte 0bRLrrrlll
  1186.         xor lx
  1187.         ld c,a
  1188.         call drawverline ;left line
  1189.         pop bc
  1190.         ld b,c ;wid/2
  1191.         ex (sp),hl
  1192.         ld c,hx ;ld c,0b11111111 ;color byte 0bRLrrrlll
  1193.         push bc
  1194.         call drawhorline ;top line
  1195.         pop bc ;b=wid/2, c=color byte 0bRLrrrlll
  1196.         ex (sp),hl ;bottom of left line
  1197.         call drawhorline ;bottom line
  1198.         pop hl ;rightmost byte of top line
  1199.         ld de,40
  1200.         add hl,de
  1201.         pop bc
  1202.         dec b ;b=hgt/2
  1203.         ld a,hx
  1204.         xor lx
  1205.         and 0b10111000 ;color byte 0bRLrrrlll
  1206.         xor lx
  1207.         ld c,a
  1208.         ;call drawverline ;right line
  1209.         ;ret
  1210. drawverline
  1211. ;hl=scraddr
  1212. ;c=color byte 0bRLrrrlll
  1213. ;b=hgt
  1214.         ld de,40
  1215. drawverline0
  1216.         ld (hl),c
  1217.         add hl,de
  1218.         djnz drawverline0
  1219.         ret
  1220.  
  1221. drawhorline
  1222. ;hl=scraddr
  1223. ;c=color byte 0bRLrrrlll
  1224. ;b=wid/2
  1225.         ld de,0x4000
  1226.         jr drawhorline0go
  1227. drawhorline0
  1228.         NEXTCOLUMN
  1229. drawhorline0go
  1230.         ld (hl),c
  1231.         djnz drawhorline0
  1232.         ret
  1233.  
  1234.         align 256
  1235. tx
  1236.         dup 256
  1237.         db ($&0xff)/4
  1238.         edup
  1239.         dup 64
  1240.         db 0x80
  1241.         db 0xc0
  1242.         db 0xa0
  1243.         db 0xe0
  1244.         edup
  1245. ty
  1246.         dup 200
  1247.         db 0xff&(($&0xff)*40)
  1248.         edup
  1249.         ds 56,0xff&8000
  1250.         dup 200
  1251.         db (($&0xff)*40)/256
  1252.         edup
  1253.         ds 56,8000/256
  1254.