bin2as.cpp

00001 // simple ELF code segment ripper
00002 
00003 #include <stdio.h>
00004 #include <assert.h> // used for runtime asserts !
00005 
00006 
00007 typedef unsigned char byte;
00008 
00009 int main(int argc, char* argv[])
00010 {
00011         assert(argc == 3);
00012         const char* szTag = argv[1];
00013         const char* szInFile = argv[2];
00014 
00015         FILE* pf = fopen(szInFile, "rb");
00016         assert(pf != NULL);
00017 
00018         printf("\t.text\n");
00019         printf("\t.align 4 # 16 bytes\n");
00020         printf("\t.global VU_%s_start\n", szTag);
00021         printf("VU_%s_start:\n", szTag);
00022 
00023         while (1)
00024         {
00025                 unsigned int data[4]; // 128 bits
00026                 assert(sizeof(data) == 128/8);
00027                 int cb = fread(data, 1, 16, pf);
00028                 if (cb == 0)
00029                         break;
00030                 assert(cb == 16);
00031                 printf("\t.word 0x%08X, 0x%08X, 0x%08X, 0x%08x\n",
00032                         data[0], data[1], data[2], data[3]);
00033         }
00034 
00035         printf("\t.global VU_%s_end\n", szTag);
00036         printf("VU_%s_end:\n", szTag);
00037 
00038         fclose(pf);
00039 
00040         return 0;
00041 }
00042 

Generated on Sun May 18 21:45:08 2008 for PS2X by  doxygen 1.5.4