1 function BitmapCanvas(){
2 this.canvasDOMObject = null;
3 this.canvasContext = null;
4 this.bufferImageData = null;
6 this.width = undefined;
7 this.height = undefined;
9 BitmapCanvas.prototype = {
10 setCanvas: function(canvasDOMObject){
11 this.canvasDOMObject = canvasDOMObject;
13 this.canvasContext = this.canvasDOMObject.getContext("2d");
14 this.width = this.canvasDOMObject.width;
15 this.height = this.canvasDOMObject.height;
16 this.bufferImageData = this.canvasContext.getImageData(0, 0, this.width, this.height);
17 this.bmp = this.bufferImageData.data;
20 this.canvasContext = null;
21 this.bufferImageData = null;
22 this.width = undefined;
23 this.height = undefined;
26 drawPoint: function(x, y, color, mode){
28 if(mode === undefined){
40 this.bmp[4 * (y * this.width + x) + 0] = (color >> 16) & 0xFF;
41 this.bmp[4 * (y * this.width + x) + 1] = (color >> 8) & 0xFF;
42 this.bmp[4 * (y * this.width + x) + 2] = color & 0xFF;
45 this.bmp[4 * (y * this.width + x) + 0] |= (color >> 16) & 0xFF;
46 this.bmp[4 * (y * this.width + x) + 1] |= (color >> 8) & 0xFF;
47 this.bmp[4 * (y * this.width + x) + 2] |= color & 0xFF;
50 this.bmp[4 * (y * this.width + x) + 0] ^= (color >> 16) & 0xFF;
51 this.bmp[4 * (y * this.width + x) + 1] ^= (color >> 8) & 0xFF;
52 this.bmp[4 * (y * this.width + x) + 2] ^= color & 0xFF;
55 this.bmp[4 * (y * this.width + x) + 0] &= (color >> 16) & 0xFF;
56 this.bmp[4 * (y * this.width + x) + 1] &= (color >> 8) & 0xFF;
57 this.bmp[4 * (y * this.width + x) + 2] &= color & 0xFF;
61 drawLine: function(x0, y0, x1, y1, color, mode){
100 for(var i = 0; i < l; i++){
101 this.drawPoint(x0 + dx * i, y0 + dy * i, color, mode);
104 fillRect: function(xSize, ySize, x0, y0, col, mode){
107 fillOval: function(xSize, ySize, x0, y0, col, mode){
111 if(this.bufferImageData){
112 this.canvasContext.putImageData(this.bufferImageData, 0, 0);
117 function WebCPU_API(){
118 this.mainWindowCanvas = null;
119 this.mainWindowContext = null;
120 //this.mainWindowBufferCanvas = document.createElement('canvas');
121 //this.mainWindowBufferContext = this.mainWindowBufferCanvas.getContext("2d");
123 this.bitmapCanvas = new BitmapCanvas();
125 //this.mainWindowBufferCanvas.width = 640;
126 //this.mainWindowBufferCanvas.height = 480;
127 //this.initCanvas(this.mainWindowBufferCanvas);
129 WebCPU_API.prototype = {
130 executeAPI: function(env){
131 var r = env.registers.Integer;
136 this.API_openWin(env, r[0x31], r[0x32])
140 this.API_flushWin(env, r[0x31], r[0x32], r[0x33], r[0x34])
144 this.API_drawPoint(env, r[0x31], r[0x32], r[0x33], r[0x34]);
148 this.API_drawLine(env, r[0x31], r[0x32], r[0x33], r[0x34], r[0x35], r[0x36]);
152 this.API_fillRect(env, r[0x31], r[0x32], r[0x33], r[0x34], r[0x35], r[0x36]);
156 this.API_fillOval(env, r[0x31], r[0x32], r[0x33], r[0x34], r[0x35], r[0x36]);
159 throw new WebCPU_Exception(0, ["Unknown API Number " + APIID.toString(16)]);
161 env.goToPointerRegister(0x30);
173 setMainWindowCanvasDOMObject: function(obj){
174 this.mainWindowCanvas = obj;
175 if(this.mainWindowCanvas){
176 this.mainWindowContext = this.mainWindowCanvas.getContext('2d')
177 this.initCanvas(this.mainWindowCanvas);
179 this.bitmapCanvas.setCanvas(this.mainWindowCanvas);
181 this.mainWindowContext = null;
184 initCanvas: function(c){
185 var d = c.getContext('2d');
186 d.fillStyle = "rgba(0,0,0,1)";
187 d.strokeStyle = "rgba(255, 255, 255, 1)";
190 d.fillRect(0, 0, c.width, c.height);
193 API_openWin: function(env, xSize, ySize){
194 env.message("junkApi_openWin();\n", 20);
195 this.mainWindowCanvas.width = xSize;
196 this.mainWindowCanvas.height = ySize;
197 //this.mainWindowBufferCanvas.width = xSize;
198 //this.mainWindowBufferCanvas.height = ySize;
199 this.initCanvas(this.mainWindowCanvas);
200 this.bitmapCanvas.setCanvas(this.mainWindowCanvas);
202 API_flushWin: function(env, xSize, ySize, x0, y0){
203 env.message("junkApi_flushWin();\n", 20);
204 //this.mainWindowContext.drawImage(this.mainWindowBufferCanvas, x0, y0, xSize, ySize, 0, 0, xSize, ySize);
205 this.bitmapCanvas.flush();
207 API_drawPoint: function(env, mode, x, y, col){
208 env.message("junkApi_drawPoint();\n", 20);
209 if((mode & 0x04) != 0){
210 col = this.colorTable[col];
212 //this.mainWindowBufferContext.fillStyle = "#" + ("000000" + col.toString(16)).slice(-6).toUpperCase();
213 //this.mainWindowBufferContext.fillRect(x, y, 1, 1);
214 this.bitmapCanvas.drawPoint(x, y, col, mode);
216 API_drawLine: function(env, mode, x0, y0, x1, y1, col){
217 env.message("junkApi_drawLine();\n", 20);
219 if((mode & 0x04) != 0){
220 col = this.colorTable[col];
223 this.mainWindowBufferContext.strokeStyle = "#" + ("000000" + col.toString(16)).slice(-6).toUpperCase();
224 this.mainWindowBufferContext.beginPath();
225 this.mainWindowBufferContext.moveTo(x0, y0);
226 this.mainWindowBufferContext.lineTo(x1, y1);
227 this.mainWindowBufferContext.closePath();
228 this.mainWindowBufferContext.stroke();
230 this.bitmapCanvas.drawLine(x0, y0, x1, y1, col, mode);
232 API_fillRect: function(env, mode, xSize, ySize, x0, y0, col){
233 env.message("junkApi_fillRect();\n", 20);
235 if((mode & 0x04) != 0){
236 col = this.colorTable[col];
239 this.mainWindowBufferContext.fillStyle = "#" + ("000000" + col.toString(16)).slice(-6).toUpperCase();
240 this.mainWindowBufferContext.fillRect(x0, y0, xSize, ySize);
243 API_fillOval: function(env, mode, xSize, ySize, x0, y0, col){
244 env.message("junkApi_fillRect();\n", 20);
246 if((mode & 0x04) != 0){
247 col = this.colorTable[col];
250 this.mainWindowBufferContext.fillStyle = "#" + ("000000" + col.toString(16)).slice(-6).toUpperCase();
251 this.mainWindowBufferContext.fillEllipse(x0, y0, xSize, ySize);