Subversion Repositories NedoOS

Rev

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

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