; ID: 1751 ; Author: markcw ; Date: 2006-07-12 03:03:20 ; Title: Memory Access functions ; Description: Uses Kernel32.dll decls ;Memory access functions, on 21/7/06 Function PeekByteMem(pbank,address) ;pbank=bank handle, address=memory address ;restoring old value lets you use any bank Local old,value old=PeekByte(pbank,0) Api_RtlMoveMemory(pbank,address,1) ;move memory to bank value=PeekByte(pbank,0) PokeByte pbank,0,old Return value End Function Function PeekShortMem(pbank,address) Local old,value old=PeekShort(pbank,0) Api_RtlMoveMemory(pbank,address,2) value=PeekShort(pbank,0) PokeShort pbank,0,old Return value End Function Function PeekIntMem(pbank,address) Local old,value old=PeekInt(pbank,0) Api_RtlMoveMemory(pbank,address,4) value=PeekInt(pbank,0) PokeInt pbank,0,old Return value End Function Function PeekFloatMem#(pbank,address) Local old,value# old=PeekInt(pbank,0) Api_RtlMoveMemory(pbank,address,4) value#=PeekFloat(pbank,0) PokeInt pbank,0,old Return value# End Function Function PokeByteMem(pbank,address,value) ;pbank=bank handle, address=memory address, value=value ;restoring old value lets you use any bank Local old old=PeekByte(pbank,0) PokeByte pbank,0,value Api_RtlCopyMemory(address,pbank,1) ;copy bank to memory PokeByte pbank,0,old End Function Function PokeShortMem(pbank,address,value) Local old old=PeekShort(pbank,0) PokeShort pbank,0,value Api_RtlCopyMemory(address,pbank,2) PokeShort pbank,0,old End Function Function PokeIntMem(pbank,address,value) Local old old=PeekInt(pbank,0) PokeInt pbank,0,value Api_RtlCopyMemory(address,pbank,4) PokeInt pbank,0,old End Function Function PokeFloatMem(pbank,address,value#) Local old old=PeekInt(pbank,0) PokeFloat pbank,0,value# Api_RtlCopyMemory(address,pbank,4) PokeInt pbank,0,old End Function ;Write memory file functions Function WriteMemoryFile(pbank,address,bytelen,filename$) ;pbank=bank handle for memory access, address=start address ;bytelen=length in bytes, filename$=filename Local file,i,error,value,j,array$ file=WriteFile(filename$) For i=1 To bytelen/4 ;write address line error=0 ;reset If address>=0 And address<65536 Then error=1 ;nb: simple error check WriteValueAsc(file,address) : WriteByte(file,32) ;"address " WriteByte(file,123) : WriteByte(file,32) ;"{ " If error=0 ;address in range value=PeekIntMem(pbank,address) WriteValueAsc(file,value) : WriteByte(file,32) ;"integer " WriteByte(file,58) : WriteByte(file,32) ;": " For j=0 To 3 Step 2 ;2 shorts value=PeekShortMem(pbank,address+j) WriteValueAsc(file,value) ;"short" If j=0 Then WriteByte(file,44) ;"," If j=2 Then WriteByte(file,32) ;" " if last Next WriteByte(file,58) : WriteByte(file,32) ;": " For j=0 To 3 ;4 bytes value=PeekByteMem(pbank,address+j) WriteValueAsc(file,value) ;"byte" If j<3 Then WriteByte(file,44) ;"," If j=3 Then WriteByte(file,32) ;" " if last Next WriteByte(file,58) : WriteByte(file,32) ;": " For j=0 To 3 ;4 chars value=PeekByteMem(pbank,address+j) WriteByte(file,value) ;"char" Next WriteByte(file,32) : WriteByte(file,58) ;" :" array$=Str(PeekFloatMem(pbank,address)) WriteByte(file,32) : WriteStringAsc(file,array$) ;" float" EndIf WriteByte(file,32) : WriteByte(file,125) ;" }" WriteNewLineAsc(file) ;"eol" address=address+4 ;next integer Next array$="address { integer : short : byte : char : float }" WriteStringAsc(file,array$) ;"info" WriteNewLineAsc(file) ;"eol" CloseFile(file) ;free from memory End Function Function WriteValueAsc(file,value) ;file=file handle, value=byte, short or integer Local array$,i,char$ array$=Str(value) For i=1 To Len(array$) char$=Mid(array$,i,1) WriteByte(file,Asc(char$)) Next End Function Function WriteStringAsc(file,array$) ;file=file handle, array$=string Local i,char$ For i=1 To Len(array$) char$=Mid(array$,i,1) WriteByte(file,Asc(char$)) Next End Function Function WriteNewLineAsc(file) ;file=file handle WriteByte(file,13) ;carriage return WriteByte(file,10) ;line feed End Function