File: WeDoPlugin.c.svn-base

package info (click to toggle)
squeak-plugins-scratch 1.4.0.2~svn.r83-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 584 kB
  • sloc: ansic: 1,360; makefile: 88; sh: 88
file content (111 lines) | stat: -rw-r--r-- 2,725 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Automatically generated from Squeak on (12 May 2009 3:14:29 pm) */

#if defined(WIN32) || defined(_WIN32) || defined(Win32)
 #ifdef __cplusplus
  #define DLLEXPORT extern "C" __declspec(dllexport)
 #else
  #define DLLEXPORT __declspec(dllexport)
 #endif /* C++ */
#else
 #define DLLEXPORT
#endif /* WIN32 */

#include "sqVirtualMachine.h"

/* memory access macros */
#define byteAt(i) (*((unsigned char *) (i)))
#define byteAtput(i, val) (*((unsigned char *) (i)) = val)
#define longAt(i) (*((int *) (i)))
#define longAtput(i, val) (*((int *) (i)) = val)

/* WeDo Functions */
int WeDoOpenPort(void);
int WeDoClosePort(void);
int WeDoRead(char *bufPtr, int bufSize);
int WeDoWrite(char *bufPtr, int bufSize);


/*** Variables ***/
struct VirtualMachine* interpreterProxy;
const char *moduleName = "WeDoPlugin 12 May 2009 (e)";

/*** Functions ***/
DLLEXPORT int primClosePort(void);
DLLEXPORT int primOpenPort(void);
DLLEXPORT int primRead(void);
DLLEXPORT int primWrite(void);
DLLEXPORT int setInterpreter(struct VirtualMachine* anInterpreter);

DLLEXPORT int primClosePort(void) {
	interpreterProxy->success(WeDoClosePort());
	return 0;
}

DLLEXPORT int primOpenPort(void) {
	interpreterProxy->success(WeDoOpenPort());
	return 0;
}

DLLEXPORT int primRead(void) {
	char *bufPtr;
	int bufSize;
	int bufOop;
	int byteCount;

	bufOop = interpreterProxy->stackValue(0);
	if (((bufOop & 1)) || (!(interpreterProxy->isBytes(bufOop)))) {
		interpreterProxy->success(0);
		return 0;
	}
	bufPtr = ((char *) (interpreterProxy->firstIndexableField(bufOop)));
	bufSize = interpreterProxy->stSizeOf(bufOop);
	if (interpreterProxy->failed()) {
		return 0;
	}
	byteCount = WeDoRead(bufPtr, bufSize);
	if (byteCount < 0) {
		interpreterProxy->success(0);
		return 0;
	}
	interpreterProxy->pop(2);
	interpreterProxy->pushInteger(byteCount);
	return 0;
}

DLLEXPORT int primWrite(void) {
	char *bufPtr;
	int bufSize;
	int bufOop;
	int byteCount;

	bufOop = interpreterProxy->stackValue(0);
	if (((bufOop & 1)) || (!(interpreterProxy->isBytes(bufOop)))) {
		interpreterProxy->success(0);
		return 0;
	}
	bufPtr = ((char *) (interpreterProxy->firstIndexableField(bufOop)));
	bufSize = interpreterProxy->stSizeOf(bufOop);
	if (interpreterProxy->failed()) {
		return 0;
	}
	byteCount = WeDoWrite(bufPtr, bufSize);
	if (byteCount < 0) {
		interpreterProxy->success(0);
		return 0;
	}
	interpreterProxy->pop(2);
	interpreterProxy->pushInteger(byteCount);
	return 0;
}

DLLEXPORT int setInterpreter(struct VirtualMachine* anInterpreter) {
	int ok;

	interpreterProxy = anInterpreter;
	ok = interpreterProxy->majorVersion() == VM_PROXY_MAJOR;
	if (ok == 0) {
		return 0;
	}
	ok = interpreterProxy->minorVersion() >= VM_PROXY_MINOR;
	return ok;
}