Page 1 of 2

Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 6:28 pm
by Henko
I needed to have a look into a .WAV file.
This is a usable hex viewer. Maybe i upgrade it later on to a better program, nice look, and give it a hex editor function.
Or maybe someone else takes on that job.

Code: Select all

graphics ! graphics clear .8,.8,.8 ! refresh off
fill color .8,.8,.8 ! draw color 0,0,0
dim hex$(16),asci$(16)
f$="explosion.wav"
button "nxt" text "next" at 30,5 size 120,30
button "bck" text "back" at 180,5 size 120,30
button "adr" text "adress" at 330,5 size 120,30
field "adress" text "0" at 480,5 size 120,30 ! field "adress" hide
fpointer=0 ! draw font size 16
x1=10 ! x2=x1+80 ! x3=x1+560 ! x4=x3+20 
maxlin=30 ! y1=50 ! y2=75 ! dy=20
draw text "Adress" at x1,y1
draw text " 0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F" at x2,y1
draw text "0123456789ABCDEF" at x4,y1
new_page:
  fill rect x1,y2 to x4+160,y2+dy*maxlin
  lin=1 ! yl=y2 ! file f$ setpos fpointer
new_line:
  for i=0 to 15
    file f$ read byt ! if byt=-1 then end_fil
    hex$(i)=n2hex$(byt) ! asci$(i)=chr$(byt)
    next i
  draw text pad$(fpointer)&"  " at x1,yl
  for i=0 to 15 ! draw text hex$(i) at x2+30*i,yl ! next i
  draw text "|"&" " at x3,yl
  for i=0 to 15 ! draw text asci$(i) at x4+10*i,yl ! next i
  yl+=dy ! lin+=1 ! fpointer+=16
  if lin <= maxlin then new_line
  refresh
poll: slowdown
  if button_pressed("nxt") then new_page
  if button_pressed("bck") then
    fpointer-=60*16 ! goto new_page
    end if
  if button_pressed("adr") then
    field "adress" show
    wait: if not field_changed("adress") then wait
    fpointer=val(field_text$("adress"))
    field("adress") hide
    goto new_page
    end if 
  goto poll
end_fil:
end

def pad$(adr)
a$="" ! siz=6
if adr=0 then n=0 else n=floor(log10(adr))
if n<siz then
  for i=1 to siz-n-1 ! a$ &= " " ! next i
  end if
a$ &= str$(adr)
return a$
end def

def n2hex$(num)
a=floor(num/16) ! b=num-16*a
if a<10 then a$=str$(a) else a$=chr$(a+55)
if b<10 then b$=str$(b) else b$=chr$(b+55)
return a$&b$
end def
IMG_1309.PNG
IMG_1309.PNG (403.94 KiB) Viewed 4284 times

Re: Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 7:01 pm
by rbytes
Nice job! I hope you will continue to upgrade it.

I will even indent your code for free! :lol:

Re: Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 7:19 pm
by Henko
:D
Same program, but negative filepointers are excluded.

Code: Select all

graphics ! graphics clear .8,.8,.8 ! refresh off
fill color .8,.8,.8 ! draw color 0,0,0
dim hex$(16),asci$(16)
f$="explosion.wav"
button "nxt" text "next" at 30,5 size 120,30
button "bck" text "back" at 180,5 size 120,30
button "adr" text "adress" at 330,5 size 120,30
field "adress" text "0" at 480,5 size 120,30 ! field "adress" hide
fpointer=0 ! draw font size 16
x1=10 ! x2=x1+80 ! x3=x1+560 ! x4=x3+20 
maxlin=30 ! y1=50 ! y2=75 ! dy=20
draw text "Adress" at x1,y1
draw text " 0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F" at x2,y1
draw text "0123456789ABCDEF" at x4,y1
new_page:
  fill rect x1,y2 to x4+160,y2+dy*maxlin
  lin=1 ! yl=y2 ! file f$ setpos fpointer
new_line:
  for i=0 to 15
    file f$ read byt ! if byt=-1 then end_fil
    hex$(i)=n2hex$(byt) ! asci$(i)=chr$(byt)
    next i
  draw text pad$(fpointer)&"  " at x1,yl
  for i=0 to 15 ! draw text hex$(i) at x2+30*i,yl ! next i
  draw text "|"&" " at x3,yl
  for i=0 to 15 ! draw text asci$(i) at x4+10*i,yl ! next i
  yl+=dy ! lin+=1 ! fpointer+=16
  if lin <= maxlin then new_line
  refresh
poll: slowdown
  if button_pressed("nxt") then new_page
  if button_pressed("bck") then
    fpointer-=60*16 ! fpointer=max(0,fpointer) ! goto new_page
    end if
  if button_pressed("adr") then
    field "adress" show
    wait: if not field_changed("adress") then wait
    fpointer=max(0,(val(field_text$("adress"))))
    field("adress") hide
    goto new_page
    end if 
  goto poll
end_fil:
end

def pad$(adr)
a$="" ! siz=6
if adr=0 then n=0 else n=floor(log10(adr))
if n<siz then
  for i=1 to siz-n-1 ! a$ &= " " ! next i
  end if
a$ &= str$(adr)
return a$
end def

def n2hex$(num)
a=floor(num/16) ! b=num-16*a
if a<10 then a$=str$(a) else a$=chr$(a+55)
if b<10 then b$=str$(b) else b$=chr$(b+55)
return a$&b$
end def


Re: Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 7:41 pm
by rbytes
Good change. I had added code to keep the fpointer from going negative.

For the next button - if you press it too many times when scanning hex, the program quits.
I see why - in the newline code

new_line:
for i=0 to 15
file f$ read byt ! if byt=-1 then end_fil
hex$(i)=n2hex$(byt) ! asci$(i)=chr$(byt)
next i

I changed end_file to poll, and now pressing Next beyond the end of file does nothing, and the program continues to respond OK. You may have a better fix.

Re: Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 8:16 pm
by Henko
nice fix for the EOF.
I don't think i'll spend more time on this prog. It does what i need.
Anyhow, i can't do much coding coming weeks, as my right hand will be operated (Dupuytren)

Re: Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 8:36 pm
by rbytes
What happened to your hand? :roll:

Re: Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 9:16 pm
by Henko
I have the Dupuytren disease (google) in both hands, currently only in the right hand. It returnes every 5 to 8 years. It's not dangerous, only a nuisance. Especially with the right hand, where the "programming" fingers reside :lol:
In a few weeks i can hit the tablet again.

Re: Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 9:32 pm
by rbytes
Good to hear that you will be back soon. I enjoy your posts, and learn a lot from them.

Re: Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 9:34 pm
by Operator
Many Thx for sharing :D and making it
easy to adapt for tiny iPhone4 screen...
Good luck with your hand ... hoping to
see some more expert code soon...

Re: Hex viewer (iPad, quick & dirty)

Posted: Thu Nov 24, 2016 9:50 pm
by Mr. Kibernetik
Henko wrote:I have the Dupuytren disease (google) in both hands, currently only in the right hand. It returnes every 5 to 8 years. It's not dangerous, only a nuisance. Especially with the right hand, where the "programming" fingers reside :lol:
In a few weeks i can hit the tablet again.
Wish you to get cured :!: