- 积分
- 14
- 实力分
- 点
- 金钱数
- 两
- 技术分
- 分
- 贡献分
- 分
|

楼主 |
发表于 2005-8-15 00:19:00
|
显示全部楼层
/*
Copyright (c) 2003 mamaich (mamaich@uymail.com)
.AUTHOR mamaich
.PACKAGE Extension
*/
package konGPS; // Konca Modified to "konGPS", org is "Extension"
import java.lang.Integer;
import com.siemens.mp.io.File;
import java.lang.String;
public class Extension
{
public Extension()
{
}
// Internal. Converts integer to a 6-digit hex string
private static String AddrToHex(int addr)
{
String ret=Integer.toHexString(addr);
while(ret.length()<6)
ret="0"+ret;
return ret;
}
// Internal. Converts integer to 4-digit hex string
private static String Int16ToHex(int val)
{
String ret=Integer.toHexString(val & 65535);
while(ret.length()<4)
ret="0"+ret;
return ret;
}
// Internal. Converts integer to 2-digit hex string
private static String Int8ToHex(int val)
{
String ret=Integer.toHexString(val & 255);
while(ret.length()<2)
ret="0"+ret;
return ret;
}
// Returns a byte from memory at a given address
public static int peekb(int address)
{
return Integer.valueOf(System.getProperty("X.d"+AddrToHex(address)).substring(6,8),16).intValue();
}
// Returns a word from memory at a given address
public static int peekw(int address)
{
return Integer.valueOf(System.getProperty("X.d"+AddrToHex(address)).substring(4,8),16).intValue();
}
// Returns a dword from memory at a given address
public static int peekd(int address)
{
return Integer.valueOf(System.getProperty("X.d"+AddrToHex(address)),16).intValue();
}
// Returns a string from memory at a given address
public static String string(int address)
{
return System.getProperty("X.s"+AddrToHex(address));
}
// Writes a byte to the specified address in memory. Returns previous value
public static int pokeb(int address, int data)
{
return Integer.valueOf(System.getProperty("X.w"+AddrToHex(address)+" "+Int8ToHex(data)),16).intValue();
}
// Writes a word to the specified address in memory. Returns previous value
public static int pokew(int address, int data)
{
return pokeb(address,data&255)+pokeb(address+1,data/256)*256;
}
// Writes a dword to the specified address in memory. Returns previous value
public static int poked(int address, int data)
{
return pokew(address,data&65535)+pokew(address+2,data/65536)*65536;
}
// Calls the given function passing up to 4 parameters. Returns R4+R5*65536
public static int Func(int address, int P1, int P2, int P3, int P4)
{
String s = System.getProperty("X.c"+AddrToHex(address)+
" "+Int16ToHex(P1)+" "+Int16ToHex(P2)+" "+Int16ToHex(P3)+" "+Int16ToHex(P4));
return Integer.valueOf(s,16).intValue();
}
// Calls the given function passing up to 4 parameters. Returns R4
public static int Func16(int address, int P1, int P2, int P3, int P4)
{
String s = System.getProperty("X.c"+AddrToHex(address)+
" "+Int16ToHex(P1)+" "+Int16ToHex(P2)+" "+Int16ToHex(P3)+" "+Int16ToHex(P4));
return Integer.valueOf(s.substring(4,8),16).intValue();
}
// Calls the given function passing up to 4 parameters. Returns R4+R5*16384
public static int FuncPtr(int address, int P1, int P2, int P3, int P4)
{
String s = System.getProperty("X.c"+AddrToHex(address)+
" "+Int16ToHex(P1)+" "+Int16ToHex(P2)+" "+Int16ToHex(P3)+" "+Int16ToHex(P4));
return Integer.valueOf(s.substring(0,4),16).intValue()*16384+Integer.valueOf(s.substring(4,8),16).intValue();
}
public static int Func16(int address)
{
return Func16(address,0,0,0,0);
}
public static int Func(int address)
{
return Func(address,0,0,0,0);
}
public static int FuncPtr(int address)
{
return FuncPtr(address,0,0,0,0);
}
private static int FileIOInited=0;
public static String Run(String FileName, String Parameters)
{
String s;
FileName = FileName.toLowerCase();
if(FileName.indexOf(' ')!=-1)
s="\""+FileName+"\"";
else
s=FileName;
if(Parameters.length()>0)
s+=" "+Parameters;
if(FileIOInited==0)
{
FileIOInited=1;
File F=new File(); // initialize java filesystem
F.exists("anything");
}
return System.getProperty("X.r"+s);
}
public static String Run(String FileName)
{
return Run(FileName,"");
}
} |
|