Google
Web alhem.net

dsm.cpp File Reference

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <map>
#include <string>
#include <Base64.h>
#include "RobotXMLFile.h"
#include "CodeTool.h"

Include dependency graph for dsm.cpp:

Go to the source code of this file.

Functions

void visa2 (const unsigned char *p, size_t &addr)
void visa4 (const unsigned char *p, size_t &addr)
int main (int argc, char *argv[])


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 35 of file dsm.cpp.

References visa2(), and visa4().

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++]; // string length
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                 } // if (x.IsOk())
00106         }
00107 }

void visa2 ( const unsigned char *  p,
size_t &  addr 
)

Definition at line 11 of file dsm.cpp.

Referenced by main().

00012 {
00013         unsigned char c;
00014         c = p[addr++];
00015         printf(" %02x",c);
00016         c = p[addr++];
00017         printf(" %02x",c);
00018 }

void visa4 ( const unsigned char *  p,
size_t &  addr 
)

Definition at line 21 of file dsm.cpp.

Referenced by main().

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 }


Generated for Robot World by doxygen 1.3.6

Page, code, and content Copyright (C) 2004 by Anders Hedström