// somewhere at init and how to set up the 8bbp mode for FB?
// Anyway the SDL does seem always to convert to 16bbp so bypassing some speedup
// could be achieved. If that wouldn't be possible then not big deal - 256 * 2
// (512 bytes) lockup table and conversion in asembler should fly anyway.
fbdev=open("/dev/fb0", O_RDWR);
fb=(unsigned int *)mmap(0, 320*240*sizeof(unsigned short int), PROT_WRITE, MAP_SHARED, fbdev, 0);
void VID_Update(vrect_t *rects)
{
    int n, i,x,y,hh,xx,yy;
    Uint8 *screenpixels,*origpixels;
    static unsigned int *source;
    // example code - goal should be to get rid of any lib for framebuffer
    // access.
    source = (unsigned int *)screen->pixels;  // source pointer
    if(doublesize == 0)
    asm
    (
        "stmfd r13!, {r0-r12}\n" // might be unnecessary but to be safe
        "mov r9, %0\n"      // load destination
        "mov r10, %1\n"      // load source
        "mov r11, #0x12000\n"  // make a constant 320 * 240 = 0x12C00
        "orr r11, r11, #0xC00\n"
        "add r11, r11, r9\n"    // the end pointer
        "loop:\n"
        "ldmia r9!, {r0-r7}\n" // push memory at close to 150MB/s
        "stmia r10!, {r0-r7}\n"
        "cmp r9, r11\n"         // something more to move?
        "blt loop\n"            // if so repeat the loop
        "ldmfd r13!, {r0-r12}\n"    // might be unnecessary...
        :
        : "r"(fb), "r"(source)
        :  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" // could be deleted
    );
    else
    {
        source += foobar; // eventually add some offset is needed
    asm
    (
        "stmfd r13!, {r0-r12}\n" // might be unnecessary but to be safe
        "mov r8, %0\n"      // load destination 
        "mov r9, %1\n"      // load source (the 160 * 120 one)
        "mov r11, #0x12000\n"  // make a constant 320 * 240 = 0x12C00
        "orr r11, r11, #0xC00\n"
        "sub r11, r11, #320\n" // but don't scan all lines
        "add r11, r11, r9\n"    // the end pointer
       
        "add r12, r8, #320\n"   // end point of single source line
        "mov r2, #0xFF\n"       // a mask
        "loop:\n"
        "ldmia r9!, {r0, r1}\n" // load eight source pixels
        "and r3, r0, r2, lsl #24\n" // some doubling for four first source pixels
        "mov r4, r3\n"              // it takes 12 machine cycles to do
        "orr r4, r4, r3, lsr #8\n"  // and there is zero extra memory accesses
        "and r3, r0, r2, lsl #16\n" // 12 cycles / 8 final pixels = 1.5 cycle/pix;)
        "orr r4, r4, r3, lsr #8\n"
        "orr r4, r4, r3, lsr #16\n"
        "and r3, r0, r2, lsl #8\n"
        "mov r5, r3\n"
        "orr r5, r5, r3, lsl #8\n"
        "and r3, r0, r2\n"
        "orr r5, r5, r3, lsl #8\n"
        "orr r5, r5, r3\n"
        "and r3, r1, r2, lsl #24\n" // some doubling for four next source pixels
        "mov r6, r3\n"              // it's loop unrolling
        "orr r6, r4, r3, lsr #8\n"
        "and r3, r1, r2, lsl #16\n"
        "orr r6, r4, r3, lsr #8\n"
        "orr r6, r4, r3, lsr #16\n"
        "and r3, r1, r2, lsl #8\n"
        "mov r7, r3\n"
        "orr r7, r5, r3, lsl #8\n"
        "and r3, r1, r2\n"
        "orr r7, r5, r3, lsl #8\n"
        "orr r7, r5, r3\n"
        
        "add r12, r8, #320\n"  // compute pointer for the second line
        "stmia r8!, {r4-r7}\n" // blast into framebuffer with doubled pixels
        "stmia r12, {r4-r7}\n"
        "cmp r8, r11\n"   // is it a time for the next line?
        "addge r8, #320\n"
        "addge r9, #320\n"
        "addge r11, #320\n"
        "cmp r8, r11\n"         // something more to move?
        "blt loop\n"            // if so repeat the loop
        "ldmfd r13!, {r0-r12}\n"    // might be unnecessary...
        :
        : "r"(fb), "r"(source)
        :  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" // could be deleted
    );
    }
}