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


