1
/* Automatically generated from Squeak on #(19 March 2005 10:08:38 am) */
9
/* Default EXPORT macro that does nothing (see comment in sq.h): */
10
#define EXPORT(returnType) returnType
12
/* Do not include the entire sq.h file but just those parts needed. */
13
/* The virtual machine proxy definition */
14
#include "sqVirtualMachine.h"
15
/* Configuration options */
17
/* Platform specific definitions */
18
#include "sqPlatformSpecific.h"
22
#define null 0 /* using 'null' because nil is predefined in Think C */
23
#ifdef SQUEAK_BUILTIN_PLUGIN
25
// was #undef EXPORT(returnType) but screws NorCroft cc
26
#define EXPORT(returnType) static returnType
29
/* memory access macros */
30
#define byteAt(i) (*((unsigned char *) (i)))
31
#define byteAtput(i, val) (*((unsigned char *) (i)) = val)
32
#define longAt(i) (*((int *) (i)))
33
#define longAtput(i, val) (*((int *) (i)) = val)
38
/*** Function Prototypes ***/
40
EXPORT(const char*) getModuleName(void);
42
static int halt(void);
43
static int msg(char *s);
45
EXPORT(int) primitiveRead24BmpLine(void);
46
EXPORT(int) primitiveWrite24BmpLine(void);
47
EXPORT(int) setInterpreter(struct VirtualMachine* anInterpreter);
51
#ifdef SQUEAK_BUILTIN_PLUGIN
54
struct VirtualMachine* interpreterProxy;
55
static const char *moduleName =
56
#ifdef SQUEAK_BUILTIN_PLUGIN
57
"BMPReadWriterPlugin 19 March 2005 (i)"
59
"BMPReadWriterPlugin 19 March 2005 (e)"
65
/* Note: This is hardcoded so it can be run from Squeak.
66
The module name is used for validating a module *after*
67
it is loaded to check if it does really contain the module
68
we're thinking it contains. This is important! */
70
EXPORT(const char*) getModuleName(void) {
74
static int halt(void) {
78
static int msg(char *s) {
79
fprintf(stderr, "\n%s: %s", moduleName, s);
82
EXPORT(int) primitiveRead24BmpLine(void) {
84
unsigned char * pixelLine;
85
unsigned int * formBits;
92
if (!((interpreterProxy->methodArgumentCount()) == 4)) {
93
return interpreterProxy->primitiveFail();
95
width = interpreterProxy->stackIntegerValue(0);
96
formBitsIndex = interpreterProxy->stackIntegerValue(1);
97
formBitsOop = interpreterProxy->stackObjectValue(2);
98
pixelLineOop = interpreterProxy->stackObjectValue(3);
99
if (interpreterProxy->failed()) {
102
if (!(interpreterProxy->isWords(formBitsOop))) {
103
return interpreterProxy->primitiveFail();
105
if (!(interpreterProxy->isBytes(pixelLineOop))) {
106
return interpreterProxy->primitiveFail();
108
formBitsSize = interpreterProxy->slotSizeOf(formBitsOop);
109
formBits = interpreterProxy->firstIndexableField(formBitsOop);
110
pixelLineSize = interpreterProxy->slotSizeOf(pixelLineOop);
111
pixelLine = interpreterProxy->firstIndexableField(pixelLineOop);
112
if (!(((formBitsIndex + width) <= formBitsSize) && ((width * 3) <= pixelLineSize))) {
113
return interpreterProxy->primitiveFail();
116
formBits += formBitsIndex-1;
119
rgb = (*pixelLine++);
120
rgb += (*pixelLine++) << 8;
121
rgb += (*pixelLine++) << 16;
122
if(rgb) rgb |= 0xFF000000; else rgb |= 0xFF000001;
126
interpreterProxy->pop(4);
129
EXPORT(int) primitiveWrite24BmpLine(void) {
131
unsigned char * pixelLine;
132
unsigned int * formBits;
139
if (!((interpreterProxy->methodArgumentCount()) == 4)) {
140
return interpreterProxy->primitiveFail();
142
width = interpreterProxy->stackIntegerValue(0);
143
formBitsIndex = interpreterProxy->stackIntegerValue(1);
144
formBitsOop = interpreterProxy->stackObjectValue(2);
145
pixelLineOop = interpreterProxy->stackObjectValue(3);
146
if (interpreterProxy->failed()) {
149
if (!(interpreterProxy->isWords(formBitsOop))) {
150
return interpreterProxy->primitiveFail();
152
if (!(interpreterProxy->isBytes(pixelLineOop))) {
153
return interpreterProxy->primitiveFail();
155
formBitsSize = interpreterProxy->slotSizeOf(formBitsOop);
156
formBits = interpreterProxy->firstIndexableField(formBitsOop);
157
pixelLineSize = interpreterProxy->slotSizeOf(pixelLineOop);
158
pixelLine = interpreterProxy->firstIndexableField(pixelLineOop);
159
if (!(((formBitsIndex + width) <= formBitsSize) && ((width * 3) <= pixelLineSize))) {
160
return interpreterProxy->primitiveFail();
163
formBits += formBitsIndex-1;
168
(*pixelLine++) = (rgb ) & 0xFF;
169
(*pixelLine++) = (rgb >> 8 ) & 0xFF;
170
(*pixelLine++) = (rgb >> 16) & 0xFF;
174
interpreterProxy->pop(4);
178
/* Note: This is coded so that is can be run from Squeak. */
180
EXPORT(int) setInterpreter(struct VirtualMachine* anInterpreter) {
183
interpreterProxy = anInterpreter;
184
ok = interpreterProxy->majorVersion() == VM_PROXY_MAJOR;
188
ok = interpreterProxy->minorVersion() >= VM_PROXY_MINOR;
193
#ifdef SQUEAK_BUILTIN_PLUGIN
196
void* BMPReadWriterPlugin_exports[][3] = {
197
{"BMPReadWriterPlugin", "primitiveRead24BmpLine", (void*)primitiveRead24BmpLine},
198
{"BMPReadWriterPlugin", "getModuleName", (void*)getModuleName},
199
{"BMPReadWriterPlugin", "primitiveWrite24BmpLine", (void*)primitiveWrite24BmpLine},
200
{"BMPReadWriterPlugin", "setInterpreter", (void*)setInterpreter},
205
#endif /* ifdef SQ_BUILTIN_PLUGIN */