Convert .o to a lyx image (adding a simple loader)

Even so this is easily prossible with either lynxer or lynxdir, the shortest, fastest and simplest way was prepared by David Huseby and Karri Kaksonen. I coded a small program to make use of it. This was done as an example for Bernds flashcart firmware, but might be useful for others, too.
#include <stdio.h>

// Posted by Karri
unsigned char micro_loader_fb68_stage1[52]={
 0xff, 0x81, 0xca, 0x33, 0xbe, 0x80, 0xa2, 0xc4, 0x6d, 0x98, 0xfe, 0x8d, 0xbc, 0x66, 0xc0, 0x7a,
 0x09, 0x50, 0x23, 0x28, 0x18, 0xc8, 0x06, 0x70, 0x58, 0x4f, 0x1b, 0xe1, 0xc7, 0x90, 0x08, 0xcd,
 0x1a, 0x6e, 0x5a, 0x45, 0x32, 0xd7, 0x6d, 0xc6, 0x8a, 0xe5, 0xd8, 0x5c, 0xa0, 0xe8, 0x4f, 0x7a,
 0x5f, 0x73, 0x8d, 0x22

// and the secondary loader that follows the encrypted loader

unsigned char micro_loader_fb68_stage2[128+12+11]={
 0xa2, 0x00, 0xa0, 0x08, 0xad, 0xb2, 0xfc, 0x95, 0x26, 0xe8, 0x88, 0xd0,
 0xf7, 0xa5, 0x26, 0x85, 0x2e, 0x20, 0xca, 0xfb, 0xa5, 0x28, 0x49, 0xff, 0xa8, 0xa5, 0x27, 0x49,
 0xff, 0xaa, 0x20, 0xa1, 0xfb, 0xa5, 0x2a, 0xa6, 0x2b, 0x85, 0x31, 0x86, 0x32, 0xa5, 0x2d, 0x49,
 0xff, 0xa8, 0xa5, 0x2c, 0x49, 0xff, 0xaa, 0x20, 0xac, 0xfb, 0x6c, 0x2a, 0x00, 0xe8, 0xd0, 0x03,
 0xc8, 0xf0, 0x57, 0x20, 0xbf, 0xfb, 0x80, 0xf5, 0xe8, 0xd0, 0x03, 0xc8, 0xf0, 0x4c, 0x20, 0xbf,
 0xfb, 0x92, 0x31, 0xe6, 0x31, 0xd0, 0xf1, 0xe6, 0x32, 0x80, 0xed, 0xad, 0xb2, 0xfc, 0xe6, 0x2f,
 0xd0, 0x38, 0xe6, 0x30, 0xd0, 0x34, 0x48, 0xda, 0x5a, 0xa5, 0x1a, 0x29, 0xfc, 0xa8, 0x09, 0x02,
 0xaa, 0xa5, 0x2e, 0xe6, 0x2e, 0x38, 0x80, 0x0b, 0x90, 0x04, 0x8e, 0x8b, 0xfd, 0x18, 0xe8, 0x8e,
 0x87, 0xfd, 0xca, 0x8e, 0x87, 0xfd, 0x2a, 0x8c, 0x8b, 0xfd, 0xd0, 0xec, 0xa5, 0x1a, 0x8d, 0x8b,
 0xfd, 0x64, 0x2f, 0xa9, 0xfe, 0x85, 0x30, 0x7a, 0xfa, 0x68, 0x60
};//                     ^^^^

// After the secondary loader you need one directory entry:
// 00       = block number
// d3 00 = offset $00d3
// 88       = dummy byte
// 00 02 = start address in RAM $0200
// 07 10 = length of binary to load $1007
// Then you just append your binary code you want to load.
// You can change the start address and length to match your code.
// The last  fe in the secondary loader should be different for different cart types.
// fe = 128k cart
// fc = 256k cart
// f8 = 512k cart

void main(int argv,char **argc)
  FILE *fh_in;
  FILE *fh_out;
  int a, b;
    fh_in =fopen(argc[1],"rb");

    for (int i=0; i< 52; i++) fputc( micro_loader_fb68_stage1[i], fh_out);
    for (int i=0; i<151; i++) fputc( micro_loader_fb68_stage2[i], fh_out);
    // now comes the first dir entry in EPYX format! @ 203

    fputc( 0x00, fh_out);
    fputc( 0xd3, fh_out); 
    fputc( 0x00, fh_out);
    fputc( 0x88, fh_out);
//     data[203+0] = 0x00; // block nr =0 (fix)
//     data[203+1] = 0xd3; // offset lo = 211 (203+8) (fix)
//     data[203+2] = 0x00; // offset hi = 0 (fix)
//     data[203+3] = 0x88; // flag executeable (fix)

    fgetc( fh_in); // skip
    fgetc( fh_in); // skip

    a=fgetc( fh_in);
    b=fgetc( fh_in);
    fputc( b, fh_out); // inverse
    fputc( a, fh_out);
//     data[203+4] = file_data[3]; // load addr lo
//     data[203+5] = file_data[2]; // load addr hi

    a=fgetc( fh_in); // actually, we have to subtract 10 here (headerlength!) buts does it matter if he load 10 bytes more!?
    b=fgetc( fh_in);
    fputc( b, fh_out); // inverse
    fputc( a, fh_out);
//     data[203+6] =  file_date[5];// length lo   should be (size-8)
//     data[203+7] =  file_date[4];// length hi   should be (size-8)

    fgetc( fh_in); // skip
    fgetc( fh_in); // skip    
    fgetc( fh_in); // skip
    fgetc( fh_in); // skip
    while(!feof( fh_in)){
       a=fgetc( fh_in);
       if( feof( fh_in)) break;
       fputc( a, fh_out);
    fclose( fh_in);
    fclose( fh_out);