yhzmr442 / jspce

PC Engine(TurboGrafx-16) Emulator written in Javascript
MIT License
2 stars 0 forks source link

Load Base64 object encode to Array buffer #1

Open shaan1974 opened 4 years ago

shaan1974 commented 4 years ago

Hello ,

I want to load a game on load of the page so.

  1. I'v create a php page in place of html :)

  2. Inside this the php part create a JS var with the binary64 encode of the file content.

<?php $binary_data = base64_encode( file_get_contents( "rom/game.pce" , false ) ); echo <<<EOF

EOF; ?>

  1. I use a function "base64ToArrayBuffer" to convert the var binaryData.

function base64ToArrayBuffer( base64 ) { var raw = window.atob( base64 ); var rawLength = raw.length; var array = new Uint8Array( new ArrayBuffer(rawLength) ); for( i = 0; i < rawLength; i++ ) { array[ i ] = raw.charCodeAt( i ); } return( array.buffer ); }

  1. I try to init the emulator

    var rom2; var u8array = new Uint8Array(binaryData); rom2 = new Array(); for(var i=0; i<u8array.length; i++) { rom2.push(u8array[i]);
    }

    pce.Init(); pce.SetROM(rom2); Start();

  2. Finaly it's start but it's really slow.

Do you have a solution for me ? :) Thanks.