After a lot of fun and headaches with the MEM* commands, some of which still need to be resolved, I finally got the basic ideas for a painting program to work.
There's still a lot of work to do, but this should serve as a sample of having some simple "painting" fun
Left mouse button to paint
Right mouse button to reset
Images uses in this sample are attached.
// --------------------------------- //
// Project: mem-paint-test
// --------------------------------- //
SETCURRENTDIR("Media")
LOCAL PX1%[], PX2%[]
LOCAL x,y,r,c,i,mx,my,mbl,mbr,rr,cc
LOCAL cr,cg,cb,ca
LOCAL argb%
CREATESCREEN 1,1,640,480
CREATESCREEN 2,2,40,40
CREATESCREEN 3,3,640,480
LOADSPRITE "catndog1.png",1
LOADSPRITE "ball.png",2
WHILE TRUE
//get mouse state
MOUSESTATE mx,my,mbl,mbr
//reset image - should build load safety timer here.. but its a test anyway.
IF mbr = 1 THEN LOADSPRITE "catndog1.png",1
//check that the mouse right and bottom are on the screen
//.....else the arrays fall over
IF mx+39 < 640 AND my+39 < 480
//get the background
SPRITE2MEM (PX1[],1)
//get paintbrush
SPRITE2MEM (PX2[],2)
//paste brush onto background
IF mbl = 1
rr = -1
FOR r = my TO my + 39 //for each row
rr = rr + 1
cc = -1
FOR c = mx TO mx + 39 //for each column
cc = cc + 1
argb = PX2[cc+rr*40]
cr = bAND(argb, 0xff)
cg = bAND(ASR(argb,8), 0xff)
cb = bAND(ASR(argb,16), 0xff)
ca = bAND(ASR(argb,24), 0xff)
IF ca <> 0
PX1[c+r*640] = argb
ENDIF
NEXT
NEXT
MEM2SPRITE (PX1[],1,640,480)
ENDIF
ENDIF //mouse in screen
//START DRAWING from here
USESCREEN -1
//dump background
DRAWSPRITE 1,0,0
//display paintbrush
DRAWSPRITE 2,mx,my
PRINT "Right Mouse button to reset", 5,450
SHOWSCREEN
WEND
[attachment deleted by admin]