I'm trying to make a javascript emulator, and i'd like it to be very light, so I don't want to load the "ROMs" with jQuery and jDataView. Si I made my own ROM loader in pure JS.
It works pretty well (thanks to many topics on this site), but there's still a problem on IE, for which I couldn't find any help elsewhere.
Here's my JS code:
/**
* @param file - the path or URL of the ROM file to load. The file must be served with the Mime-Type: 'text/plain; charset=x-user-defined'
* @param callback - a function to call when the loading is complete. Its first parameter contains an array of numbers representing the ROM bytes.
*/
function loadRom(file, callback)
{
  var xhr = new XMLHttpRequest();                             // AJAX loader
  xhr.onreadystatechange = function(){
    if(xhr.readyState == 4){                                  // When the file content is received
      var str = xhr.responseText;                             // Store it as a string
      var ch, bytes = [];
      for (var i = 0; i < str.length; i++){
        ch = str.charCodeAt(i);                               // Read each character
        bytes.push(ch & 0xFF);                                // Store the last byte of the character
      }
      callback(bytes);                                        // Call the callback function with bytes as parameter
    }
  };
  xhr.open("GET", file, true);                                // Load the file
  xhr.send(null);                                             // Send the AJAX request
}
// Test
var mem=[];
loadRom("TEST.ch8", function(m){
  for(i=0;i<m.length;i++)console.log(m[i].toString(16))                 // Log each byte in hexa
});
Here's my .htaccess (the chip8 ROMs have the extension .ch8):
AddType 'text/plain; charset=x-user-defined' ch8
And here's my test ROM (it contains the bytes 0x00 to 0xFF)
http://www.filedropper.com/test_16
Results of the test:
Firefox and Chrome work fine: they log every byte from 0x00 to 0xFF
IE9 does the same, except for the 32 bytes between 0x80 to 0x9F, that are replaced with totally unrelated numbers. ( Even if we compare binary codes, there's no apparent conversion logic )
So my questions are:
- What does IE9 do with these bytes?
- How could I fix it?
Thanks for your ideas (or solutions)!
Max.
 
    