aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS7
-rw-r--r--LICENSE8
-rw-r--r--src/library.js6
-rw-r--r--src/library_sdl.js73
-rw-r--r--src/preamble.js3
-rw-r--r--tests/files.cpp3
6 files changed, 81 insertions, 19 deletions
diff --git a/AUTHORS b/AUTHORS
index e70748be..3db02f2d 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,2 +1,7 @@
-Alon Zakai <azakai@mozilla.com>
+The following authors have all licensed their contributions to Emscripten
+under the licensing terms detailed in LICENSE.
+
+* Alon Zakai <alonzakai@gmail.com> (copyright owned by Mozilla Foundation)
+*
+*
diff --git a/LICENSE b/LICENSE
index ac26c241..6d090777 100644
--- a/LICENSE
+++ b/LICENSE
@@ -13,8 +13,7 @@ The full text of both licenses follows.
==============================================================================
-Copyright (c) 2010 Alon Zakai
-Copyright (c) 2010 Mozilla Foundation
+Copyright (c) 2010-2011 Emscripten authors, see AUTHORS file.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -36,12 +35,9 @@ THE SOFTWARE.
==============================================================================
-Copyright (c) 2010 Alon Zakai
-Copyright (c) 2010 Mozilla Foundation
+Copyright (c) 2010-2011 Emscripten authors, see AUTHORS file.
All rights reserved.
-Developed by: Alon Zakai, Mozilla
-
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal with the Software without restriction, including
diff --git a/src/library.js b/src/library.js
index b321dbc9..99626a0c 100644
--- a/src/library.js
+++ b/src/library.js
@@ -465,6 +465,7 @@ var Library = {
STDIO.write(stream, Module._fputc_ptr, 1);
},
+ getc__deps: ['$STDIO'],
getc: function(file) {
if (!Module._getc_ptr) Module._getc_ptr = _malloc(1);
var ret = STDIO.read(file, Module._getc_ptr, 1);
@@ -474,6 +475,11 @@ var Library = {
getc_unlocked: 'getc',
_IO_getc: 'getc',
+ getchar__deps: ['getc'],
+ getchar: function() {
+ return _getc(_stdin);
+ },
+
ungetc: function(chr, stream) {
var f = STDIO.streams[stream];
if (!f)
diff --git a/src/library_sdl.js b/src/library_sdl.js
index aa42f01c..40fc5e7f 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -1,5 +1,64 @@
// To use emscripten's SDL library here, you need to define
// Module.canvas and at least one of Module.ctx2D, Module.ctxGL.
+//
+// More specifically, our SDL implementation will look for
+// Module.canvas and Module.ctx2D. You should fill them using
+// something like
+//
+// function onLoad() {
+// // Pass canvas and context to the generated code
+// Module.canvas = document.getElementById('canvas');
+// Module.ctx2D = Module.canvas.getContext('2d');
+// }
+//
+// Note that this must be called during onload, since you will
+// only be able to access the canvas element in the page after
+// it loads. You will likely also want to disable running by
+// default, with something like
+//
+// var Module = {
+// noInitialRun: true
+// };
+//
+// which is defined BEFORE you load the compiled code. Here
+// is a full example:
+
+/*
+<html>
+ <head>
+ <title>Demo</title>
+ <script type='text/javascript'>
+ var Module = {
+ noInitialRun: true
+ };
+
+ // implement print
+ var print = function(text) {
+ var element = document.getElementById('output')
+ element.innerHTML = text.replace('\n', '<br>', 'g') + element.innerHTML;
+ }
+ </script>
+ <script src='doom.ccsimple.js' type='text/javascript'></script>
+ <script type='text/javascript'>
+ function onLoad() {
+ // Pass canvas and context to the generated code, and do the actual run() here
+ Module.canvas = document.getElementById('canvas');
+ Module.ctx2D = Module.canvas.getContext('2d');
+ if (!Module.ctx2D) {
+ alert('Canvas not available :(');
+ return;
+ }
+ Module.run();
+ }
+ </script>
+ <body onload='onLoad()' style='background-color: black; color: white'>
+ <center>
+ <canvas id='canvas' width='320' height='200'></canvas>
+ </center>
+ <div id='output'></div>
+ </body>
+</html>
+*/
mergeInto(Library, {
$SDL__deps: ['$Browser'],
@@ -204,14 +263,14 @@ mergeInto(Library, {
// Copy pixel data to somewhere accessible to 'C/C++'
var num2 = surfData.image.data.length;
for (var i = 0; i < num2; i++) {
- IHEAP[surfData.buffer+i] = surfData.image.data[i];
+ {{{ makeSetValue('surfData.buffer', 'i', 'surfData.image.data[i]', 'i8') }}};
}
}
// Mark in C/C++-accessible SDL structure
// SDL_Surface has the following fields: Uint32 flags, SDL_PixelFormat *format; int w, h; Uint16 pitch; void *pixels; ...
// So we have fields all of the same size, and 5 of them before us.
// TODO: Use macros like in library.js
- IHEAP[surf + 5*QUANTUM_SIZE] = surfData.buffer;
+ {{{ makeSetValue('surf', '5*QUANTUM_SIZE', 'surfData.buffer', 'void*') }}};
},
SDL_UnlockSurface: function(surf) {
@@ -220,7 +279,7 @@ mergeInto(Library, {
var num = surfData.image.data.length;
if (!surfData.colors) {
for (var i = 0; i < num; i++) {
- surfData.image.data[i] = IHEAP[surfData.buffer+i]; // XXX - make sure alpha values are proper in your input
+ surfData.image.data[i] = {{{ makeGetValue('surfData.buffer', 'i', 'i8') }}}; // XXX - make sure alpha values are proper in your input
}
} else {
var width = Module['canvas'].width;
@@ -231,7 +290,7 @@ mergeInto(Library, {
for (var y = 0; y < height; y++) {
var base = y*width*4;
for (var x = 0; x < width; x++) {
- var val = IHEAP[s++];
+ var val = {{{ makeGetValue('s++', '0', 'i8') }}};
var color = colors[val] || [Math.floor(Math.random()*255),Math.floor(Math.random()*255),Math.floor(Math.random()*255)]; // XXX
var start = base + x*4;
data[start] = color[0];
@@ -325,11 +384,7 @@ mergeInto(Library, {
var surfData = SDL.surfaces[surf];
surfData.colors = [];
for (var i = firstColor; i < nColors; i++) {
-#if USE_TYPED_ARRAYS
- surfData.colors[i] = Array.prototype.slice.call(IHEAP, colors + i*4, colors + i*4 + 4);
-#else
- surfData.colors[i] = IHEAP.slice(colors + i*4, colors + i*4 + 4);
-#endif
+ surfData.colors[i] = Array_copy(colors + i*4, colors + i*4 + 4);
}
return 1;
},
diff --git a/src/preamble.js b/src/preamble.js
index cfab022e..b5a8930a 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -589,11 +589,10 @@ if (!this['read']) {
function readBinary(filename) {
var stringy = read(filename);
- var data = new Array(stringy.length+1);
+ var data = new Array(stringy.length);
for (var i = 0; i < stringy.length; i++) {
data[i] = stringy.charCodeAt(i) & 0xff;
}
- data[stringy.length] = 0;
return data;
}
diff --git a/tests/files.cpp b/tests/files.cpp
index 202c03bb..39f9e61a 100644
--- a/tests/files.cpp
+++ b/tests/files.cpp
@@ -52,7 +52,8 @@ int main()
FILE *other = fopen("test.file", "r");
assert(other);
char otherData[1000];
- fread(otherData, 1, 10, other);
+ num = fread(otherData, 1, 9, other);
+ otherData[num] = 0;
fclose(other);
printf("other=%s.\n", otherData);