Hexmonitor-my first cellular basic prog

20 views
Skip to first unread message

01746...@vodafone.de

unread,
Oct 9, 2011, 12:35:22 PM10/9/11
to CellularBasicPro
From time to time i need to modificate certain files on my phone (the
settings.bin for example), but i found no Hexmonitor Midlet, therefore
i write a short basic prog to mod small files (<255 bytes):

SUB main
file$="Media/bas/settings.bin"
f$=readfile(file$)
print "*** cmg's Hexmonitor ***"
delay(1000)
call dispfile
REM ####Wait for keyboard
cur=1 :curold=1 :yl=0
WHILE key<>55 and key<>57
key=getkey :delay(200)
if key>49 and key<57 then
color(0,0,0) :call cursor
if key=52 then cur=cur-1:end if
if key=54 then cur=cur+1:end if
if key=53 then
print "Input Hex";:input h$
call hex2dez
f$=left$(f$,cur-1)+chr$(d)+right$(f$,len(f$)-cur)
call dispfile
end if
if key=50 then cur=cur-8:end if
if key=56 then cur=cur+8:end if
end if
color(0,255,0) :call cursor
WEND
print key,"End program"
if key=57 then :file$=file$+"b"
writefile(f$,file$)
print "new file saved"
end if
END SUB

SUB waitkey
outtext(0,180,"press key 1")
updatescreen
while key<>49 :key=getkey :wend
color(0,0,0)
outtext(0,180,"press key 1")
updatescreen :color(0,255,0)
END SUB

SUB dispfile
REM ####Print file to screen
clearcolor(0,0,0):cls
color(0,255,0) :setsmallfont
xc=28 :yl=0 :xca=128
offset$="" :lowb=0
FOR i=1 TO len(f$)
d=lowb :call dez2hex
offset$="00"+h$+":"
outtext (0,yl,offset$)
d=asc(mid$(f$,i,1)) :call dez2hex
outtext (xc,yl,h$)
outtext (xca,yl,chr$(d))
xc=xc+12 :xca=xca+6
if xc>120 then :lowb=lowb+8
outtext (124,yl,"$") :updatescreen
xc=28 :xca=128 :yl=yl+8
end if
NEXT i
call waitkey
outtext(0,180,"4=<-,6=->,5=ent,2=up,8=down,7=esc,9=esc+save")
END SUB

SUB cursor
if cur>0 and cur<len(f$) then
curx=cur-8*(int((cur-1)/8))
xc=curx*12+12
yl=8*(int((cur-1)/8))
outtext(xc,yl,"_"):updatescreen
end if
END SUB

SUB dez2hex
s=16 :x=2 :h$=""
WHILE s<d :x=x+1 :s=s*16
WEND
t=d
FOR l=x TO 1 STEP -1
n=INT(t/s) :f=0
IF n>9 THEN f=1 :END IF
h$=h$+CHR$(48+n+7*f)
t=t-n*s :s=s/16
NEXT l
if len(h$)=3 then h$=right$(h$,2)
end if
END SUB

SUB hex2dez
d=0 :s=1 :rem position multipler
FOR l=len(h$) TO 1 STEP -1
a$=mid$(h$,l,1)
rem convert "0"-"F" to 0-15
n=asc(a$)-48
if n>9 then n=n-7 :end if
d=d+n*s :s=s*16
NEXT l
print "Hex ";h$;" = Dec ";d
delay(1000)
END SUB


Reply all
Reply to author
Forward
0 new messages