00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 #include <map>
00005 #include <string>
00006 #include <Base64.h>
00007 #include "RobotXMLFile.h"
00008 #include "CodeTool.h"
00009
00010
00011 void visa2(const unsigned char *p,size_t& addr)
00012 {
00013 unsigned char c;
00014 c = p[addr++];
00015 printf(" %02x",c);
00016 c = p[addr++];
00017 printf(" %02x",c);
00018 }
00019
00020
00021 void visa4(const unsigned char *p,size_t& addr)
00022 {
00023 unsigned char c;
00024 c = p[addr++];
00025 printf(" %02x",c);
00026 c = p[addr++];
00027 printf(" %02x",c);
00028 c = p[addr++];
00029 printf(" %02x",c);
00030 c = p[addr++];
00031 printf(" %02x",c);
00032 }
00033
00034
00035 int main(int argc,char *argv[])
00036 {
00037 if (argc < 2)
00038 {
00039 printf("Usage: %s <.xml file>\n",*argv);
00040 exit(-1);
00041 }
00042 for (int i = 1; i < argc; i++)
00043 {
00044 RobotXMLFile x(argv[i]);
00045
00046 if (x.IsOk())
00047 {
00048 CodeTool ct(x);
00049 std::string robot_name = x.GetString("name");
00050 std::string owner_uid = x.GetString("owner");
00051
00052 printf("Disassembly of robot: %s\n",robot_name.c_str());
00053 printf("Created by: %s\n",owner_uid.c_str());
00054
00055 if (ct.Sane())
00056 {
00057 unsigned char opcode;
00058 size_t addr = 0;
00059 while (addr < ct.GetCodesize())
00060 {
00061 printf("%04x %04x ",addr/0x10000,addr%0x10000);
00062 opcode = ct.GetCode(addr++);
00063 int opsize = ct.GetOpsize(opcode);
00064 printf("%02x %s ",opcode,ct.GetOpcode(opcode).c_str());
00065 if (opsize == -1)
00066 {
00067 }
00068 else
00069 if (opsize == -2)
00070 {
00071 visa2(ct.GetBuf(),addr);
00072 unsigned char c;
00073 c = ct.GetBuf()[addr++];
00074 printf(" string length=%d '",c);
00075 for (int i = 0; i < c; i++)
00076 {
00077 char c;
00078 c = ct.GetBuf()[addr++];
00079 printf("%c",c);
00080 }
00081 }
00082 else
00083 if (opsize == 2)
00084 {
00085 visa2(ct.GetBuf(), addr);
00086 }
00087 else
00088 if (opsize == 4)
00089 {
00090 visa4(ct.GetBuf(), addr);
00091 }
00092 if (opcode == 0x11 || opcode == 0x82)
00093 {
00094 printf(" body length = ");
00095 visa2(ct.GetBuf(), addr);
00096 }
00097 printf("\n");
00098 }
00099 }
00100 else
00101 {
00102 printf("Insane code\n");
00103 }
00104
00105 }
00106 }
00107 }
00108
00109