?login_element?

Subversion Repositories NedoOS

Rev

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

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