?login_element?

Subversion Repositories NedoOS

Rev

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