Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.3183
Browse files Browse the repository at this point in the history
BitBltPlugin:
implement primitivePixelValueAtX:y:put: to complement primitivePixelValueAtX:y:.
Reuse the obsolete & unused sendInvokeCallback:Stack:Registers:Jmpbuf: function
in the VirtualMachione struct to access storeLong32:ofObject:withValue:.
  • Loading branch information
eliotmiranda committed Apr 19, 2022
1 parent 06dca1d commit 1283ba4
Show file tree
Hide file tree
Showing 50 changed files with 649 additions and 6,134 deletions.
4 changes: 4 additions & 0 deletions platforms/Cross/vm/sqVirtualMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ struct VirtualMachine* sqGetInterpreterProxy(void)
VM->setInterruptCheckChain = setInterruptCheckChain;
VM->classAlien = classAlien;
VM->classUnsafeAlien = classUnsafeAlien;
# if OLD_FOR_REFERENCE /* slot repurposed for storeLong32ofObjectwithValue */
VM->sendInvokeCallbackStackRegistersJmpbuf = sendInvokeCallbackStackRegistersJmpbuf;
# else
VM->storeLong32ofObjectwithValue = storeLong32ofObjectwithValue;
# endif
VM->reestablishContextPriorToCallback = reestablishContextPriorToCallback;
VM->getStackPointer = (sqInt *(*)(void))getStackPointer;
VM->isOopImmutable = isOopImmutable;
Expand Down
8 changes: 8 additions & 0 deletions platforms/Cross/vm/sqVirtualMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ typedef struct VirtualMachine {
void *(*setInterruptCheckChain)(void (*aFunction)(void));
sqInt (*classAlien)(void);
sqInt (*classUnsafeAlien)(void);
# if OLD_FOR_REFERENCE /* slot repurposed for storeLong32ofObjectwithValue */
sqInt (*sendInvokeCallbackStackRegistersJmpbuf)(sqInt thunkPtrAsInt, sqInt stackPtrAsInt, sqInt regsPtrAsInt, sqInt jmpBufPtrAsInt);
# else
usqInt (*storeLong32ofObjectwithValue)(sqInt index, sqInt oop, usqInt);
# endif
sqInt (*reestablishContextPriorToCallback)(sqInt callbackContext);
sqInt *(*getStackPointer)(void);
sqInt (*isOopImmutable)(sqInt oop);
Expand Down Expand Up @@ -548,7 +552,11 @@ usqInt sizeOfAlienData(sqInt);
sqInt signalNoResume(sqInt);
#if VM_PROXY_MINOR > 8
sqInt *getStackPointer(void); /* Alien FFI */
# if OLD_FOR_REFERENCE /* slot repurposed for storeLong32ofObjectwithValue */
sqInt sendInvokeCallbackStackRegistersJmpbuf(sqInt thunkPtrAsInt, sqInt stackPtrAsInt, sqInt regsPtrAsInt, sqInt jmpBufPtrAsInt); /* Alien FFI */
# else
usqInt storeLong32ofObjectwithValue(sqInt index, sqInt oop, usqInt);
# endif
sqInt reestablishContextPriorToCallback(sqInt callbackContext); /* Alien FFI */
sqInt sendInvokeCallbackContext(vmccp);
sqInt returnAsThroughCallbackContext(sqInt, vmccp, sqInt);
Expand Down
30 changes: 14 additions & 16 deletions platforms/iOS/vm/Common/Classes/sqSqueakAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Some of this code was funded via a grant from the European Smalltalk User Group
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down Expand Up @@ -50,37 +50,35 @@ - (void)dealloc {
}

- (void) makeMainWindow {

/*Beware creating a main window must be done on main thread it will not work from this interpreter squeak thread */

sqInt width,height;
windowDescriptorBlock *windowBlock;

NSObject * createdWindow = [self createPossibleWindow];

extern sqInt getSavedWindowSize(void); //This is VM Callback
extern sqInt setSavedWindowSize(sqInt value); //This is VM Callback

/* get old window size */
width = ((unsigned) getSavedWindowSize()) >> 16;
height = getSavedWindowSize() & 0xFFFF;

extern sqInt getFullScreenFlag(void);
if (!getFullScreenFlag()) {
if (!getFullScreenFlag())
[self placeMainWindowOnLargerScreenGivenWidth: width height: height];
}


windowBlock = AddWindowBlock();
windowBlock->handle = (__bridge void*) createdWindow;
windowBlock->context = nil;
windowBlock->updateArea = CGRectZero;
setSavedWindowSize( (width << 16) |(height & 0xFFFF));

setSavedWindowSize((width << 16) | (height & 0xFFFF));
windowBlock->width = width;
windowBlock->height = height;

ioSetFullScreen(getFullScreenFlag());

}

- (sqSqueakMainApplication *) makeApplicationInstance {
Expand All @@ -105,14 +103,14 @@ - (void) workerThreadStart {
#if COGVM
[squeakThread setStackSize: [squeakThread stackSize]*4];
#endif

[squeakThread start];
}

- (void) singleThreadStart {
/* This the carbon logic model
described by http://developer.apple.com/qa/qa2001/qa1061.html */

[[NSRunLoop mainRunLoop] performSelector: @selector(runSqueak)
target: self.squeakApplication
argument: nil
Expand Down
117 changes: 113 additions & 4 deletions src/plugins/BitBltPlugin/BitBltPlugin.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Automatically generated by
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3171 uuid: b926bcd4-a4a9-4d38-8267-4eac3fec60d9
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3183 uuid: c5c103b4-2c5c-44e7-8e32-030e79600ca6
from
BitBltSimulation VMMaker.oscog-eem.3171 uuid: b926bcd4-a4a9-4d38-8267-4eac3fec60d9
BitBltSimulation VMMaker.oscog-eem.3183 uuid: c5c103b4-2c5c-44e7-8e32-030e79600ca6
*/
static char __buildInfo[] = "BitBltSimulation VMMaker.oscog-eem.3171 uuid: b926bcd4-a4a9-4d38-8267-4eac3fec60d9 " __DATE__ ;
static char __buildInfo[] = "BitBltSimulation VMMaker.oscog-eem.3183 uuid: c5c103b4-2c5c-44e7-8e32-030e79600ca6 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -167,6 +167,7 @@ EXPORT(sqInt) primitiveCopyBits(void);
EXPORT(sqInt) primitiveDisplayString(void);
EXPORT(sqInt) primitiveDrawLoop(void);
EXPORT(sqInt) primitivePixelValueAt(void);
EXPORT(sqInt) primitivePixelValueAtPut(void);
EXPORT(sqInt) primitiveWarpBits(void);
static sqInt reloadDestAndSourceForms(void);
static unsigned int rgbAddwith(unsigned int sourceWord, unsigned int destinationWord);
Expand Down Expand Up @@ -298,6 +299,7 @@ static sqInt (*stackObjectValue)(sqInt offset);
static sqInt (*stackValue)(sqInt offset);
static sqInt (*statNumGCs)(void);
static sqInt (*storeIntegerofObjectwithValue)(sqInt index, sqInt oop, sqInt integer);
static usqInt (*storeLong32ofObjectwithValue)(sqInt fieldIndex, sqInt oop, usqInt anInteger);
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
extern sqInt byteSizeOf(sqInt oop);
extern sqInt failed(void);
Expand Down Expand Up @@ -348,6 +350,11 @@ extern sqInt statNumGCs(void);
# define statNumGCs() 0
#endif
extern sqInt storeIntegerofObjectwithValue(sqInt index, sqInt oop, sqInt integer);
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 16)
extern usqInt storeLong32ofObjectwithValue(sqInt fieldIndex, sqInt oop, usqInt anInteger);
#else
# define storeLong32ofObjectwithValue(fieldIndex, oop, anInteger) 0
#endif
extern
#endif
struct VirtualMachine* interpreterProxy;
Expand All @@ -358,7 +365,7 @@ static int maskTable[33] = {
0, 1, 3, 0, 15, 31, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 65535,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1
};
static const char *moduleName = "BitBltPlugin VMMaker.oscog-eem.3171 " INT_EXT;
static const char *moduleName = "BitBltPlugin VMMaker.oscog-eem.3183 " INT_EXT;
static sqInt noHalftone;
static sqInt noSource;
static sqInt numGCsOnInvocation;
Expand Down Expand Up @@ -5696,6 +5703,99 @@ primitivePixelValueAt(void)
}


/* Sets the single pixel at x@y. Answers the previous value of the pixel.
It does not handle LSB bitmaps right now.
If x or y are < 0, return 0 to indicate transparent (cf
BitBlt>bitPeekerFromForm: usage).
Likewise if x>width or y>depth.
Fail if the rcvr doesn't seem to be a Form, or x|y seem wrong
*/

/* BitBltSimulation>>#primitivePixelValueAtX:y:put: */
EXPORT(sqInt)
primitivePixelValueAtPut(void)
{
sqInt bitmap;
sqInt bitsSize;
sqInt depth;
unsigned int mask;
sqInt oldPixel;
sqInt pixel;
sqInt ppW;
sqInt rcvr;
sqInt shift;
sqInt stride;
sqInt word;
sqInt xVal;
sqInt yVal;

if (!((isIntegerObject((xVal = stackValue(2))))
&& ((isIntegerObject((yVal = stackValue(1))))
&& (isIntegerObject((pixel = stackValue(0))))))) {
return primitiveFailFor(PrimErrBadArgument);
}
xVal = integerValueOf(xVal);
yVal = integerValueOf(yVal);
pixel = integerValueOf(pixel);
rcvr = stackValue(3);
rcvr = stackValue(methodArgumentCount());
if (!((isPointers(rcvr))
&& ((slotSizeOf(rcvr)) >= 4))) {
return primitiveFailFor(PrimErrBadReceiver);
}
bitmap = fetchPointerofObject(FormBitsIndex, rcvr);
if (!(isWordsOrBytes(bitmap))) {
return primitiveFailFor(PrimErrBadReceiver);
}
width = fetchIntegerofObject(FormWidthIndex, rcvr);
height = fetchIntegerofObject(FormHeightIndex, rcvr);

/* if width/height/depth are not integer, fail */
depth = fetchIntegerofObject(FormDepthIndex, rcvr);
if ((failed())
|| (depth < 0)) {
return primitiveFailFor(PrimErrBadReceiver);
}
if ((xVal < 0)
|| ((xVal >= width)
|| ((yVal < 0)
|| ((yVal >= height)
|| (pixel < 0))))) {
return primitiveFailFor(PrimErrBadArgument);
}

/* pixels in each word */
ppW = 32 / depth;

/* how many words per row of pixels */
stride = (width + (ppW - 1)) / ppW;
bitsSize = byteSizeOf(bitmap);
if (!(bitsSize >= ((stride * height) * 4))) {

/* bytes per word */
return primitiveFailFor(PrimErrBadReceiver);
}

/* load the word that contains our target */
word = fetchLong32ofObject((yVal * stride) + (xVal / ppW), bitmap);

/* make a mask to isolate the pixel within that word */
mask = ((usqInt)(0xFFFFFFFFU)) >> (32 - depth);

/* this is the tricky MSB part - we mask the xVal to find how far into the word we need, then add 1 for the pixel we're looking for, then * depth to get the bit shift */
shift = 32 - (((xVal & (ppW - 1)) + 1) * depth);

/* shift, mask and dim the lights */
oldPixel = (((usqInt)(word)) >> shift) & mask;
word = ((word | (((usqInt)(mask) << shift))) - (((usqInt)(mask) << shift))) + (((sqInt)((usqInt)(pixel) << shift)));
storeLong32ofObjectwithValue((yVal * stride) + (xVal / ppW), bitmap, word);
if (!(failed())) {
methodReturnValue(positive32BitIntegerFor(oldPixel));
}
return null;
}


/* Invoke the warpBits primitive. If the destination is the display, then
copy it to the screen.
*/
Expand Down Expand Up @@ -6811,6 +6911,13 @@ setInterpreter(struct VirtualMachine *anInterpreter)
#endif
#endif
storeIntegerofObjectwithValue = interpreterProxy->storeIntegerofObjectwithValue;
#if VM_PROXY_MAJOR > 1 || (VM_PROXY_MAJOR == 1 && VM_PROXY_MINOR >= 16)
storeLong32ofObjectwithValue = interpreterProxy->storeLong32ofObjectwithValue;
#else
#if !defined(storeLong32ofObjectwithValue)
storeLong32ofObjectwithValue = 0;
#endif
#endif
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */
}
return ok;
Expand Down Expand Up @@ -8276,6 +8383,7 @@ void* BitBltPlugin_exports[][3] = {
{(void*)_m, "primitiveDisplayString\000\001\000", (void*)primitiveDisplayString},
{(void*)_m, "primitiveDrawLoop\000\002\000", (void*)primitiveDrawLoop},
{(void*)_m, "primitivePixelValueAt\000\002\001", (void*)primitivePixelValueAt},
{(void*)_m, "primitivePixelValueAtPut\000\002\001", (void*)primitivePixelValueAtPut},
{(void*)_m, "primitiveWarpBits\000\001\000", (void*)primitiveWarpBits},
{(void*)_m, "setInterpreter", (void*)setInterpreter},
{NULL, NULL, NULL}
Expand All @@ -8289,6 +8397,7 @@ EXPORT(signed short) primitiveCopyBitsMetadata = 0x100;
EXPORT(signed short) primitiveDisplayStringMetadata = 0x100;
EXPORT(signed short) primitiveDrawLoopMetadata = 0x200;
EXPORT(signed short) primitivePixelValueAtMetadata = 513;
EXPORT(signed short) primitivePixelValueAtPutMetadata = 513;
EXPORT(signed short) primitiveWarpBitsMetadata = 0x100;
#endif // SPURVM

Expand Down
2 changes: 1 addition & 1 deletion src/spur32.cog.lowcode/cogit.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated by
CCodeGenerator VMMaker.oscog-eem.3174 uuid: 2edcc3c8-ba87-4012-b4f4-ea60094be91f
CCodeGenerator VMMaker.oscog-eem.3183 uuid: c5c103b4-2c5c-44e7-8e32-030e79600ca6
*/


Expand Down
Loading

0 comments on commit 1283ba4

Please sign in to comment.