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

Hex viewer (iPad, quick & dirty)

Post 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 4290 times

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Hex viewer (iPad, quick & dirty)

Post by rbytes »

Nice job! I hope you will continue to upgrade it.

I will even indent your code for free! :lol:
The only thing that gets me down is gravity...

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 »

: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


User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Hex viewer (iPad, quick & dirty)

Post 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.
The only thing that gets me down is gravity...

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 »

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)

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Hex viewer (iPad, quick & dirty)

Post by rbytes »

What happened to your hand? :roll:
The only thing that gets me down is gravity...

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 »

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.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Hex viewer (iPad, quick & dirty)

Post by rbytes »

Good to hear that you will be back soon. I enjoy your posts, and learn a lot from them.
The only thing that gets me down is gravity...

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Hex viewer (iPad, quick & dirty)

Post 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...
Attachments
image.jpg
image.jpg (154.18 KiB) Viewed 4262 times

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Hex viewer (iPad, quick & dirty)

Post 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 :!:

Post Reply