私は JavaScript エミュレーターを作成しようとしていますが、非常に軽量にしたいので、jQuery と jDataView で「ROM」をロードしたくありません。私は純粋な JS で独自の ROM ローダーを作成しました。
これはかなりうまく機能します (このサイトの多くのトピックのおかげです) が、IE にはまだ問題があり、他の場所でヘルプを見つけることができませんでした。
これが私のJSコードです:
/**
* @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
});
これが私の .htaccess です (chip8 ROM の拡張子は .ch8 です):
AddType 'text/plain; charset=x-user-defined' ch8
そして、これが私のテストROMです(バイト0x00から0xFFが含まれています)
http://www.filedropper.com/test_16
テストの結果:
Firefox と Chrome は正常に動作します: 0x00 から 0xFF までのすべてのバイトをログに記録します
IE9 も同じことを行いますが、0x80 から 0x9F までの 32 バイトはまったく無関係な数値に置き換えられます。(バイナリコードを比較しても明らかな変換ロジックはありません)
だから私の質問は:
- IE9 はこれらのバイトで何をしますか?
- どうすれば修正できますか?
あなたのアイデア(または解決策)をありがとう!
最大。