Hex viewer (iPad, quick & dirty)

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Hex viewer (iPad, quick & dirty)

Post by Henko »

Thank you all, it's no big thing, i have been there three times before :mrgreen:

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Hex viewer (iPad, quick & dirty)

Post by Henko »

Last update: small files (less than 480 bytes) are displayed correctly.

Code: Select all

graphics ! graphics clear .8,.8,.8 ! refresh off
fill color .8,.8,.8 ! draw color 0,0,0
f$="spironum"
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:
  draw text pad$(fpointer)&"  " at x1,yl
  draw text "|"&" " at x3,yl
  for i=0 to 15
    file f$ read byt ! if byt=-1 then ! refresh ! goto poll ! end if
    draw text n2hex$(byt) at x2+30*i,yl
    draw text chr$(byt) 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

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Hex viewer (iPad, quick & dirty)

Post by Henko »

A little modification: upon starting this util, a filename can be entered. If an empty input is returned, the default filename as stated in the start of the code is taken. This is handy when using the tool intensively on the same file. Also a little bug is corrected.

Code: Select all

' hex_viewer version 16-01-2017
' utility to view contents of any type of file
' by Henko
'
f_def$="temp.jpg"     '  default filename
maxlin=30             ' # of lines per page
input "filename ?": f$ ! if f$="" then f$=f_def$
if not file_exists(f$) then ! print "filename?" ! stop ! end if
graphics ! graphics clear .8,.8,.8 ! refresh off
fill color .8,.8,.8 ! draw color 0,0,0
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 
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:
  draw text pad$(fpointer)&"  " at x1,yl
  draw text "|"&" " at x3,yl
  for i=0 to 15
    file f$ read byt ! if byt=-1 then ! refresh ! goto poll ! end if
    draw text n2hex$(byt) at x2+30*i,yl
    draw text chr$(byt) 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-=2*maxlin*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

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Hex viewer (iPad, quick & dirty)

Post by GeorgeMcGinn »

Hope everything went well with your operation. Wish mine were as minor. I'm looking at a right hip fusion after 3 back fusions failed. Now I fall more than ever, for no reason other than the operations screwed up my back and I have loss feeling in both legs.

Wish you well.

George.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Hex viewer (iPad, quick & dirty)

Post by Henko »

Yes, my right hand is 90% again. Also some loss of feeling, but neglible compared with your troubles. keep up the good spirit.

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Hex viewer (iPad, quick & dirty)

Post by GeorgeMcGinn »

Thanks. i will try. But sometimes walking is so difficult even with a walker I'm still a fall risk, and I fell down the side of a 30-foot swale just last Friday. I was not near the edge on the cart path. I heard the lawn crew's mower and turned to see were my service dog was and the next thing I know I'm at the bottom of the swale. My walker hit me twice on the way down.

Sounds funny now, but the three lawn workers didn't when they saw it hit me. One called 911.

First fall of the year. I had fallen 4 times last year and one required hospitalization as it involved a siezure. No cause found. My neurosurgeon thinks its the three screwed up back surgeries. But it can't be fixed. Something I must deal with.

I just don't want to have my hip fused and wind up in a wheelchair. I now have to weigh that fact in every discussion of surgery. I'll just keep falling until I break something :D

Thanks for your support. I can still code, still do research, and when I have the funds, lease time at observatories to do observational astronomy. Have to now. Light pollution is bad, and unless I build a mobile observatory/camper, leasing telescope time is my only way.

Thanks for your support.

George.

Henko wrote:
Mon Jan 16, 2017 9:18 pm
Yes, my right hand is 90% again. Also some loss of feeling, but neglible compared with your troubles. keep up the good spirit.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Hex viewer (iPad, quick & dirty)

Post by Dav »

Wow. I wish both of you better health for 2017. Hearing about those challenges makes me respect your coding & sharing them here with us even more.

- Dav

Post Reply