?login_element?

Subversion Repositories NedoOS

Rev

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

  1. hexeditor_XYTOP=0x0000
  2. hexeditor_HGT=txtscrhgt-1
  3. hexeditor_WID=80
  4. hexeditor_MAXX=15
  5. hexeditor_PAGESIZE=16*hexeditor_HGT
  6.  
  7.        if PRSTDIO
  8. _hexeditor_CURSORCOLOR=0x0700;0x38
  9. _hexeditor_COLOR=0x0007;7
  10.        else
  11. _hexeditor_CURSORCOLOR=0x38
  12. _hexeditor_COLOR=7
  13.        endif
  14.  
  15. hexeditor_redrawloop
  16.         ;YIELDGETKEYLOOP
  17.         call hexeditor_prpage
  18. hexeditor_mainloop
  19.         call hexeditor_calccursorxy
  20.         ld hl,_hexeditor_CURSORCOLOR
  21.         ld b,2
  22.         call drawfilecursor_sizeb_colorhl
  23.         call hexeditor_calctextcursorxy
  24.        if PRSTDIO
  25.         call nv_setxy ;keeps de,hl,ix
  26.        else
  27.         ld hl,_hexeditor_CURSORCOLOR
  28.         ld b,1
  29.         call drawfilecursor_sizeb_colorhl
  30.        endif
  31.       if 0
  32. ;hexeditor_yieldkeep
  33.         ld a,2
  34. hexeditor_yieldkeep
  35.         ld (hexeditor_wasnokey),a
  36.         YIELDKEEP
  37.         ld a,55+128 ;"or a"
  38.         ld (hexeditor_wasyield),a
  39.       endif
  40. hexeditor_mainloop_nokey
  41.       if 0
  42.       else
  43.         YIELD
  44.       endif
  45.        if PRSTDIO
  46.         GETKEY_
  47.         jr nz,hexeditor_keyq
  48.         GETKEY_
  49.         jr nz,hexeditor_keyq
  50.         GETKEY_
  51.         jr nz,hexeditor_keyq ;event бывает 3-символьный
  52.        else
  53.         GET_KEY
  54.         ld a,c ;keynolang
  55.         ;cp NOKEY
  56.          or a
  57.         jr nz,hexeditor_keyq
  58.        endif
  59.        if PRSTDIO
  60.        ld a,(stdindatacount)
  61.        or a
  62.        jr nz,hexeditor_mainloop;_nokey
  63.        endif
  64.       if 0
  65. ;если два раза подряд нет события, то рисуем панельку и делаем YIELD, иначе YIELDKEEP
  66. hexeditor_wasnokey=$+1
  67.         ld a,1
  68.         dec a
  69.         jr nz,hexeditor_yieldkeep
  70. ;рисовать панельку только при отсутствии события после YIELD
  71. hexeditor_wasyield=$
  72.         scf
  73.         jr nc,hexeditor_nopanel
  74.       endif
  75.         call hexeditor_panel
  76.        if PRSTDIO
  77.         call hexeditor_calctextcursorxy
  78.         call nv_setxy ;keeps de,hl,ix
  79.        endif
  80.       if 0
  81. hexeditor_nopanel
  82.         YIELD
  83.         ld a,55 ;"scf"
  84.         ld (hexeditor_wasyield),a
  85.       endif
  86.         jr hexeditor_mainloop_nokey
  87. hexeditor_keyq
  88.         ;push hl
  89.         ;push bc
  90.         ;push de
  91.         push af
  92.         call hexeditor_calccursorxy
  93.         ld hl,_hexeditor_COLOR
  94.         ld b,2
  95.         call drawfilecursor_sizeb_colorhl
  96.        if PRSTDIO == 0
  97.         call hexeditor_calctextcursorxy
  98.         ld hl,_hexeditor_COLOR
  99.         ld b,1
  100.         call drawfilecursor_sizeb_colorhl
  101.        endif
  102.         pop af
  103.         ;pop de
  104.         ;pop bc
  105.         ;pop hl
  106.         cp key_redraw
  107.         jr z,hexeditor_redrawloop
  108.         cp key_esc
  109.         ret z
  110.         cp key_tab
  111.         jp z,nvview_hexeditorq
  112.         ld hl,hexeditor_mainloop
  113.         push hl
  114.          cp key_up
  115.          jp z,hexeditor_up
  116.          cp key_down
  117.          jp z,hexeditor_down
  118.          cp key_pgup
  119.          jp z,hexeditor_pgup
  120.          cp key_pgdown
  121.          jp z,hexeditor_pgdown
  122.         ;cp key_home
  123.         ;jp z,hexeditor_home
  124.         ;cp key_sspgup;ext3
  125.         ;jp z,hexeditor_home
  126.         ;cp key_end
  127.         ;jp z,hexeditor_end
  128.         ;cp key_sspgdown;ext4
  129.         ;jp z,hexeditor_end
  130.         cp key_left
  131.         jp z,hexeditor_left
  132.         cp key_right
  133.         jp z,hexeditor_right
  134.          cp key_csenter
  135.          jp z,hexeditor_save
  136.          cp key_F2
  137.          jp z,hexeditor_save
  138.         cp '0'
  139.         ret c
  140.         cp '9'+1
  141.         jr c,hexeditor_symbol
  142.         cp 'a'
  143.         ret c
  144.         cp 'f'+1
  145.         ret nc ;jp c,hexeditor_symbol
  146.         ;ret
  147. hexeditor_symbol
  148.         push af
  149.         call nvhex_calccuraddrline ;addr cur line
  150.         ld de,(hexcuraddrxy)
  151.         ld d,0
  152.         add hl,de ;addrcurline + x(e)
  153.         call ahl_to_pgaddr
  154.         pop af
  155.         ;0   a-10
  156.         cp 'a'
  157.         jr nc,hexeditor_symbol_af
  158.         ld b,-0x30
  159.         jr hexeditor_symbol_pr
  160. hexeditor_symbol_af        
  161.         ld b,-0x61+0x0a;0x56
  162. hexeditor_symbol_pr        
  163.         add a,b
  164.        
  165. hexeditor_half=$
  166.         or a ;/scf
  167.         jr c,hexeditor_symbol_right
  168.         add a,a
  169.         add a,a
  170.         add a,a
  171.         add a,a;a=XXXX0000
  172.         xor (hl)
  173.         and 0xf0
  174.         xor (hl)
  175.         jr hexeditor_symbol_rightq
  176. hexeditor_symbol_right
  177.         xor (hl)
  178.         and 0x0f
  179.         xor (hl)
  180. hexeditor_symbol_rightq
  181.         ld (hl),a
  182.         ld hl,hexeditor_half
  183.         ld a,(hl)
  184.         xor 0x80
  185.         ld (hl),a
  186.         call setchanged
  187.         call nvhex_calccuraddrline ;ahl=addr cur line
  188.         ld de,(hexcuraddrxy)
  189.         ld e,0
  190.         push af
  191.         call nv_setxy ;keeps de,hl,ix
  192.         pop af ;keep ahl!!!
  193.         jp hexeditor_prline
  194.  
  195. hexeditor_save
  196.         ;ld hl,fcb_filename
  197.         ;ld de,fcb2_filename
  198.         ;call copy_to_defcb_filename
  199.         ;call nv_createfcb2 ;autopush nv_closefcb2
  200.         ;ret nz ;error
  201.         ld de,filenametext
  202.         OS_CREATEHANDLE
  203.         or a
  204.         ret nz ;error
  205.         ld a,b
  206.         ld (curhandle),a
  207.         ld de,(filesize)
  208.         ld hl,(filesizeHSW)
  209.         ld a,0 ;page number
  210. hexeditor_save0
  211. ;a=page number in table (0..)
  212. ;hlde=remaining size
  213.         push af
  214.         push de
  215.         push hl
  216.         call setpg32k
  217.         ld a,d
  218.         and 0xc0
  219.         or h
  220.         or l
  221.         jr z,$+5 ;de=size
  222.          ld de,0x4000
  223.         ex de,hl ;hl=pg size
  224.         push hl ;hl=pg size
  225.         call cmd_savepage
  226.         pop bc ;bc=pg size
  227.         pop hl
  228.         pop de
  229.         ex de,hl
  230.         or a
  231.         sbc hl,bc
  232.         ex de,hl
  233.         jr nc,$+3
  234.          dec hl ;size = size-pgsize
  235.         ld a,h
  236.         or l
  237.         or d
  238.         or e
  239.         jr z,hexeditor_save_popq
  240.         pop af
  241.         inc a
  242.         jr hexeditor_save0
  243. hexeditor_save_popq
  244.         call nv_closehandle
  245.         call setunchanged
  246.         pop af
  247.         ret
  248.  
  249. hexeditor_left
  250.         ld de,(hexcuraddrxy)
  251.         ld a,e
  252.         cp 0
  253.         ret z
  254.         dec e
  255.         ld (hexcuraddrxy),de
  256.         ret
  257.  
  258. hexeditor_right
  259.         ld de,(hexcuraddrxy)
  260.         ld a,e
  261.         cp hexeditor_MAXX
  262.         ret z
  263.         inc e
  264.         push de
  265.         call nvhex_calccuraddrline ;ahl=lineaddr
  266.         pop de
  267.         push af
  268.         ld a,e
  269.         add a,l
  270.         ld l,a
  271.         pop af
  272.         call iseof
  273.         ret nc
  274.         ld (hexcuraddrxy),de
  275.         ret
  276.  
  277. hexeditor_calccursorxy
  278.         ld de,(hexcuraddrxy)
  279.         ld a,e
  280.         add a,a
  281.         add a,e
  282.         add a,8
  283.         ld e,a
  284.         ret
  285.  
  286. hexeditor_calctextcursorxy
  287.         ld de,(hexcuraddrxy)
  288.         ld a,e
  289.         add a,57
  290.         ld e,a
  291.         ret ;no ret because panel is empty
  292.  
  293. hexeditor_panel=nvview_panel
  294.         ;ret
  295.  
  296. hexeditor_prpage
  297.         ld hl,(hexaddrline)
  298.         ld a,(hexaddrlineHSB)
  299.         ld de,hexeditor_XYTOP
  300.         ld b,hexeditor_HGT
  301. hexeditor_prpage0
  302.         push bc
  303.         push de
  304.         push af
  305.         call nv_setxy ;keeps de,hl,ix
  306.         pop af
  307.         call hexeditor_prline
  308.         pop de
  309.         pop bc
  310.         inc d
  311.         djnz hexeditor_prpage0
  312. ;hexeditor_setbottom
  313.         ;ld (hexaddrline),hl
  314.         ;ld (hexaddrlineHSB),a
  315.         ret
  316.  
  317. hexeditor_prline
  318. ;ahl =  addr line      
  319.         push af
  320.         push hl
  321.         push hl
  322.         call getmaxlinesize ;bc=max line size before eof, z=(bc==0)
  323.         ld hl,16
  324.         call minhl_bc_tobc ;bc = min(16, max line size before eof)
  325.         pop hl
  326.         ;push bc
  327.          ld de,thexedline
  328.         call hexeditor_praddrline
  329.         call ahl_to_pgaddr
  330.          inc de      
  331.         ;pop bc ;bc = min(16, max line size before eof)
  332.  
  333.          push bc
  334.         push hl
  335.         ld a,c
  336.         or a
  337.         jr z,hexeditor_prlhex0q
  338.         ld b,a
  339. hexeditor_prlhex0
  340.          inc de
  341.         ld a,(hl)
  342.         rrca
  343.         rrca
  344.         rrca
  345.         rrca
  346.         or 0xf0
  347.         daa
  348.         add a,0xa0
  349.         adc a,0x40
  350.          ld (de),a
  351.          inc de
  352.         ld a,(hl)
  353.         or 0xf0
  354.         daa
  355.         add a,0xa0
  356.         adc a,0x40
  357.          ld (de),a
  358.          inc de
  359.         inc  l
  360.         djnz hexeditor_prlhex0
  361. hexeditor_prlhex0q
  362.         ld a,16
  363.         sub c
  364.         jp z,hexeditor_prlhex1q
  365.         ld b,a
  366.          ld a,' '
  367. hexeditor_prlhex1
  368.          inc de
  369.          ld (de),a
  370.          inc de
  371.          ld (de),a
  372.          inc de
  373.         djnz hexeditor_prlhex1
  374. hexeditor_prlhex1q
  375.  
  376.         pop hl
  377.          inc de
  378.          inc de
  379.         ld a,c
  380.         or a
  381.         jr z,hexeditor_prlsym0q
  382.         ld b,a
  383. hexeditor_prlsym0
  384.         ld a,(hl)
  385.         cp 32
  386.         jr nc,$+4
  387.           ld a,'.'
  388.          ld (de),a
  389.          inc de
  390.         inc  l
  391.         djnz hexeditor_prlsym0
  392. hexeditor_prlsym0q
  393.         ld a,16
  394.         sub c
  395.         jp z,hexeditor_prlsym1q
  396.         ld b,a
  397.          ld a,' '
  398. hexeditor_prlsym1
  399.          ld (de),a
  400.          inc de
  401.         djnz hexeditor_prlsym1
  402. hexeditor_prlsym1q
  403.          ld de,thexedline
  404.          ld hl,80
  405.          call sendchars
  406.          pop bc ;bc=bytes shown in line
  407.         pop hl
  408.         pop af
  409.         ;ld b,0
  410.         add hl,bc
  411.         adc a,b
  412.         ret
  413.  
  414. hexeditor_praddrline
  415. ;ahl = addr line
  416.         push af
  417.         call hexeditor_prNN
  418.         ld a,h
  419.         call hexeditor_prNN      
  420.         ld a,l        
  421.         call hexeditor_prNN
  422.         pop af
  423.         ret
  424.  
  425. hexeditor_prNN
  426. ;#30 - 0,1,2..9 #41 - A,B,C,D,E,F #61 - a,b,c..
  427. ;a=XX
  428.         push af
  429.         rrca
  430.         rrca
  431.         rrca
  432.         rrca
  433.         or 0xf0
  434.         daa
  435.         add a,0xa0
  436.         adc a,0x40
  437.          ld (de),a
  438.          inc de
  439.         pop af
  440.         or 0xf0
  441.         daa
  442.         add a,0xa0
  443.         adc a,0x40
  444.          ld (de),a
  445.          inc de
  446.         ret
  447.  
  448. thexedline
  449.         db "000000: 00 00 00 00 00 00 00 00|00 00 00 00 00 00 00 00  ................       "
  450.  
  451. hexeditor_prevline
  452. ;ahl =addr line  
  453. ;out: ahl =addr line, NC=error      
  454.         call isbof ;CY=0
  455.         ret z ;NC
  456.         push bc
  457.         ld bc,0x0010
  458.         or a
  459.         sbc hl,bc
  460.         sbc a,b
  461.         scf
  462.         pop bc
  463.         ret ;CY
  464.  
  465.         if 1==0
  466. hexeditor_nextline
  467.         call iseof
  468.         ret nc
  469.         push bc
  470.         ld bc,0x0010
  471.         add hl,bc
  472.         adc a,b
  473.         pop bc
  474.         ret
  475.         endif
  476.  
  477. hexeditor_pgup
  478.         call nvhex_calccuraddrline
  479.         ld de,(hexcuraddrxy)
  480.         ld c,a
  481.         ld a,d
  482.         or a
  483.         ld a,c
  484.         jr nz,hexeditor_pgupq
  485.         ld b,hexeditor_HGT-1
  486. hexeditor_pgup0
  487.         push bc
  488.         call hexeditor_prevline
  489.         pop bc
  490.         djnz hexeditor_pgup0
  491.         ld (hexaddrline),hl
  492.         ld (hexaddrlineHSB),a
  493.         call hexeditor_prpage
  494.         jp clear_keyboardbuffer
  495. hexeditor_pgupq
  496.         ld d,0
  497.         ld (hexcuraddrxy),de
  498.         ret
  499.  
  500. hexeditor_pgdown
  501.         call nvhex_calccuraddrline
  502.         ld de,(hexcuraddrxy)
  503.         ld c,a
  504.         ld a,d
  505.         cp hexeditor_HGT-1
  506.         ld a,c
  507.         jr z,hexeditor_pgdown_do
  508. hexeditor_pgdown0
  509.         ld c,a
  510.         ld a,d
  511.         cp hexeditor_HGT-1
  512.         ld a,c
  513.         jr z,hexeditor_pgdownq
  514.         call nvhex_calcnextcorrectxy
  515.         jr c,hexeditor_pgdown0
  516. hexeditor_pgdownq
  517.         ld (hexcuraddrxy),de
  518.         ret
  519. hexeditor_pgdown_do
  520.         ld (hexaddrline),hl
  521.         ld (hexaddrlineHSB),a
  522.         push de
  523.         call hexeditor_prpage
  524.         pop de
  525.         ld hl,(hexaddrline)
  526.         ld a,(hexaddrlineHSB)
  527.         ld d,0
  528. hexeditor_pgdown_do0
  529.         ld c,a
  530.         ld a,d
  531.         cp hexeditor_HGT-1
  532.         ld a,c
  533.         jr z,hexeditor_pgdown_doq
  534.         call nvhex_calcnextcorrectxy
  535.         jr c,hexeditor_pgdown_do0
  536. hexeditor_pgdown_doq
  537.         ld (hexcuraddrxy),de
  538.         jp clear_keyboardbuffer
  539.  
  540. hexeditor_up
  541.         call nvhex_calccuraddrline
  542.         call hexeditor_prevline
  543.         ret nc ;bof
  544.         ld de,(hexcuraddrxy)
  545.         ld a,d
  546.         or a
  547.         jr z,hexeditor_up_scroll
  548.         dec d
  549.         ld (hexcuraddrxy),de
  550.         ret
  551. hexeditor_up_scroll        
  552.         ld de,hexeditor_XYTOP
  553.         ld hl,256*hexeditor_HGT + hexeditor_WID
  554.        if PRSTDIO
  555.         call scrolldown
  556.        else
  557.         OS_SCROLLDOWN
  558.        endif
  559.         ld de,hexeditor_XYTOP
  560.         call nv_setxy ;keeps de,hl,ix
  561.         ld hl,(hexaddrline)
  562.         ld a,(hexaddrlineHSB)
  563.         call hexeditor_prevline
  564.         ld (hexaddrline),hl
  565.         ld (hexaddrlineHSB),a
  566.         jp hexeditor_prline
  567.  
  568. hexeditor_down
  569.         call nvhex_calccuraddrline
  570.         ld de,(hexcuraddrxy)
  571.         call nvhex_calcnextcorrectxy
  572.         ret nc
  573.         ld c,a
  574.         ld a,d
  575.         cp hexeditor_HGT
  576.         ld a,c
  577.         jr z,hexeditor_down_scroll
  578.         ld (hexcuraddrxy),de
  579.         ret
  580. hexeditor_down_scroll
  581.         ;ld hl,(hexaddrline)
  582.         ;ld a,(hexaddrlineHSB)
  583.         ;ld bc,hexeditor_PAGESIZE
  584.         ;add hl,bc
  585.         ;adc a,0
  586.         push af
  587.         push hl
  588.         ld a,e
  589.         ld (hexcuraddrx),a
  590.         ld de,hexeditor_XYTOP
  591.         ld hl,256*hexeditor_HGT + hexeditor_WID
  592.        if PRSTDIO
  593.         call scrollup
  594.        else
  595.         OS_SCROLLUP
  596.        endif
  597.         ld de,hexeditor_XYTOP+((hexeditor_HGT-1)*256)
  598.         call nv_setxy ;keeps de,hl,ix
  599.         ld hl,(hexaddrline)
  600.         ld a,(hexaddrlineHSB)
  601.         ld bc,16
  602.         add hl,bc
  603.         adc a,b;0
  604.         ld (hexaddrline),hl
  605.         ld (hexaddrlineHSB),a
  606.         pop hl
  607.         pop af
  608.         jp hexeditor_prline
  609.  
  610. nvhex_calccuraddrline
  611. ;out: ahl = addr cur line
  612.         ld hl,(hexaddrline)
  613.         ld a,(hexaddrlineHSB)
  614.         ld de,(hexcuraddrxy)
  615.         ld e,0
  616.         srl d
  617.         rr e
  618.         srl d
  619.         rr e
  620.         srl d
  621.         rr e
  622.         srl d
  623.         rr e
  624.         add hl,de       ;hl+d*16
  625.         adc a,0
  626.         ret
  627.  
  628. nvhex_calcnextcorrectxy
  629. ;ahl=line addr, de=yx
  630. ;out:ahl=line addr, de=yx, NC=error
  631.         ld bc,16
  632.         add hl,bc
  633.         adc a,b
  634.         call iseof
  635.         jr nc,nvhex_calcnextcorrectxy_error
  636.         inc d
  637.         ld c,e
  638.         ld b,0
  639.         push hl
  640.         add hl,bc
  641.         call iseof
  642.         pop hl
  643.         ret c
  644.         push af
  645.         ld a,(filesize)
  646.         dec a
  647.         and 0x0f
  648.         ld e,a
  649.         pop af
  650.         scf
  651.         ret ;CY
  652. nvhex_calcnextcorrectxy_error
  653.         call hexeditor_prevline
  654.         or a
  655.         ret ;NC
  656.        
  657. hexcuraddrxy
  658. hexcuraddrx
  659.         db 0
  660. hexcuraddry
  661.         db 0
  662.  
  663. hexaddrline
  664.         dw 0
  665. hexaddrlineHSB
  666.         db 0
  667.