Subversion Repositories NedoOS

Rev

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

  1. NVVIEW_HEXEDITOR_XYTOP=0x0000
  2. NVVIEW_HEXEDITOR_HGT=24
  3. NVVIEW_HEXEDITOR_WID=80
  4. NVVIEW_HEXEDITOR_PANELCOLOR=#38
  5. NVVIEW_HEXEDITOR_CURCOLOR=#38
  6. NVVIEW_HEXEDITOR_PAGESIZE=16*NVVIEW_HEXEDITOR_HGT
  7. COLOR_HEXEDITOR=7
  8. NVVIEW_HEXEDITOR_MAXX=15
  9.  
  10. nvview_hexeditor_redrawloop
  11.         ;YIELDGETKEYLOOP
  12.         call nvview_hexeditor_prpage
  13. nvview_hexeditor_prfile_mainloop
  14. 1;prwindow_waitkey_nokey
  15.         call nvhexed_calccursorxy
  16.         ld a,NVVIEW_HEXEDITOR_CURCOLOR
  17.         ld b,2
  18.         call drawfilecursor_sizeb
  19.        
  20.         YIELD ;halt ;хёыш ёфхырЄ№ яЁюёЄю di:rst #38, Єю 1.ёфтшэхь ЄрщьхЁ ш 2.ьюцхь яюЄхЁ Є№ ърфЁютюх яЁхЁ√трэшх, р хёыш схч ei, Єю сєфєЄ уы■ъш
  21.         GET_KEY ;OS_GETKEYNOLANG
  22.         ld a,c ;keynolang
  23.         push hl
  24.         push bc
  25.         push de
  26.         push af
  27.         call nvhexed_calccursorxy
  28.         ld a,COLOR_HEXEDITOR
  29.         ld b,2
  30.         call drawfilecursor_sizeb
  31.         pop af
  32.         pop de
  33.         pop bc
  34.         pop hl
  35.        
  36.         cp NOKEY
  37.         jr nz,nvview_hexeditor_prfileq
  38.         call nvview_hexeditor_panel
  39.         jr 1b;prwindow_waitkey_nokey
  40. nvview_hexeditor_prfileq
  41.         cp key_redraw
  42.         jr z,nvview_hexeditor_redrawloop
  43.         cp key_esc
  44.         ret z
  45.         cp key_tab
  46.         jp z,nvview_hexeditorq
  47.         ld hl,nvview_hexeditor_prfile_mainloop
  48.         push hl
  49.          cp key_up
  50.          jp z,nvview_hexeditor_up
  51.          cp key_down
  52.          jp z,nvview_hexeditor_down
  53.          cp key_pgup
  54.          jp z,nvview_hexeditor_pgup
  55.          cp key_pgdown
  56.          jp z,nvview_hexeditor_pgdown
  57.         ;cp key_home
  58.         ;jp z,nvview_hexeditor_home
  59.         ;cp key_sspgup;ext3
  60.         ;jp z,nvview_hexeditor_home
  61.         ;cp key_end
  62.         ;jp z,nvview_hexeditor_end
  63.         ;cp key_sspgdown;ext4
  64.         ;jp z,nvview_hexeditor_end
  65.         cp key_left
  66.         jp z,nvview_hexeditor_left
  67.         cp key_right
  68.         jp z,nvview_hexeditor_right
  69.          cp key_csenter
  70.          jp z,nvview_hexeditor_save
  71.         ;cp 'w'
  72.         ;jp z,nvview_wrap
  73.         cp '0'
  74.         ret c
  75.         cp '9'+1
  76.         jp c,nvview_hexeditor_symbol
  77.         cp 'a'
  78.         ret c
  79.         cp 'f'+1
  80.         jp c,nvview_hexeditor_symbol
  81.         ret
  82.  
  83. nvview_hexeditor_symbol
  84.         push af
  85.         call nvhex_calccuraddrline ;addr cur line
  86.         ld de,(hexcuraddrxy)
  87.         ld d,0
  88.         add hl,de ;addrcurline + x(e)
  89.         call ahl_to_pgaddr
  90.         pop af
  91.         ;0   a-10
  92.         cp 'a'
  93.         jr nc,nvview_hexeditor_symbol_af
  94.         ld b,-#30
  95.         jr nvview_hexeditor_symbol_pr
  96. nvview_hexeditor_symbol_af        
  97.         ld b,-#61+#0a;#56
  98. nvview_hexeditor_symbol_pr        
  99.         add a,b
  100.        
  101. nvhexed_half=$
  102.         or a ;/scf
  103.         jr c,nvhexed_symbol_right
  104.         add a,a
  105.         add a,a
  106.         add a,a
  107.         add a,a;a=XXXX0000
  108.         xor (hl)
  109.         and #f0
  110.         xor (hl)
  111.         jr nvhexed_symbol_rightq
  112. nvhexed_symbol_right
  113.         xor (hl)
  114.         and #0f
  115.         xor (hl)
  116. nvhexed_symbol_rightq
  117.         ld (hl),a
  118.         ld hl,nvhexed_half
  119.         ld a,(hl)
  120.         xor #80
  121.         ld (hl),a
  122.         call nvhex_calccuraddrline ;addr cur line
  123.         ld de,(hexcuraddrxy)
  124.         ld e,0
  125.         call nv_setxy
  126.         call nvview_hexeditor_prline
  127.         ret
  128. ;--------
  129.         ;ld a,(fcb+FCB_FSIZE)
  130.         ;dec a   ;a=????xxxx  l=XXXXzzzz
  131.         ;;xor l   ;a=????xzxz  l=XXXXzzzz
  132.         ;and #0f ;a=0000xzxz  l=XXXXzzzz
  133.         ;;xor l   ;a=XXXXxxxx  l=XXXXzzzz
  134.         ;;ld l,a
  135.         ;ld e,a
  136.        
  137. ;--------
  138.        
  139.        
  140. nvview_hexeditor_save
  141.         ;call getfcbundercursor ;->fcb
  142.         ld hl,fcb_filename
  143.         ld de,fcb2_filename
  144.         call copy_to_defcb_filename
  145.         ;call setcurpaneldir
  146.         call nv_createfcb2 ;autopush nv_closefcb2
  147.         ret nz ;error
  148.         ld de,(fcb+FCB_FSIZE)
  149.         ld hl,(fcb+FCB_FSIZE+2)
  150.         ld a,0 ;page number
  151. nvview_hexeditor_save0
  152. ;a=page number in table (0..)
  153. ;hlde=remaining size
  154.         push af
  155.         push de
  156.         push hl
  157.         call setpg32k
  158.         ld a,d
  159.         and #c0
  160.         or h
  161.         or l
  162.         jr z,$+5 ;de=size
  163.         ld de,#4000
  164.         ex de,hl ;hl=pg size
  165.         push hl ;hl=pg size
  166.         call cmd_savepage
  167.         pop bc ;bc=pg size
  168.         pop hl
  169.         pop de
  170.         ex de,hl
  171.         or a
  172.         sbc hl,bc
  173.         ex de,hl
  174.         jr nc,$+3
  175.         dec hl ;size = size-pgsize
  176.         ld a,h
  177.         or l
  178.         or d
  179.         or e
  180.         jr z,nvview_hexeditor_save_popq
  181.         pop af
  182.         inc a
  183.         jr nvview_hexeditor_save0
  184. nvview_hexeditor_save_popq
  185.         pop af
  186.         ret
  187.        
  188. nvview_hexeditor_left
  189.         ld de,(hexcuraddrxy)
  190.         ld a,e
  191.         cp 0
  192.         ret z
  193.         dec e
  194.         ld (hexcuraddrxy),de
  195.         ret
  196.        
  197. nvview_hexeditor_right
  198.         ld de,(hexcuraddrxy)
  199.         ld a,e
  200.         cp NVVIEW_HEXEDITOR_MAXX
  201.         ret z
  202.         inc e
  203.         push de
  204.         call nvhex_calccuraddrline ;ahl=lineaddr
  205.         pop de
  206.         push af
  207.         ld a,e
  208.         add a,l
  209.         ld l,a
  210.         pop af
  211.         call iseof
  212.         ret nc
  213.         ld (hexcuraddrxy),de
  214.         ret
  215.        
  216. nvhexed_calccursorxy
  217.         ld de,(hexcuraddrxy)
  218.         ld a,e
  219.         add a,a
  220.         add a,e
  221.         add a,8
  222.         ld e,a
  223.         ret
  224.        
  225. nvview_hexeditor_panel
  226.         ret
  227.        
  228. nvview_hexeditor_prpage
  229.         ld hl,(hexaddrline)
  230.         ld a,(hexaddrlineHSB)
  231.         ld de,NVVIEW_HEXEDITOR_XYTOP
  232.         ld b,NVVIEW_HEXEDITOR_HGT
  233. nvview_hexeditor_prpage0
  234.         push bc
  235.         push de
  236.         push af
  237.         push hl
  238.         OS_SETXY
  239.         pop hl
  240.         pop af
  241.         call nvview_hexeditor_prline
  242.         pop de
  243.         pop bc
  244.         inc d
  245.         djnz nvview_hexeditor_prpage0
  246. ;nvview_hexeditor_setbottom
  247.         ;ld (hexaddrline),hl
  248.         ;ld (hexaddrlineHSB),a
  249.         ret
  250.        
  251.  
  252. nvview_hexeditor_prline
  253. ;ahl =  addr line      
  254.         ;jr $
  255.         push hl
  256.         push af
  257.        
  258.         push hl
  259.         call getmaxlinesize ;bc=max line size before eof, z=(bc==0)
  260.         ld hl,16
  261.         call minhl_bc_tobc ;bc = min(16, max line size before eof)
  262.         pop hl
  263.                  
  264.         push bc
  265.         call nvview_hexeditor_praddrline
  266.         call ahl_to_pgaddr
  267.        
  268.         push hl
  269.         ld a,':'
  270.         PRCHAR
  271.         pop hl
  272.        
  273.         pop bc;ld b,0
  274.        
  275.         push hl
  276. nvview_hexeditor1        
  277.         ld a,b
  278.         cp 8
  279.         ld a,' '
  280.         jr nz,nvview_hexeditor0
  281.         ld a,'|'
  282. nvview_hexeditor0
  283.         push hl
  284.         push bc
  285.         PRCHAR
  286.         pop bc
  287.         pop hl
  288.        
  289.         ld a,b
  290.         cp c
  291.         jr c,nvview_hexeditor_prhex
  292.         push bc
  293.         ld b,2
  294.         call nvview_prlinespc_b
  295.         pop bc
  296.         jr nvview_hexeditor_notprhex
  297. nvview_hexeditor_prhex        
  298.         ld a,(hl)
  299.         push bc
  300.         call nvview_hexeditor_prNN
  301.         pop bc
  302. nvview_hexeditor_notprhex
  303.         inc hl
  304.         inc b
  305.         ld a,b
  306.         cp 16
  307.         jr nz,nvview_hexeditor1        
  308.         pop hl
  309.        
  310.         ld b,2
  311.         call nvview_prlinespc_b
  312.        
  313.         ld b,0
  314. nvview_hexeditor2      
  315.         ld a,b
  316.         cp c
  317.         ld a,' '
  318.         jr nc,nvview_hexeditor2_sym  
  319. nvview_hexeditor2_prtext        
  320.         ld a,(hl)
  321.         cp 32
  322.         jr nc,nvview_hexeditor2_sym
  323.         ld a,'.'
  324. nvview_hexeditor2_sym        
  325.         push hl
  326.         push bc
  327.         PRCHAR
  328.         pop bc
  329.         pop hl
  330.         inc hl
  331.         inc b
  332.         ld a,b
  333.         cp 16
  334.         jr nz,nvview_hexeditor2        
  335.         pop af
  336.         pop hl
  337.         ld b,0
  338.         add hl,bc
  339.         adc a,b
  340.  
  341.         ld b,7
  342.         call nvview_prlinespc_b
  343.         ret        
  344.  
  345. nvview_hexeditor_prNN
  346.         push af
  347.         push hl
  348.         call nvview_prhexbyte
  349.         pop hl
  350.         pop af
  351.         ret
  352.        
  353. nvview_hexeditor_praddrline
  354. ;ahl = addr line
  355.         push af
  356.         call nvview_hexeditor_prNN
  357.         ld a,h
  358.         call nvview_hexeditor_prNN      
  359.         ld a,l        
  360.         call nvview_hexeditor_prNN
  361.         pop af
  362.         ret
  363.        
  364. nvview_prhexbyte
  365. ;ld a,#30;a=#30 - 0,1,2..9 #41 - A,B,C,D,E,F #61 - a,b,c..
  366. ;a=XX
  367.         ;push hl
  368.         ;push af
  369.         rrca
  370.         rrca
  371.         rrca
  372.         rrca
  373.         call pronehexdigit
  374.         rlca
  375.         rlca
  376.         rlca
  377.         rlca
  378.         ;call pronehexdigit
  379.         ;pop af
  380.         ;pop hl
  381.         ;ret
  382. pronehexdigit
  383. ;a=?X
  384.         push bc
  385.         push af
  386.         and #f
  387.         cp 10
  388.         jr c,prcharbit_noletter
  389.         add a,'a'-('0'+10)
  390. prcharbit_noletter
  391.         add a,'0'
  392.         PRCHAR
  393.         pop af
  394.         pop bc
  395.         ret
  396.  
  397. nvview_hexeditor_prevline
  398. ;ahl =addr line  
  399. ;out: ahl =addr line, nc=error      
  400.         call isbof ;cy=0
  401.         ret z
  402.         push bc
  403.         ld bc,#0010
  404.         or a
  405.         sbc hl,bc
  406.         sbc a,b
  407.         scf
  408.         pop bc
  409.         ret ;c        
  410.        
  411. nvview_hexeditor_nextline
  412.         call iseof
  413.         ret nc
  414.         push bc
  415.         ld bc,#0010
  416.         add hl,bc
  417.         adc a,b
  418.         pop bc
  419.         ret        
  420.                
  421.  
  422. nvview_hexeditor_up
  423.         call nvhex_calccuraddrline
  424.         call nvview_hexeditor_prevline
  425.         ret nc
  426.         ld de,(hexcuraddrxy)
  427.         ld a,d
  428.         or a
  429.         jp z,nvview_hexeditor_up_scroll
  430.         dec d
  431.         ld (hexcuraddrxy),de
  432.         ret
  433. nvview_hexeditor_up_scroll        
  434.         ld de,NVVIEW_HEXEDITOR_XYTOP
  435.         ld hl,256*NVVIEW_HEXEDITOR_HGT + NVVIEW_HEXEDITOR_WID
  436.         OS_SCROLLDOWN
  437.         ld de,NVVIEW_HEXEDITOR_XYTOP
  438.         OS_SETXY
  439.         ld hl,(hexaddrline)
  440.         ld a,(hexaddrlineHSB)
  441.         call nvview_hexeditor_prevline
  442.         ld (hexaddrline),hl
  443.         ld (hexaddrlineHSB),a
  444.        
  445.         call nvview_hexeditor_prline
  446.         ;call nvview_prline
  447.         ;call deccurline
  448.         ;ld hl,(curbottomtextaddrhex)
  449.         ;ld a,(curbottomtextHSBhex)
  450.         ;call nvview_prevline
  451.         ;jp nvview_hexeditor_setbottom
  452.         ret
  453.        
  454. nvview_hexeditor_pgdown
  455.         call nvhex_calccuraddrline
  456.         ld de,(hexcuraddrxy)
  457.         ld c,a
  458.         ld a,d
  459.         cp NVVIEW_HEXEDITOR_HGT-1
  460.         ld a,c
  461.         jp z,nvview_hexeditor_pgdown_do
  462. nvview_hexeditor_pgdown0
  463.         ld c,a
  464.         ld a,d
  465.         cp NVVIEW_HEXEDITOR_HGT-1
  466.         ld a,c
  467.         jp z,nvview_hexeditor_pgdownq
  468.         call nvhex_calcnextcorrectxy
  469.         jp c,nvview_hexeditor_pgdown0
  470. nvview_hexeditor_pgdownq
  471.         ld (hexcuraddrxy),de
  472.         ret
  473. nvview_hexeditor_pgdown_do
  474.         ld (hexaddrline),hl
  475.         ld (hexaddrlineHSB),a
  476.         push de
  477.         call nvview_hexeditor_prpage
  478.         pop de
  479.         ld hl,(hexaddrline)
  480.         ld a,(hexaddrlineHSB)
  481.         ld d,0
  482. nvview_hexeditor_pgdown_do0
  483.         ld c,a
  484.         ld a,d
  485.         cp NVVIEW_HEXEDITOR_HGT-1
  486.         ld a,c
  487.         jp z,nvview_hexeditor_pgdown_doq
  488.         call nvhex_calcnextcorrectxy
  489.         jp c,nvview_hexeditor_pgdown_do0
  490. nvview_hexeditor_pgdown_doq
  491.         ld (hexcuraddrxy),de
  492.         jp clear_keyboardbuffer
  493.  
  494. nvview_hexeditor_pgup
  495.         call nvhex_calccuraddrline
  496.         ld de,(hexcuraddrxy)
  497.         ld c,a
  498.         ld a,d
  499.         or a
  500.         ld a,c
  501.         jp nz,nvview_hexeditor_pgupq
  502.         ld b,NVVIEW_HEXEDITOR_HGT-1
  503. nvview_hexeditor_pgup0
  504.         push bc
  505.         call nvview_hexeditor_prevline
  506.         pop bc
  507.         djnz nvview_hexeditor_pgup0
  508.         ld (hexaddrline),hl
  509.         ld (hexaddrlineHSB),a
  510.         call nvview_hexeditor_prpage
  511.         jp clear_keyboardbuffer
  512. nvview_hexeditor_pgupq
  513.         ld d,0
  514.         ld (hexcuraddrxy),de
  515.         ret
  516.        
  517.        
  518.        
  519. nvview_hexeditor_down
  520.         call nvhex_calccuraddrline
  521.         ld de,(hexcuraddrxy)
  522.         call nvhex_calcnextcorrectxy
  523.         ret nc
  524.         ld c,a
  525.         ld a,d
  526.         cp NVVIEW_HEXEDITOR_HGT
  527.         ld a,c
  528.         jr z,nvview_hexeditor_down_scroll
  529.         ld (hexcuraddrxy),de
  530.         ret
  531. nvview_hexeditor_down_scroll
  532.         ;ld hl,(hexaddrline)
  533.         ;ld a,(hexaddrlineHSB)
  534.         ;ld bc,NVVIEW_HEXEDITOR_PAGESIZE
  535.         ;add hl,bc
  536.         ;adc a,0
  537.         push af
  538.         push hl
  539.         ld a,e
  540.         ld (hexcuraddrx),a
  541.         ld de,NVVIEW_HEXEDITOR_XYTOP
  542.         ld hl,256*NVVIEW_HEXEDITOR_HGT + NVVIEW_HEXEDITOR_WID
  543.         OS_SCROLLUP
  544.         ld de,NVVIEW_HEXEDITOR_XYTOP+((NVVIEW_HEXEDITOR_HGT-1)*256)
  545.         OS_SETXY
  546.         ld hl,(hexaddrline)
  547.         ld a,(hexaddrlineHSB)
  548.         ld bc,16
  549.         add hl,bc
  550.         ld (hexaddrline),hl
  551.         ld (hexaddrlineHSB),a
  552.         pop hl
  553.         pop af
  554.         jp nvview_hexeditor_prline
  555.        
  556. nvhex_calccuraddrline
  557. ;out: ahl = addr cur line
  558.         ld hl,(hexaddrline)
  559.         ld a,(hexaddrlineHSB)
  560.         ld de,(hexcuraddrxy)
  561.         ld e,0
  562.         srl d
  563.         rr e
  564.         srl d
  565.         rr e
  566.         srl d
  567.         rr e
  568.         srl d
  569.         rr e
  570.         add hl,de       ;hl+d*16
  571.         adc a,0
  572.         ret
  573.  
  574. nvhex_calcnextcorrectxy
  575. ;ahl=line addr, de=yx
  576. ;out:ahl=line addr, de=yx, NC=error
  577.         ld bc,16
  578.         add hl,bc
  579.         adc a,b
  580.         call iseof
  581.         jr nc,nvhex_calcnextcorrectxy_error
  582.         inc d
  583.         ld c,e
  584.         ld b,0
  585.         push hl
  586.         add hl,bc
  587.         call iseof
  588.         pop hl
  589.         ret c
  590.         push af
  591.         ld a,(fcb+FCB_FSIZE)
  592.         dec a   ;a=????xxxx  l=XXXXzzzz
  593.         ;xor l   ;a=????xzxz  l=XXXXzzzz
  594.         and #0f ;a=0000xzxz  l=XXXXzzzz
  595.         ;xor l   ;a=XXXXxxxx  l=XXXXzzzz
  596.         ;ld l,a
  597.         ld e,a
  598.         pop af
  599.         scf
  600.         ret ;c
  601. nvhex_calcnextcorrectxy_error
  602.         call nvview_hexeditor_prevline
  603.         or a
  604.         ret ;nc
  605.        
  606. hexcuraddrxy
  607. hexcuraddrx
  608.         db 0
  609. hexcuraddry
  610.         db 0
  611.  
  612. hexaddrline
  613.         dw 0
  614. hexaddrlineHSB
  615.         db 0
  616.