PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Direct Memory Access

A few questions first.

What's the difference between MEMCPY and MEMMOVE ? (MEMCPY doesn't seem to work, but MEMMOVE does - although the symantics of it sounds like MEMMOVE should zero out the source).

Is there any way to have the lockinfo's pixel struct act like an array of shorts? My initial test of poking values into the pixels was poor - and that was on the desktop PC.

Anyway, without quick/direct access to the pixels, I think something like the fire demo is out of the question. I do have something I'm working on that you'll probably like.
Here is a description of memmove:

The memmove function copies count bytes of characters from src to dest. If some regions of the source area and the destination overlap, memmove ensures that the original source bytes in the overlapping region are copied before being overwritten.

and memcpy:

The memcpy function copies count bytes of src to dest. If the source and destination overlap, this function does not ensure that the original source bytes in the overlapping region are copied before being overwritten. Use memmove to handle overlapping regions.


I will get back to you and try to find a better alternative to access memory with an array.

I think this should work:

Code:
SDIM(a$, TShort, 240, 320);
&a;$ = lockinf.pixels$;
a$[10,10] = g_rgb(255, 255, 255);


This should make the address of a$ the location of the start of the pixels.

Let me know if this works.
Hi Fast_Rx,

Here are two ways of optimizing and directly accessing memory:

Code:
// Default Game API skeleton

#include "GameAPI.ppl"

func mainproc(hWnd$, Msg$, wParam$, lParam$)
ok$ = true;

case (Msg$)
WM_CLOSE:
// Shutdown the GameAPI.
ShutGameAPI(hWnd$);
struct(i$, MENUITEMINFO);
GetMenuItemInfo(NULL, MF_BYCOMMAND, 400, i$);
end;

return (ok$);
end;

func gameproc(hWnd$, Msg$, wParam$, lParam$)
ok$ = true;

case (Msg$)
WM_PAINT:
g_clear(0);
G_Lock(null);
for (x$, 10, 20, 1)
for (y$, 10, 20, 1)
//poke(pixels$ + y$ * pitch$ + x$, g_rgb(255, 255, 255), tbyte);
pixarray$[x$, y$] = g_rgb(255, 255, 255);
end;
end;
G_Unlock(null, null, false);
end;

return (ok$);
end;

func WinMain
// Create a new form that will hold the GAPI.
h$ = newform({GAPI}, {GAPIClass}, &mainproc;);
ShowWindow(h$, SW_SHOW);

// Activate FPS display in white.
ShowFPS(true, G_RGB(255, 255, 255));
Pad$ = NewSurface(2048, 2048, newrast$);
freeSurface(pad$);
freeRasterizer(newrast$);

// Initialize GameAPI.
InitGameAPI(h$, &gameproc;, 5);

Global(pixels$, pitch$);
g_beginscene;
struct(lockinf$, LockInfo);
&lockinf;$ = G_Lock(null);
pitch$ = lockinf.pitch$ >> 1;
pixels$ = lockinf.pixels$;
G_Unlock(lockinf$, null, false);
g_update;

Global(pixarray$);
SDIM(pixarray$, TShort, 240, 320);
&pixarray;$ = pixels$;

return (true);
end;


Of course the g_lock() and g_unlock() take one more parameter in the newest version of PPL to specify the surface to lock/unlock. (In this case NULL means main buffer).

EDIT: I just fixed the array offset calculation. I don't know why but for some reason it wasn't right. The [x$,y$] will always be reversed in your version.