DirectFB help needed

new topic     » topic index » view thread      » older message » newer message

I'm trying to drive DirectFB directly from OEU instead of using a C library on a Raspberry Pi. I get stuck on one problem when poking into mapped memory.

I want to port this code:

 
    // Map the device to memory 
    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); 
 
    // Figure out where in memory to put the pixel 
    for (y = 100; y < 300; y++) 
        for (x = 100; x < 300; x++) { 
 
            location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + 
                       (y+vinfo.yoffset) * finfo.line_length; 
 
            if (vinfo.bits_per_pixel == 32) { 
                *(fbp + location) = 100;        // Some blue 
                *(fbp + location + 1) = 15+(x-100)/2;     // A little green 
                *(fbp + location + 2) = 200-(y-100)/5;    // A lot of red 
                *(fbp + location + 3) = 0;      // No transparency 
            } else  { //assume 16bpp 
                int b = 10; 
                int g = (x-100)/6;     // A little green 
                int r = 31-(y-100)/16;    // A lot of red 
                unsigned short int t = r<<11 | g << 5 | b; 
                *((unsigned short int*)(fbp + location)) = t; 
            } 
 
        } 
    munmap(fbp, screensize); 
 

I wrote this code:

 
  fbp = mmap(0, screensize, or_bits(PROT_READ, PROT_WRITE), MAP_SHARED, fbfd, 0) 
 
  -- Figure out where in memory to put the pixel 
  atom xoffset = peek4u(vinfo+VSI_XOFFSET) 
  atom yoffset = peek4u(vinfo+VSI_YOFFSET) 
  atom line_length = peek4u(finfo+FSI_LINE_LENGTH) 
 
  for y = 100 to 299 do 
      for x = 100 to 299 do 
 
          location = (x+xoffset) * (bits_per_pixel/8) + 
                     (y+yoffset) * line_length 
 
          if bits_per_pixel = 32 then 
              poke(fbp + location, { 
                     100,        -- Some blue 
                     trunc(15+(x-100)/2),     -- A little green 
                     trunc(200-(y-100)/5),    -- A lot of red 
                     0})      -- No transparency 
          else --assume 16bpp 
              integer b = 10 
              integer g = trunc((x-100)/6)     -- A little green 
              integer r = trunc(31-(y-100)/16)    -- A lot of red 
              integer t = or_all({shift_bits(r,-11), shift_bits(g,-5), b}) 
              poke2(fbp + location, t) 
          end if 
 
      end for 
  end for 
  munmap(fbp, screensize) 
 

I get a machine level exception on poke(fbp + location, {. It seems I try to poke into a bad location but I can't locate the bug!

Can anyone help?

Jean-Marc

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu