sint32 EMU_CALL psx_init(void) { sint32 r; psx_endian_check(); psx_size_check(); // BIOS must be loaded first if ( !bios_get_image_native() || !bios_get_imagesize() ) return 0; // // BIOS must be a power of 2, or all hell breaks loose // { uint32 s = bios_get_imagesize(); if(s & (s - 1)) psx_hang("imagesize error"); } // // Environment inits // ps1preboot = getenvhex("ps1preboot"); ps2preboot = getenvhex("ps2preboot"); r = iop_init(); if(r) return r; r = ioptimer_init(); if(r) return r; r = r3000_init(); if(r) return r; r = spu_init(); if(r) return r; r = spucore_init(); if(r) return r; r = vfs_init(); if(r) return r; library_was_initialized = 1; return 0; }
// slightly refactored original heplug.c logic here... int he_install_bios(const char *he_bios_path) { // dumpComressedHeBios(); // tmp utility if ( !bios_get_imagesize() ) { // if ((he_bios_path == 0) || !strlen(he_bios_path)) { #ifdef BUILTIN_HEBIOS // use built-in hebios void * he_bios = malloc( HEBIOS_SIZE ); long hebios_size= HEBIOS_SIZE; if (Z_OK != uncompress(he_bios, &hebios_size, zhebios, zhebios_size)) { trace( "he: BIOS uncompress error\n" ); return -1; } if (hebios_size != HEBIOS_SIZE) { trace( "he: BIOS uncompress mismatch\n" ); return -1; } bios_set_image( he_bios, hebios_size ); trace( "he: using built-in hebios\n" ); #else // } else { // install specific bios if ( !*he_bios_path ) { trace( "he: no BIOS set\n" ); return -1; } FILE * f = psf_file_fopen( he_bios_path ); if ( !f ) { trace( "he: failed to open bios %s\n", he_bios_path ); return -1; } void * ps2_bios = malloc( 0x400000 ); if ( !ps2_bios ) { psf_file_fclose( f ); trace( "he: out of memory\n" ); return -1; } int compressionEnabled= 1; size_t ps2_bios_size= 0; if (compressionEnabled && isCompressed(he_bios_path)) { size_t compressed_size = em_fgetlength( f ); if (tmp_bios_buffer) { free(tmp_bios_buffer);} tmp_bios_buffer= malloc( compressed_size ); if ( psf_file_fread( tmp_bios_buffer, 1, compressed_size, f ) < compressed_size ) { free( tmp_bios_buffer ); psf_file_fclose( f ); trace( "he: error reading compressed bios\n" ); return -1; } ps2_bios_size= inflate2(tmp_bios_buffer, compressed_size, ps2_bios, 0x400000); if (ps2_bios_size < 0x400000) { free( ps2_bios ); psf_file_fclose( f ); trace( "he: could not uncompress bios\n" ); return -1; } } else { size_t ps2_bios_size = em_fgetlength( f ); if ( ps2_bios_size != 0x400000 ) { psf_file_fclose( f ); trace( "he: bios is wrong size\n" ); return -1; } if ( psf_file_fread( ps2_bios, 1, 0x400000, f ) < 0x400000 ) { free( ps2_bios ); psf_file_fclose( f ); trace( "he: error reading bios\n" ); return -1; } psf_file_fclose( f ); } int bios_size = 0x400000; void * he_bios = mkhebios_create( ps2_bios, &bios_size ); trace( "he: fucko - %p, %p, %u\n", ps2_bios, he_bios, bios_size ); free( ps2_bios ); if ( !he_bios ) { trace( "he: error processing bios\n" ); return -1; } bios_set_image( he_bios, bios_size ); // } #endif } return 0; }