Subversion Repositories NedoOS

Rev

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