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;
18 console.log(this.bufferImageData);
21 for(var i = 0; i < 100; i += 2){
22 this.drawLine(0, i, 100, i, 0xffffff, 0);
28 this.drawLine(x0, y0, x1, y1, 0xff0000, 0);
29 this.drawLine(x1, y1, x0, y0, 0x00ff00, 1);
34 this.canvasContext = null;
35 this.bufferImageData = null;
36 this.width = undefined;
37 this.height = undefined;
40 drawPoint: function(x, y, color, mode){
42 if(mode === undefined){
54 this.bmp[4 * (y * this.width + x) + 0] = (color >> 16) & 0xFF;
55 this.bmp[4 * (y * this.width + x) + 1] = (color >> 8) & 0xFF;
56 this.bmp[4 * (y * this.width + x) + 2] = color & 0xFF;
59 this.bmp[4 * (y * this.width + x) + 0] |= (color >> 16) & 0xFF;
60 this.bmp[4 * (y * this.width + x) + 1] |= (color >> 8) & 0xFF;
61 this.bmp[4 * (y * this.width + x) + 2] |= color & 0xFF;
64 this.bmp[4 * (y * this.width + x) + 0] ^= (color >> 16) & 0xFF;
65 this.bmp[4 * (y * this.width + x) + 1] ^= (color >> 8) & 0xFF;
66 this.bmp[4 * (y * this.width + x) + 2] ^= color & 0xFF;
69 this.bmp[4 * (y * this.width + x) + 0] &= (color >> 16) & 0xFF;
70 this.bmp[4 * (y * this.width + x) + 1] &= (color >> 8) & 0xFF;
71 this.bmp[4 * (y * this.width + x) + 2] &= color & 0xFF;
75 drawLine: function(x0, y0, x1, y1, color, mode){
114 for(var i = 0; i < l; i++){
115 this.drawPoint(x0 + dx * i, y0 + dy * i, color, mode);
118 fillRect: function(xSize, ySize, x0, y0, col, mode){
121 fillOval: function(xSize, ySize, x0, y0, col, mode){
125 if(this.bufferImageData){
126 this.canvasContext.putImageData(this.bufferImageData, 0, 0);
131 function WebCPU_API(){
132 this.mainWindowCanvas = null;
133 this.mainWindowContext = null;
134 //this.mainWindowBufferCanvas = document.createElement('canvas');
135 //this.mainWindowBufferContext = this.mainWindowBufferCanvas.getContext("2d");
137 this.bitmapCanvas = new BitmapCanvas();
139 //this.mainWindowBufferCanvas.width = 640;
140 //this.mainWindowBufferCanvas.height = 480;
141 //this.initCanvas(this.mainWindowBufferCanvas);
143 WebCPU_API.prototype = {
144 executeAPI: function(env){
145 var r = env.registers.Integer;
150 this.API_openWin(env, r[0x31], r[0x32])
154 this.API_flushWin(env, r[0x31], r[0x32], r[0x33], r[0x34])
158 this.API_drawPoint(env, r[0x31], r[0x32], r[0x33], r[0x34]);
162 this.API_drawLine(env, r[0x31], r[0x32], r[0x33], r[0x34], r[0x35], r[0x36]);
166 this.API_fillRect(env, r[0x31], r[0x32], r[0x33], r[0x34], r[0x35], r[0x36]);
170 this.API_fillOval(env, r[0x31], r[0x32], r[0x33], r[0x34], r[0x35], r[0x36]);
173 throw new WebCPU_Exception(0, ["Unknown API Number " + APIID.toString(16)]);
175 env.goToPointerRegister(0x30);
187 setMainWindowCanvasDOMObject: function(obj){
188 this.mainWindowCanvas = obj;
189 if(this.mainWindowCanvas){
190 this.mainWindowContext = this.mainWindowCanvas.getContext('2d')
191 this.initCanvas(this.mainWindowCanvas);
193 this.bitmapCanvas.setCanvas(this.mainWindowCanvas);
195 this.mainWindowContext = null;
198 initCanvas: function(c){
199 var d = c.getContext('2d');
200 d.fillStyle = "rgba(0,0,0,1)";
201 d.strokeStyle = "rgba(255, 255, 255, 1)";
204 d.fillRect(0, 0, c.width, c.height);
207 API_openWin: function(env, xSize, ySize){
208 env.message("junkApi_openWin();\n", 20);
209 this.mainWindowCanvas.width = xSize;
210 this.mainWindowCanvas.height = ySize;
211 //this.mainWindowBufferCanvas.width = xSize;
212 //this.mainWindowBufferCanvas.height = ySize;
213 this.initCanvas(this.mainWindowCanvas);
214 this.bitmapCanvas.setCanvas(this.mainWindowCanvas);
216 API_flushWin: function(env, xSize, ySize, x0, y0){
217 env.message("junkApi_flushWin();\n", 20);
218 //this.mainWindowContext.drawImage(this.mainWindowBufferCanvas, x0, y0, xSize, ySize, 0, 0, xSize, ySize);
219 this.bitmapCanvas.flush();
221 API_drawPoint: function(env, mode, x, y, col){
222 env.message("junkApi_drawPoint();\n", 20);
223 if((mode & 0x04) != 0){
224 col = this.colorTable[col];
226 //this.mainWindowBufferContext.fillStyle = "#" + ("000000" + col.toString(16)).slice(-6).toUpperCase();
227 //this.mainWindowBufferContext.fillRect(x, y, 1, 1);
228 this.bitmapCanvas.drawPoint(x, y, col, mode);
230 API_drawLine: function(env, mode, x0, y0, x1, y1, col){
231 env.message("junkApi_drawLine();\n", 20);
233 if((mode & 0x04) != 0){
234 col = this.colorTable[col];
237 this.mainWindowBufferContext.strokeStyle = "#" + ("000000" + col.toString(16)).slice(-6).toUpperCase();
238 this.mainWindowBufferContext.beginPath();
239 this.mainWindowBufferContext.moveTo(x0, y0);
240 this.mainWindowBufferContext.lineTo(x1, y1);
241 this.mainWindowBufferContext.closePath();
242 this.mainWindowBufferContext.stroke();
244 this.bitmapCanvas.drawLine(x0, y0, x1, y1, col, mode);
246 API_fillRect: function(env, mode, xSize, ySize, x0, y0, col){
247 env.message("junkApi_fillRect();\n", 20);
249 if((mode & 0x04) != 0){
250 col = this.colorTable[col];
253 this.mainWindowBufferContext.fillStyle = "#" + ("000000" + col.toString(16)).slice(-6).toUpperCase();
254 this.mainWindowBufferContext.fillRect(x0, y0, xSize, ySize);
257 API_fillOval: function(env, mode, xSize, ySize, x0, y0, col){
258 env.message("junkApi_fillRect();\n", 20);
260 if((mode & 0x04) != 0){
261 col = this.colorTable[col];
264 this.mainWindowBufferContext.fillStyle = "#" + ("000000" + col.toString(16)).slice(-6).toUpperCase();
265 this.mainWindowBufferContext.fillEllipse(x0, y0, xSize, ySize);