?login_element?

Subversion Repositories NedoOS

Rev

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

  1.  
  2. texted_XYTOP=0x0000
  3. texted_HGT=24
  4. texted_WID=80
  5. _texted_PANELCOLOR=0x0700;0x38
  6.  
  7. textview
  8.         ;xor a
  9.         ;ld h,a
  10.         ;ld l,a
  11.         ;call texted_settop
  12.         ;ld (curlineaddr),hl
  13.         ;ld (curlineaddrHSB),a
  14.         ;ld hl,1
  15.         ;ld (texted_ncurline),hl
  16.         ;ld hl,0
  17.         ;ld (curxy),hl
  18.         call texted_gotobof
  19.        
  20.         call texted_panel        
  21.        
  22.         call texted_calclines
  23.  
  24. texted_redrawloop
  25.         call setredrawflag
  26. texted_mainloop
  27. texted_lineredrawflag=$
  28.         scf ;/or a
  29.         call c,texted_prcurline ;might set redrawflag
  30. texted_redrawflag=$
  31.         scf ;/or a
  32.         call c,texted_prcurpage
  33.  
  34. ;texted_waitkey_nokey
  35.         ld de,(curxy)
  36.         call nv_setxy
  37.         ld a,2
  38. mainloop_yieldkeep
  39.         ld (wasnokey),a
  40.         YIELDKEEP
  41.         ld a,55+128 ;"or a"
  42.         ld (texted_wasyield),a
  43. texted_waitkey_nokey
  44.         GETKEY_ ;OS_GETKEYNOLANG
  45.         ;or a ;cp NOKEY ;keylang==0?
  46.         ;jr nz,texted_mainloop_keyq
  47.         ;cp c ;keynolang==0?
  48.         ;ld a,c ;keynolang
  49.         ;cp NOKEY ;TODO отличить от отсутствия фокуса nz? (не в фокусе клавиши не отдаются)
  50.         jr nz,texted_mainloop_keyq ;event
  51.         GETKEY_
  52.         jr nz,texted_mainloop_keyq ;event
  53.        ld a,(stdindatacount)
  54.        or a
  55.        jr nz,texted_mainloop
  56. ;если два раза подряд нет события, то делаем YIELD, иначе YIELDKEEP
  57. ;рисовать панельку только при отсутствии события после YIELD
  58. wasnokey=$+1
  59.         ld a,1
  60.         dec a
  61.         jr nz,mainloop_yieldkeep
  62. texted_wasyield=$
  63.         scf
  64.         jr nc,nopanel
  65. texted_panelredrawflag=$
  66.         scf ;/or a
  67.         call c,texted_panel
  68.         ld de,(curxy)
  69.         call nv_setxy
  70. nopanel
  71.         YIELD
  72.         ld a,55 ;"scf"
  73.         ld (texted_wasyield),a
  74.         jr texted_waitkey_nokey
  75. texted_mainloop_keyq      
  76.  
  77.         cp key_redraw
  78.         jr z,texted_redrawloop
  79.         cp key_esc
  80.         ret z
  81.        
  82.         ld hl,texted_mainloop
  83.         push hl
  84.         cp key_up
  85.         jp z,texted_up
  86.         cp key_down
  87.         jp z,texted_down
  88.         cp key_pgup
  89.         jp z,texted_pgup
  90.         cp key_pgdown
  91.         jp z,texted_pgdown
  92.         ;cp 's'
  93.         ;jp z,texted_changeencoding
  94.         cp key_home
  95.         jp z,texted_home
  96.         cp key_end
  97.         jp z,texted_end
  98.         cp key_left
  99.         jp z,texted_left
  100.         cp key_right
  101.         jp z,texted_right
  102.         cp key_sspgup;ext3
  103.         jp z,texted_gotobof;home
  104.         cp key_sspgdown;ext4
  105.         jp z,texted_gotoeof;end
  106.         cp extW
  107.         jp z,texted_wrap
  108.          cp key_ins
  109.          jp z,texted_wrap
  110.         cp key_backspace
  111.         jp z,texted_backspace
  112.         cp key_del
  113.         jp z,texted_del
  114.         cp key_enter
  115.         jp z,texted_enter
  116.         cp key_csenter
  117.         jp z,texted_save
  118.         cp key_F2
  119.         jp z,texted_save
  120.         cp 0x20
  121.         ret c ;прочие системные кнопки не нужны
  122. typein
  123.         ld c,a
  124.         call linesize_minus_x ;sz<x = error
  125.         call c,insert_minushl_spaces
  126.         call calccursoraddr
  127.         call insertbyte
  128. ;TODO wrap (reprint screen if needed)        
  129.         call setlineredrawflag;texted_prcurpage
  130.         jp texted_right
  131.  
  132. linesize_minus_x
  133. ;sz<x = CY
  134.         ld hl,(curlineaddr)
  135.         ld a,(curlineaddrHSB)
  136.         call calclinesz ;hl=sz
  137.         ex de,hl
  138.         call calccurlinex
  139.         ex de,hl
  140.         or a
  141.         sbc hl,de ;sz<x = error
  142.         ret
  143.  
  144. insert_minushl_spaces
  145.         push bc
  146. textinsertsymbol_pseudospace0
  147.         push hl ;sz-x < 0
  148.         call texted_end
  149.         call calccursoraddr
  150.         ld c,' '
  151.         call insertbyte
  152.         pop hl ;sz-x < 0
  153.         inc hl
  154.         inc h
  155.         dec h
  156.         jr nz,textinsertsymbol_pseudospace0
  157.         call texted_end
  158.         pop bc
  159.         ret
  160.  
  161. texted_enter
  162.         call linesize_minus_x ;sz<x = error
  163.         ;jr nc,texted_enter_nopseudospaces
  164.         call c,texted_end
  165. ;texted_enter_nopseudospaces
  166.         call calccursoraddr
  167.         ld c,0x0d
  168.         call insertbyte
  169.         ld c,0x0a
  170.         call insertbyte
  171.         xor a
  172.         ld (curx),a
  173.         ld hl,0
  174.         ld (texted_prline_shift),hl
  175.  
  176.         call setredrawflag;texted_prcurpage
  177.  
  178.         call incnlines
  179.         jp texted_down
  180.        
  181. texted_save
  182. texted_filenameaddr=$+1
  183.         ld de,defaultfilename
  184.         OS_CREATEHANDLE
  185.         or a
  186.         ret nz
  187. ;b=new file handle
  188.         push bc
  189.         ld a,b
  190.         ld (cmd_savepage_handle),a
  191.  
  192.         ;ld de,(fcb+FCB_FSIZE)
  193.         ;ld hl,(fcb+FCB_FSIZE+2)
  194.         call getsize
  195.         ex de,hl
  196.         ld l,a
  197.         ld h,0
  198.         ld a,0 ;page number
  199. texted_save0
  200. ;a=page number in table (0..)
  201. ;hlde=remaining size
  202.         push af ;pg
  203.         push de ;remaining LSW
  204.         push hl ;remaining HSW
  205.         call setpg32k
  206.         ld a,d
  207.         and 0xc0
  208.         or h
  209.         or l
  210.         jr z,$+5 ;de=size
  211.         ld de,#4000
  212.         ex de,hl ;hl=pg size
  213.          push hl ;hl=pg size
  214.         call cmd_savepage
  215.          pop bc ;bc=pg size
  216.         pop hl ;remaining HSW
  217.         pop de ;remaining LSW
  218.         ex de,hl
  219.         or a
  220.         sbc hl,bc
  221.         ex de,hl
  222.         jr nc,$+3
  223.         dec hl ;size = size-pgsize
  224.         ld a,h
  225.         or l
  226.         or d
  227.         or e
  228.         jr z,texted_save_popq
  229.         pop af ;pg
  230.         inc a
  231.         jr texted_save0
  232. texted_save_popq
  233.         pop af
  234.         pop bc
  235.         OS_CLOSEHANDLE
  236.         call setunchanged
  237.         jp setpanelredrawflag
  238.  
  239. cmd_savepage
  240. ;hl=size
  241. ;out: a=error
  242. cmd_savepage_handle=$+1
  243.         ld b,0
  244.         ld de,#8000
  245. ;B = file handle, DE = Buffer address, HL = Number of bytes to write
  246.         OS_WRITEHANDLE
  247. ;HL = Number of bytes actually written, A=error
  248.         ret
  249.        
  250. setredrawflag
  251.         ld a,55 ;scf
  252.         ld (texted_redrawflag),a
  253.         ;ret
  254. setpanelredrawflag
  255.         ld a,55 ;scf
  256.         ld (texted_panelredrawflag),a
  257.         ret
  258. setlineredrawflag
  259.         ld a,55 ;scf
  260.         ld (texted_lineredrawflag),a
  261.         jr setpanelredrawflag;ret
  262.  
  263. calccurlinex
  264.         ld hl,(texted_prline_shift)
  265.         ld a,(curx)
  266.         add a,l
  267.         ld l,a
  268.         ret nc
  269.         inc h
  270.         ret
  271.        
  272. calccursoraddr
  273. ;TODO учитывать ширину строки (правее строки простое сложение бессмысленно)
  274.         call calccurlinex
  275.         ex de,hl
  276.         ld hl,(curlineaddr)
  277.         ld a,(curlineaddrHSB)
  278.         add hl,de
  279.         adc a,0
  280.         ret
  281.        
  282. texted_backspace
  283. ;TODO wrap (set y, reprint screen if needed)
  284.         call calccurlinex
  285.         ld a,h
  286.         or l
  287.         jr z,texted_backspace_startline
  288.  
  289.         call linesize_minus_x ;sz<x = error
  290.         jp c,texted_left
  291.  
  292.         call calccursoraddr
  293.         call prevbyte
  294.         ;call isbof
  295.         ;ret z
  296.         call deletebyte        
  297.         call setlineredrawflag
  298.         jp texted_left
  299. texted_backspace_startline
  300.         call calccursoraddr
  301.         call isbof
  302.         ret z
  303.         call prevbyte
  304.         call getbyte
  305.         push bc
  306.         call deletebyte
  307.         pop bc
  308.         ld b,a
  309.          ld a,c ;deleted byte
  310.          cp 0x0d
  311.          ld a,b
  312.          jr z,texted_backspace_startline_onlycr ;for CR texts
  313.         ld a,c
  314.         cp 0x0a
  315.         ld a,b
  316.         jr nz,texted_backspace_startline_onlycr
  317.         call isbof
  318.         jr z,texted_backspace_startline_onlycr
  319.         call prevbyte
  320.         call getbyte
  321.         ld b,a
  322.         ld a,c
  323.         cp 0x0d
  324.         ld a,b
  325.         ;jr nz,texted_backspace_startline_onlycr
  326.         call z,deletebyte ;0x0d
  327. texted_backspace_startline_onlycr
  328. ;ahl=at deleted CR/LF
  329. ;if not CR/LF before, go to "previous line" (after earlier CR/LF) and count difference
  330. ;else x=0
  331.          push af
  332.          push hl
  333.         call prevbyte
  334.         call getbyte ;c
  335.          pop hl
  336.          pop af
  337.          ld d,h
  338.          ld e,l
  339.         ld b,a
  340.         ld a,c
  341.         cp 0x0d
  342.         jr z,texted_backspace_startline_setxshift_hlminusde
  343.         cp 0x0a
  344.         jr z,texted_backspace_startline_setxshift_hlminusde
  345.         ld a,b
  346.  
  347.         ;push af
  348.         push hl
  349.         call texted_prevline ;CY=error (impossible?)
  350.         ex de,hl
  351.         ;ld c,a
  352.         pop hl ;hl=at deleted CR?,de=prevline
  353.         ;pop af
  354. texted_backspace_startline_setxshift_hlminusde
  355.         or a
  356.         sbc hl,de
  357.         ;sbc a,c
  358.         call setxshift_hl
  359.        
  360.         call setredrawflag
  361.  
  362.         call decnlines
  363.         jp texted_up
  364.  
  365. decnlines
  366.         push hl
  367.         ld hl,(nlines)
  368.         dec hl
  369.         ld (nlines),hl
  370.         pop hl
  371.         ret
  372. incnlines
  373.         push hl
  374.         ld hl,(nlines)
  375.         inc hl
  376.         ld (nlines),hl
  377.         pop hl
  378.         ret
  379.  
  380. texted_home
  381. ;TODO wrap (set y)
  382.         ld hl,0
  383.         call setxshift_hl
  384.         jp setredrawflag
  385.  
  386. texted_end
  387. ;TODO wrap (set y)
  388.         ;call calccursoraddr
  389.         ld hl,(curlineaddr)
  390.         ld a,(curlineaddrHSB)
  391.         call calclinesz ;hl=sz
  392.         call setxshift_hl
  393.         jp setredrawflag
  394.  
  395. calclinesz
  396. ;ahl=line addr
  397. ;out: hl=sz (keeps bc,de)
  398.         push bc
  399.         call texted_nextline ;CY=error
  400.         call c,getsize
  401.         call nc,skipbackcrlf
  402.         ld bc,(curlineaddr)
  403.         or a
  404.         sbc hl,bc
  405.         pop bc
  406.         ret
  407.  
  408. skipbackcrlf
  409. ;out: ahl=eof or endline+1 (at cr/lf)
  410.         call isbof
  411.         ret z
  412.         call prevbyte
  413.         call getbyte
  414.         ld b,a
  415.          ld a,c
  416.          cp 0x0d
  417.          ld a,b
  418.          ret z ;for CR texts
  419.         ld a,c
  420.         cp 0x0a
  421.         ld a,b
  422.         jp nz,nextbyte
  423.         call isbof
  424.         ret z
  425.         call prevbyte
  426.         call getbyte
  427.         ld b,a
  428.         ld a,c
  429.         cp 0x0d
  430.         ld a,b
  431.         jp nz,nextbyte
  432.         ret
  433.        
  434. setxshift_hl
  435. ;X=hl=ahl-startline
  436. ;x+shift = X:
  437. ;x = min(X,texted_WID-1), но под mod8 должен совпадать с X
  438. ;shift = X-x
  439.         ld bc,texted_WID-1
  440.         call minhl_bc_tobc
  441.         ld a,c
  442.         xor l
  443.         and %11111000
  444.         xor l
  445.         ld c,a
  446.         ld (curx),a
  447.         or a
  448.         sbc hl,bc
  449.         ld (texted_prline_shift),hl
  450.         ret
  451.        
  452. texted_del
  453. ;TODO wrap (set y, reprint screen if needed)
  454.         call linesize_minus_x ;sz<x = error
  455.         jr c,texted_del_newline
  456.         jr z,texted_del_newline
  457.         call texted_right
  458.         jp texted_backspace
  459. texted_del_newline
  460. ;удаление ентера справа (backspace не умеет)
  461. ;hl=sz-x
  462.         call c,insert_minushl_spaces
  463.         call setredrawflag
  464.         call calccursoraddr
  465.         call iseof
  466.         ret z
  467.         call decnlines
  468.         call getbyte
  469.         push af
  470.         call deletebyte
  471.         pop bc ;b=deleted byte
  472.         ld c,a
  473.         ld a,b
  474.         cp 0x0a
  475.         ld a,c
  476.         ret z ;endline = 0x0a
  477.         call iseof
  478.         ret z
  479.         call getbyte
  480.         ld b,a
  481.         ld a,c
  482.         cp 0x0a
  483.         ld a,b
  484.         ret nz
  485.         call deletebyte        
  486.         ret
  487.        
  488. texted_wrap
  489.         ld a,(wrapflag)
  490.         xor 128
  491.         ld (wrapflag),a
  492.         ld hl,0
  493.         ld (texted_prline_shift),hl
  494.         ld (curxy),hl
  495.         call texted_calclines
  496.         ld hl,(curtoptextaddr)
  497.         ld a,(curtoptextHSB)
  498.         ld (curlineaddr),hl
  499.         ld (curlineaddrHSB),a
  500.         call texted_calccurline
  501.         jp setredrawflag;texted_prcurpage
  502.        
  503. texted_right
  504. ;TODO X<16384
  505.         call setpanelredrawflag
  506.         ld de,(curxy)
  507.         inc e
  508.         ld a,e
  509.         cp texted_WID
  510.         ld (curx),a
  511.         ret c
  512.          call iswrapon ;CY=on
  513.          jr c,texted_right_wrap
  514.         ld hl,(texted_prline_shift)
  515.         ld bc,8
  516.         add hl,bc
  517.         ld (texted_prline_shift),hl
  518.         ld a,e
  519.         sub c;8
  520.         ld (curx),a
  521.         jp setredrawflag;texted_prcurpage
  522.        
  523. texted_right_wrap
  524.         xor a
  525.         ld (curx),a
  526.         jp texted_down
  527.        
  528. texted_left
  529.         call setpanelredrawflag
  530.         ld de,(curxy)
  531.         ld a,e
  532.         sub 1
  533.         ld e,a
  534.         ld (curx),a
  535.         ret nc
  536.         xor a
  537.         ld (curx),a
  538.         ld hl,(texted_prline_shift)
  539.         ld bc,8
  540.         or a
  541.         sbc hl,bc
  542.         ret c
  543.         ld (texted_prline_shift),hl
  544.         ld a,e
  545.         add a,c;8
  546.         ld (curx),a
  547.         jp setredrawflag;texted_prcurpage
  548.        
  549. texted_prcurline
  550.         ld a,55+0x80 ;or a
  551.         ld (texted_lineredrawflag),a
  552.         ld de,(curxy)
  553.         ld e,0
  554.         push de
  555.         call nv_setxy
  556.         pop de
  557. ;print lines until CR or EOF
  558.         ld hl,(curlineaddr)
  559.         ld a,(curlineaddrHSB)
  560. texted_prcurline_continue0
  561.         push de
  562.         call texted_prline_nextline
  563.         call c,getsize
  564.         call iseof
  565.         pop de
  566.         ret z
  567.         call prevbyte
  568.         call getbyte
  569.         ld b,a
  570.         ld a,c
  571.         cp 0x0d
  572.         ret z
  573.         cp 0x0a
  574.         ret z
  575.         inc d
  576.         ld a,d
  577.         cp texted_HGT
  578.         ret z
  579.         ld a,b
  580.         call nextbyte
  581.         jr texted_prcurline_continue0
  582.  
  583. texted_prcurpage
  584.          ;ld e,0
  585.          ;OS_CLS
  586.         ld a,55+0x80 ;or a
  587.         ld (texted_redrawflag),a
  588.         ld hl,(curtoptextaddr)
  589.         ld a,(curtoptextHSB)
  590.         jp texted_prpage
  591.        
  592. texted_gotobof
  593.         xor a
  594.         ld h,a
  595.         ld l,a
  596. ;texted_gotobof_ok
  597.         call texted_settop
  598.         ld (curlineaddr),hl
  599.         ld (curlineaddrHSB),a
  600.         ;ld hl,1
  601.         ;ld (texted_ncurline),hl
  602. ;ahl=curtextline (kept)
  603.         call texted_calccurline
  604.         ld hl,0
  605.         ld (curxy),hl
  606.         jp setredrawflag;texted_prcurpage
  607.  
  608. getsize
  609.         ld hl,(filesize)
  610.         ld a,(filesizeHSW)
  611.         ret
  612.        
  613. texted_gotoeof
  614.         call getsize
  615.         ld b,texted_HGT
  616. texted_end0
  617.         push bc
  618.         call texted_prevline
  619.         pop bc
  620.         djnz texted_end0
  621. ;ahl=curtextline (kept)
  622.         call texted_calccurline
  623.         jp texted_pgdown_bottom
  624.  
  625.  
  626. deccurline
  627.         push hl
  628.         ld hl,(texted_ncurline)
  629.         dec hl
  630.         ld (texted_ncurline),hl
  631.         pop hl
  632.         ret
  633. deccury
  634.         push hl
  635.         ld hl,cury
  636.         dec (hl)
  637.         pop hl
  638.         ret
  639.        
  640. inccurline
  641.         push hl
  642.         ld hl,(texted_ncurline)
  643.         inc hl
  644.         ld (texted_ncurline),hl
  645.         pop hl
  646.         ret
  647. inccury
  648.         push hl
  649.         ld hl,cury
  650.         inc (hl)
  651.         pop hl
  652.         ret
  653.  
  654. texted_up
  655.         ld hl,(curlineaddr)
  656.         ld a,(curlineaddrHSB)
  657.         call texted_prevline
  658.         ret c
  659.         ld (curlineaddr),hl
  660.         ld (curlineaddrHSB),a
  661.         push af
  662.         push hl
  663.         call deccurline
  664.         call setpanelredrawflag
  665.         pop hl
  666.         pop af
  667.         ld c,a
  668.         ld a,(cury)
  669.         sub 1
  670.         ld (cury),a
  671.         ret nc
  672.         inc a
  673.         ld (cury),a
  674.         ld a,c
  675.         call texted_settop
  676.         push af
  677.         push hl
  678.         ld de,texted_XYTOP
  679.         ld hl,256*texted_HGT + texted_WID
  680.         call scrolldown ;OS_SCROLLDOWN
  681.         ld de,texted_XYTOP
  682.         call nv_setxy
  683.         pop hl
  684.         pop af
  685.         call texted_prline
  686.         ret
  687.  
  688. texted_down
  689.         ld hl,(curlineaddr)
  690.         ld a,(curlineaddrHSB)
  691.         call texted_nextline
  692.         ret c
  693.         ld (curlineaddr),hl
  694.         ld (curlineaddrHSB),a
  695.         push af
  696.         push hl
  697.         call inccurline
  698.         call setpanelredrawflag
  699.         pop hl
  700.         pop af
  701.         ld c,a
  702.         ld de,(curxy)
  703.         inc d
  704.         ld a,d
  705.         cp texted_HGT
  706.         ld (curxy),de
  707.         ret c
  708.         dec a
  709.         ld (cury),a
  710.         ld a,c
  711.         push af
  712.         push hl
  713.         ld de,texted_XYTOP
  714.         ld hl,256*texted_HGT + texted_WID
  715.         call scrollup ;OS_SCROLLUP
  716.         ld de,texted_XYTOP+((texted_HGT-1)*256)
  717.         call nv_setxy
  718.         pop hl
  719.         pop af
  720.         call texted_prline;_nextline
  721. curtoptextaddr=$+1
  722.         ld hl,0
  723. curtoptextHSB=$+1
  724.         ld a,0
  725.         call texted_nextline
  726. texted_settop        
  727.         ld (curtoptextaddr),hl
  728.         ld (curtoptextHSB),a
  729.         ret
  730.  
  731. texted_pgup
  732.         call setpanelredrawflag
  733.         ld a,(cury)
  734.         or a
  735.         ld b,a
  736.         ld hl,(curlineaddr)
  737.         ld a,(curlineaddrHSB)
  738.         jr z,texted_pgup_top
  739. texted_pgup_gotop0
  740.         push bc
  741.         call texted_prevline
  742.          call nc,deccurline
  743.          call nc,deccury
  744.         pop bc
  745.         djnz texted_pgup_gotop0
  746.         ld (curlineaddr),hl
  747.         ld (curlineaddrHSB),a
  748.         ret
  749. texted_pgup_top
  750.         ld b,texted_HGT-1
  751. texted_pgup0
  752.         push bc
  753.         call texted_prevline
  754.          call nc,deccurline
  755.         pop bc
  756.         djnz texted_pgup0
  757.         call texted_settop
  758.         ld (curlineaddr),hl
  759.         ld (curlineaddrHSB),a
  760.         call setredrawflag
  761.         ret
  762.        
  763. texted_pgdown
  764.         call setpanelredrawflag
  765.         ld a,(cury)
  766.         sub texted_HGT-1
  767.         neg
  768.         ld b,a
  769.         ld hl,(curlineaddr)
  770.         ld a,(curlineaddrHSB)
  771.         jr z,texted_pgdown_bottom
  772. texted_pgdown_gobottom0
  773.         push bc
  774.         call texted_nextline
  775.          call nc,inccurline
  776.          call nc,inccury
  777.         pop bc
  778.         djnz texted_pgdown_gobottom0
  779.         ld (curlineaddr),hl
  780.         ld (curlineaddrHSB),a
  781.         ret
  782. texted_pgdown_bottom
  783.         push af
  784.         xor a
  785.         ld (cury),a
  786.         pop af
  787.         call texted_settop
  788.         ld b,texted_HGT-1
  789. texted_pgdown0
  790.         push bc
  791.         call texted_nextline
  792.          call nc,inccurline
  793.          call nc,inccury
  794.         pop bc
  795.         djnz texted_pgdown0
  796.         ld (curlineaddr),hl
  797.         ld (curlineaddrHSB),a
  798.         jp setredrawflag
  799.        
  800. texted_calccurline
  801. ;ahl=curtextline (kept)
  802.         push af
  803.         push hl
  804.         ld (texted_calccurline_old),hl
  805.         ld (texted_calccurline_oldHSB),a
  806.         ld ix,1;0
  807.          or h
  808.          or l
  809.          jr z,texted_calccurline_countq
  810.         xor a
  811.         ld h,a
  812.         ld l,a
  813. texted_calccurline_count0
  814.         call texted_nextline ;texted_pseudoprline
  815.  
  816.         if 1==0
  817.         jr c,texted_calccurline_countq ;не помогает
  818.         ex de,hl
  819. texted_calccurline_old=$+1
  820.         ld hl,0
  821.         or a
  822.         sbc hl,de ;nc: hl<=old
  823.         ld l,a
  824. texted_calccurline_oldHSB=$+1
  825.         ld a,0
  826.         sbc a,l
  827.         ld a,l
  828.         inc ix
  829.         jr nc,texted_calccurline_count0 ;nc: ahl<=old
  830.         else
  831.        
  832.         push hl
  833. texted_calccurline_old=$+1
  834.         ld bc,0
  835.         or a
  836.         sbc hl,bc ;nc: hl>=old
  837.         ld l,a
  838. texted_calccurline_oldHSB=$+1
  839.         sbc a,0
  840.         ld a,l
  841.         pop hl
  842.         inc ix
  843.         jr c,texted_calccurline_count0 ;cy: ahl<old
  844.         endif
  845. texted_calccurline_countq
  846.         ;push ix
  847.         ;pop hl
  848.         ld (texted_ncurline),ix;hl
  849.         pop hl
  850.         pop af
  851.         ret
  852.        
  853. texted_calclines
  854. ;sets nlines
  855.         xor a
  856.         ld h,a
  857.         ld l,a
  858.         ld (nlines),hl
  859. texted_calclines0
  860.         call incnlines
  861.         call texted_nextline
  862.         jr nc,texted_calclines0
  863.         ret
  864.        
  865. clear_keyboardbuffer
  866.         push bc
  867.         ld b,50;5
  868. clear_keyboardbuffer0
  869.         push bc
  870.         GETKEY_
  871.         pop bc
  872.         djnz clear_keyboardbuffer0
  873.         pop bc
  874.         ret
  875.        
  876. texted_changeencoding
  877.         ld hl,texted_prline_recodepatch
  878.         ld a,(hl)
  879.         xor 0x7e ;"ld a,(hl)"
  880.         ld (hl),a
  881.         call setredrawflag;texted_prcurpage
  882.         ;call texted_prcurpage
  883.         ;ret
  884. texted_panel
  885.         ld a,55+0x80 ;or a
  886.         ld (texted_panelredrawflag),a
  887.         ld de,0x1800
  888.         call nv_setxy
  889.         ld de,_texted_PANELCOLOR
  890.         SETCOLOR_
  891.        
  892.         ld a,(texted_prline_recodepatch)
  893.         or a
  894.         ld hl,t866
  895.         jr z,$+5
  896.         ld hl,twin
  897.         call prtext
  898.        
  899. fchanged=$+1
  900.         ld a,' '
  901.         PRCHAR_
  902.         call calccurlinex
  903.         inc hl
  904.         call prword
  905.         ld a,','
  906.         PRCHAR_
  907. texted_ncurline=$+1
  908.         ld hl,0
  909.         call prword
  910.         ld a,'/'
  911.         PRCHAR_
  912.         ld hl,(nlines)
  913.         exx
  914.         ld hl,0
  915.         exx
  916.         call prdword
  917.         ld a,' '
  918.         PRCHAR_
  919.         call getsize
  920.         exx
  921.         ;ld hl,(fcb+FCB_FSIZE+2)
  922.         ld l,a
  923.         ld h,0
  924.         exx
  925.         ;ld hl,(fcb+FCB_FSIZE)
  926.         call prdword
  927.         ld de,tspaces_filename
  928.         ld hl,TSPACES_FILENAME_SZ
  929.         call sendchars
  930.         ;ld de,_texted_PANELCOLOR;#38
  931.         ;OS_PRATTR
  932.         ld de,_COLOR
  933.         SETCOLOR_
  934.        
  935.         ret
  936.  
  937. tspaces_filename
  938.         db ' '
  939. tshown_filename
  940.         ds TSPACES_FILENAME_SZ,' '
  941.        
  942. twin
  943.         db "WIN",0
  944. t866
  945.         db "866",0
  946.  
  947.      
  948. isbof
  949. ;out: z=bof
  950.         push bc
  951.         ld c,a
  952.         or h
  953.         or l
  954.         ld a,c
  955.         pop bc
  956.         ret
  957. iseof
  958. ;out: z=eof
  959.         push bc
  960.         push de
  961.         push hl
  962.         ;ld de,(fcb+FCB_FSIZE)
  963.         ;ld bc,(fcb+FCB_FSIZE+2)
  964.         ;ld b,a
  965.         ;or a
  966.         ;sbc hl,de
  967.         ;sbc a,c
  968.         ;ld a,b
  969.         ex de,hl
  970.         ld c,a
  971.         call getsize
  972.         or a
  973.         sbc hl,de
  974.         sbc a,c
  975.         or h
  976.         or l
  977.         ld a,c
  978.         pop hl
  979.         pop de
  980.         pop bc
  981.         ret
  982.      
  983. texted_prpage
  984. ;ahl=addr
  985.         ld (curtoptextaddr),hl
  986.         ld (curtoptextHSB),a
  987.         push af
  988.         ld de,texted_XYTOP
  989.         call nv_setxy
  990.         pop af
  991.         ld b,texted_HGT
  992. texted_prpage0
  993.         push bc
  994.         ;push de
  995.         call texted_prline_nextline
  996.         call c,getsize
  997.         ;pop de
  998.         pop bc
  999.         ;inc d
  1000.         djnz texted_prpage0
  1001.         ;call clear_keyboardbuffer
  1002.         ret
  1003.        
  1004. texted_prevline
  1005. ;ahl=addr
  1006. ;line < 16K
  1007. ;out: ahl, CY=error (keeps de)
  1008.         call isbof
  1009.          scf
  1010.         ret z
  1011. ;перед нами может быть #0d или #0d,#0a или ничего
  1012.         ld (findprevline_old),hl
  1013.         ld (findprevline_oldHSB),a
  1014.        
  1015.         or a
  1016.         ld bc,0xffff
  1017.         jr nz,$+4
  1018.          ld b,h
  1019.          ld c,l
  1020.          
  1021.         push de
  1022.         ld de,0x4000
  1023.         or a
  1024.         sbc hl,de
  1025.         sbc a,e;0
  1026.         pop de
  1027.        
  1028.         push af
  1029.         push hl
  1030.         call ahl_to_pgaddr
  1031.         set 6,h
  1032. ;hl=c000+, можно уменьшать
  1033. ;bc=number of chars to go != 0
  1034.  
  1035. ;перед нами может быть #0d или #0d,#0a или ничего
  1036.         dec hl
  1037.         dec bc
  1038.         ld a,b
  1039.         or c
  1040.         jr z,texted_prevlineq
  1041.         ld a,0x0a
  1042.         cp (hl)
  1043.         jr nz,texted_prevline_nolf
  1044.         dec hl
  1045.         dec bc
  1046.         ld a,b
  1047.         or c
  1048.         jr z,texted_prevlineq
  1049. texted_prevline_nolf
  1050.         ld a,0x0d
  1051.         cp (hl)
  1052.         jr nz,texted_prevline_nocr
  1053.         dec hl
  1054.         dec bc
  1055.         ld a,b
  1056.         or c
  1057.         jr z,texted_prevlineq
  1058. texted_prevline_nocr
  1059. ;сейчас мы находимся перед символом конца предыдущей строки (не на нём)
  1060. texted_prevline0
  1061.         ld a,(hl)
  1062.         cp 0x0d
  1063.         jr z,texted_prevline_cr
  1064.         cp 0x0a
  1065.         jr z,texted_prevline_lf
  1066.         dec hl
  1067.         dec bc
  1068.         ld a,b
  1069.         or c
  1070.         jr nz,texted_prevline0
  1071. ;beginning of file
  1072.         jr texted_prevlineq
  1073. texted_prevline_cr
  1074. texted_prevline_lf
  1075. ;сейчас мы находимся на конце символа конца строки перед предыдущей
  1076.         inc hl
  1077. texted_prevlineq
  1078.         ex de,hl ;new addr (bits 13..0), bit 14 = overflow
  1079.         pop hl ;old addr
  1080.         pop af
  1081.         call pgaddr_to_ahl
  1082.         call iswrapon ;CY=on
  1083.         ret nc ;no wrap
  1084.  
  1085. findprevline_linewrap
  1086. ;ahl = в начале строки
  1087. ;перед ней может быть #0d или #0d,#0a
  1088. ;надо псевдонапечатать несколько псевдострок, пока не дойдём до текущей
  1089. findprevline_linewrap_count0
  1090.          push af
  1091.          push hl
  1092.         call texted_pseudoprline
  1093.         push hl
  1094. findprevline_old=$+1
  1095.         ld bc,0
  1096.         or a
  1097.         sbc hl,bc ;nc: hl>=old
  1098.         ld l,a
  1099. findprevline_oldHSB=$+1
  1100.         sbc a,0
  1101.         ld a,l
  1102.         pop hl
  1103.          pop de ;old addr
  1104.          pop bc ;b=old HSB
  1105.         jr c,findprevline_linewrap_count0
  1106.         ex de,hl
  1107.         ld a,b
  1108. ;ahl=на псевдострочку раньше
  1109.         ret ;nc
  1110.  
  1111. getmaxlinesize
  1112. ;ahl = addr
  1113. ;out: bc=max line size before eof, z=(bc==0) (keeps ahl,de)
  1114.          push de
  1115.         push af
  1116.         push hl
  1117.         ex de,hl
  1118.         ld c,a
  1119.         call getsize
  1120.         or a
  1121.         sbc hl,de
  1122.         sbc a,c
  1123.         ld bc,0
  1124.         jr c,getmaxlinesize_aftereof
  1125.         dec bc
  1126.         or a
  1127.         jr nz,$+4 ;filesize-addr >= 0x10000, will be 0xffff
  1128.          ld b,h
  1129.          ld c,l ;filesize-addr
  1130. getmaxlinesize_aftereof
  1131.         pop hl
  1132.         pop af
  1133.         ld e,a
  1134.         ld a,b
  1135.         or c
  1136.         ld a,e
  1137.          pop de
  1138.         ret
  1139.  
  1140. texted_prline_nextline
  1141.         push af
  1142.         push hl
  1143.         call texted_prline
  1144.         pop hl
  1145.         pop af
  1146. texted_nextline
  1147. ;if eof, returns CY and old addr (use call c,getsize) [eof addr]
  1148. ;ahl=addr
  1149. ;line < 16K
  1150. ;out: ahl, CY=error (keeps de)
  1151.         call iswrapon ;CY=on
  1152.         jp c,texted_pseudoprline
  1153.         call getmaxlinesize ;bc=max line size before eof, z=(bc==0)
  1154.          scf
  1155.         ret z
  1156.         push af
  1157.         push hl
  1158.         call ahl_to_pgaddr
  1159. ;bc=number of chars to go != 0
  1160. texted_nextline0
  1161.         ld a,(hl)
  1162.         inc hl
  1163.         dec bc
  1164.         cp 0x0d
  1165.         jr z,texted_nextline_cr
  1166.         cp 0x0a
  1167.         jr z,texted_nextline_lf
  1168.         ld a,b
  1169.         or c
  1170.         jr nz,texted_nextline0
  1171. ;texted_nextline_eof
  1172.         pop hl ;old addr
  1173.         pop af
  1174.         scf ;error
  1175.         ret
  1176. texted_nextlineq
  1177.         ex de,hl ;new addr (bits 13..0), bit 14 = overflow
  1178.         pop hl ;old addr
  1179.         pop af
  1180.         jp pgaddr_to_ahl
  1181. texted_nextline_cr
  1182.         ld a,b
  1183.         or c
  1184.         jr z,texted_nextlineq
  1185.         ld a,(hl)
  1186.         cp 0x0a
  1187.         jr nz,texted_nextline_lf
  1188.         inc hl
  1189. texted_nextline_lf
  1190.         jr texted_nextlineq
  1191.        
  1192. texted_prline
  1193. ;ahl=addr
  1194. ;check for last line (vs. file size)
  1195. ;if filesize-addr < 80, then b=filesize-addr, else b=80
  1196.         call getmaxlinesize ;bc=max line size before eof, z=(bc==0)
  1197.         jr z,texted_prlinespc_all;ret z
  1198.         call ahl_to_pgaddr
  1199. ;hl=#8000+0..#3fff
  1200. ;bc=max line size before eof != 0
  1201. texted_prline_shift=$+1
  1202.         ld de,0
  1203.         call istherecr_or_lf ;add hl,de
  1204.         ;jr nz,$+3
  1205.         ;dec hl ;hl=cr/lf address
  1206.  
  1207.         push hl
  1208.         ld h,b
  1209.         ld l,c
  1210.         or a
  1211.         sbc hl,de
  1212.         ld b,h
  1213.         ld c,l ;bc=bc-lineshift
  1214.         pop hl
  1215.         ;ld a,texted_WID
  1216.         jr c,texted_prlinespc_all
  1217.         jr z,texted_prlinespc_all ;maxlinesize<=lineshift
  1218.  
  1219.         push hl
  1220.         ld hl,texted_WID
  1221.         call minhl_bc_tobc
  1222.         ld b,c
  1223.         pop hl
  1224. ;b=number of chars to print != 0
  1225.         ld de,prlinebuf
  1226.         ld c,texted_WID
  1227. texted_prline0
  1228.         ld a,(hl)
  1229.         inc hl
  1230.         cp 0x0d
  1231.         jr z,texted_prline_cr
  1232.         cp 0x0a
  1233.         jr z,texted_prline_cr;lf
  1234.         ;push bc
  1235.         push hl
  1236.         ld h,twinto866/256
  1237.         ld l,a
  1238. texted_prline_recodepatch=$
  1239.         nop ;/ld a,(hl)
  1240.         ld (de),a ;PRCHAR_
  1241.         inc de
  1242.         pop hl
  1243.         ;pop bc
  1244.         dec c
  1245.         djnz texted_prline0
  1246.         ;call print_prlinebuf
  1247.         ;jr nz,texted_prline_lf
  1248.         ;ret
  1249. texted_prline_cr
  1250.         call print_prlinebuf
  1251. ;texted_prline_lf
  1252. ;допечатать пробелы до конца строки
  1253.         jr texted_prlinespc
  1254. texted_prlinespc_all
  1255.         ld c,texted_WID
  1256. texted_prlinespc
  1257.         push af
  1258.         push hl
  1259.         ;ld l,b
  1260.         ;ld h,0
  1261.         ;ld de,tspaces
  1262.         ;call sendchars
  1263.          ld a,c
  1264.          or a
  1265.         call nz,clearrestofline_crlf
  1266.         pop hl
  1267.         pop af
  1268.         ret
  1269.  
  1270. print_prlinebuf
  1271.         push af
  1272.         push bc
  1273.         push hl
  1274. ;c=texted_WID-число символов
  1275.         ld de,prlinebuf
  1276.         ld a,texted_WID
  1277.         sub c
  1278.         ld l,a
  1279.         ld h,0
  1280.         call sendchars
  1281.         pop hl
  1282.         pop bc
  1283.         pop af
  1284.         ret
  1285.  
  1286. prlinebuf
  1287.         ds texted_WID
  1288.  
  1289. texted_pseudoprline
  1290. ;ahl=addr
  1291. ;out: ahl, CY=error
  1292. ;check for last line (vs. file size)
  1293. ;if filesize-addr < 80, then b=filesize-addr, else b=80
  1294.         call getmaxlinesize ;bc=max line size before eof, z=(bc==0)
  1295.          scf
  1296.         ret z
  1297.         push af
  1298.         push hl
  1299.         call ahl_to_pgaddr
  1300. ;hl=#8000+0..#3fff
  1301. ;bc=max line size before eof != 0
  1302.         push hl
  1303.         ld hl,texted_WID
  1304.         call minhl_bc_tobc
  1305.         ld b,c
  1306.         pop hl
  1307. ;b=number of chars to print != 0
  1308.         ld c,texted_WID
  1309. texted_pseudoprline0
  1310.         ld a,(hl)
  1311.         inc hl
  1312.         cp 0x0d
  1313.         jr z,texted_pseudoprline_cr
  1314.         cp 0x0a
  1315.         jr z,texted_pseudoprline_lf
  1316.         dec c
  1317.         djnz texted_pseudoprline0
  1318.          ld a,(hl)
  1319.          inc hl
  1320.          cp 0x0d
  1321.          jr z,texted_pseudoprline_crok
  1322.          cp 0x0a
  1323.          jr z,texted_pseudoprline_lf
  1324.          dec hl
  1325.         jp texted_nextlineq
  1326. texted_pseudoprline_cr
  1327.         dec b
  1328.         jp z,texted_nextlineq
  1329. texted_pseudoprline_crok
  1330.         ld a,(hl)
  1331.         cp 0x0a
  1332.         jr nz,texted_pseudoprline_lf
  1333.         inc hl
  1334. texted_pseudoprline_lf
  1335.         jp texted_nextlineq
  1336.        
  1337. ;по идее это псевдопечать N экранных позиций (там могут быть цветовые коды и т.п.)
  1338. istherecr_or_lf
  1339. ;hl=addr ;TODO ahl
  1340. ;de=length to search
  1341. ;out: z=found, hl=at match or after area (TODO ahl)
  1342.         ld a,d
  1343.         or e
  1344.         jr z,istherecr_or_lf_fail
  1345.          push hl
  1346.         ld a,0x0d
  1347.         call istherecrlfgo
  1348.         jr z,istherecr_or_lf_popafZret;ret z
  1349.          pop hl
  1350.         ld a,0x0a
  1351. istherecrlfgo
  1352.         push bc
  1353.         ld b,d
  1354.         ld c,e
  1355.         cpir ;TODO несколько раз через все блоки, если заканчиваются блоки, то их переключать
  1356.         pop bc
  1357.         ret nz ;nz=not found
  1358.          dec hl
  1359.         ret ;z=found
  1360. istherecr_or_lf_fail
  1361.         dec a
  1362.         ret ;nz=not found
  1363.        
  1364. istherecr_or_lf_popafZret
  1365.         pop af
  1366.         cp a ;Z
  1367.         ret
  1368.        
  1369. ;texted_closefcb
  1370. ;        ld de,fcb
  1371. ;        OS_FCLOSE
  1372. ;        ret
  1373.  
  1374. setunchanged
  1375.         ld a,' '
  1376.         jr setchanged_a
  1377. setchanged
  1378.         ld a,'*'
  1379. setchanged_a
  1380.         ld (fchanged),a
  1381.         ret
  1382.  
  1383. iswrapon
  1384. ;CY = on
  1385. wrapflag=$
  1386.         or a ;/scf
  1387.         ret
  1388.  
  1389. curlineaddr
  1390.         ds 3
  1391. curlineaddrHSB=$-1
  1392.  
  1393. nlines
  1394.         dw 0
  1395.  
  1396. curxy
  1397. curx
  1398.         db 0
  1399. cury
  1400.         db 0
  1401.        
  1402.         align 256
  1403. twinto866
  1404.         incbin "../_sdk/codepage/winto866"
  1405.