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