Quickie knocked up a rough little sample, but should be enough to give the idea.
It will load the sample hex file into a linked list which is then displayed using a combo gadget to display list data in decimal, hex & 8 bit binary numbers. You can then edit the list & if you want save it back to a new file.
Code: Select all
Enumeration
#Window_0
#Combo_0
#Text_Dec
#Text_Hex
#Text_Bin
#Button_Edit
#Text_3
#Text_4
#Text_5
#Button_Save
;
#Window_1
#Text_1_1
#Text_1_loc
#Text_1_2
#String_1_Val
#Button_1_OK
#Button_1_Cancel
EndEnumeration
Global NewList eepromDat.a() ; make global so can be used between procedures easily
; cast list as type unsigned ascii to make life easier when dealing with 8 bit eeprom data
Procedure SetStatus(status)
SelectElement(eepromDat(),status)
SetGadgetState(#Combo_0,status)
SetGadgetText(#Text_Dec,RSet(Str(eepromDat()),3,"0"))
SetGadgetText(#Text_Hex,RSet(Hex(eepromDat()),2,"0"))
SetGadgetText(#Text_Bin,RSet(Bin(eepromDat()),8,"0"))
EndProcedure
Procedure loadF()
file$ = OpenFileRequester("Please choose file...","","*.bin | *.bin", 0)
If file$<>""
fileNum = ReadFile(#PB_Any, file$)
If fileNum
ClearList(eepromDat()) ; make sure list is empty
While Not Eof(fileNum)
AddElement(eepromDat()) ; add elements
eepromDat()=ReadByte(fileNum) ; place data from file into list
Wend
CloseFile(fileNum)
SelectElement(eepromDat(),0) ; set to 1st element
ProcedureReturn 1
EndIf
EndIf
EndProcedure
Procedure SaveF()
File$=SaveFileRequester("Save File","","*.bin | *.bin",0)
If File$<>""
overwrite=#PB_MessageRequester_Yes
filenum=ReadFile(#PB_Any,File$)
If filenum
CloseFile(filenum)
overwrite=MessageRequester("File already exists","Overwrite file?",#PB_MessageRequester_YesNo)
EndIf
file$=RemoveString(file$,GetExtensionPart(file$))
file$=RemoveString(file$,".")
File$=GetPathPart(File$)+GetFilePart(File$)+".bin"
If overwrite=#PB_MessageRequester_Yes
newfile=CreateFile(#PB_Any,File$)
If newfile
size=ListSize(eepromDat())
FirstElement(eepromDat())
While a<size
WriteByte(newfile,eepromDat())
NextElement(eepromDat())
a+1
Wend
CloseFile(newfile)
EndIf
EndIf
If overwrite=#PB_MessageRequester_No
SaveF()
EndIf
EndIf
EndProcedure
Procedure ProcessUpdate()
NewVal=Val(GetGadgetText(#String_1_Val))
position=Val(GetGadgetText(#Text_1_Loc))
If NewVal<256
SelectElement(eepromDat(),position)
eepromDat()=NewVal
SetStatus(position)
CloseWindow(#Window_1)
DisableWindow(#Window_0,0)
ProcedureReturn 1
EndIf
EndProcedure
Procedure Open_Window_1(position)
If OpenWindow(#Window_1,216,0,150,90,"Edit",#PB_Window_SystemMenu,WindowID(#Window_0))
TextGadget(#Text_1_1,20,10,50,20,"Location")
TextGadget(#Text_1_Loc,20,30,50,20,Str(position),#PB_Text_Border)
TextGadget(#Text_1_2,90,10,50,20,"Value")
SelectElement(eepromDat(),position)
StringGadget(#String_1_Val,90,30,50,20,Str(eepromDat()),#PB_String_Numeric)
ButtonGadget(#Button_1_OK,20,60,50,20,"OK")
ButtonGadget(#Button_1_Cancel,80,60,50,20,"Cancel")
ProcedureReturn 1
EndIf
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Window_0, 216, 0, 550, 75, "New window ( 0 )", #PB_Window_SystemMenu | #PB_Window_TitleBar )
ComboBoxGadget(#Combo_0, 20, 30, 80, 20)
TextGadget(#Text_Dec, 110, 30, 60, 20, "", #PB_Text_Border)
TextGadget(#Text_Hex, 180, 30, 60, 20, "", #PB_Text_Border)
TextGadget(#Text_Bin, 250, 30, 100, 20, "", #PB_Text_Border)
ButtonGadget(#Button_Edit, 360, 30, 80, 20, "Edit")
TextGadget(#Text_3, 110, 10, 60, 20, "Dec", #PB_Text_Center)
TextGadget(#Text_4, 180, 10, 60, 20, "Hex", #PB_Text_Center)
TextGadget(#Text_5, 250, 10, 100, 20, "Bin", #PB_Text_Center)
ButtonGadget(#Button_Save, 450, 30, 80, 20, "Save")
ProcedureReturn 1
EndIf
EndProcedure
If Not loadF()
MessageRequester("Fault","no file loaded")
End
EndIf
If Not Open_Window_0()
MessageRequester("Fault","Main window initialisation fail")
End
Else
a=0
While a<ListSize(eepromDat())
AddGadgetItem(#Combo_0,-1,Str(a))
a+1
Wend
SetGadgetState(#Combo_0,0) ; set the gadgets with data to start up
SetStatus(0)
SetActiveGadget(#Combo_0)
EndIf
Repeat
Ev=WaitWindowEvent(1)
If Ev=#PB_Event_Gadget
Select EventGadget()
Case #Button_Edit
If Open_Window_1(GetGadgetState(#Combo_0))
DisableWindow(#Window_0,1)
EndIf
Case #Combo_0
SetStatus(GetGadgetState(#Combo_0))
Case #Button_Save
SaveF()
Case #Button_1_OK
If Not ProcessUpdate()
MessageRequester("Error","Value out of range, please use a different value")
EndIf
Case #Button_1_Cancel
CloseWindow(#Window_1)
DisableWindow(#Window_0,0)
EndSelect
EndIf
If Ev=#PB_Event_CloseWindow
Select EventWindow()
Case #Window_0
quit=1
Case #Window_1
CloseWindow(#Window_1)
DisableWindow(#Window_0,0)
EndSelect
EndIf
Until quit