static int machine_load_rom_bank_from_file( memory_page* bank_map, int page_num, const char *filename, size_t expected_length, int custom ) { int error; utils_file rom; error = utils_read_auxiliary_file( filename, &rom, UTILS_AUXILIARY_ROM ); if( error == -1 ) { ui_error( UI_ERROR_ERROR, "couldn't find ROM '%s'", filename ); return 1; } if( error ) return error; if( rom.length != expected_length ) { ui_error( UI_ERROR_ERROR, "ROM '%s' is %ld bytes long; expected %ld bytes", filename, (unsigned long)rom.length, (unsigned long)expected_length ); utils_close_file( &rom ); return 1; } error = machine_load_rom_bank_from_buffer( bank_map, page_num, rom.buffer, rom.length, custom ); utils_close_file( &rom ); return error; }
static int machine_load_rom_bank_from_file( memory_page* bank_map, size_t which, int page_num, const char *filename, size_t expected_length, int custom ) { compat_fd fd; int error; utils_file rom; fd = utils_find_auxiliary_file( filename, UTILS_AUXILIARY_ROM ); if( fd == COMPAT_FILE_OPEN_FAILED ) { ui_error( UI_ERROR_ERROR, "couldn't find ROM '%s'", filename ); return 1; } error = utils_read_fd( fd, filename, &rom ); if( error ) return error; if( rom.length != expected_length ) { ui_error( UI_ERROR_ERROR, "ROM '%s' is %ld bytes long; expected %ld bytes", filename, (unsigned long)rom.length, (unsigned long)expected_length ); utils_close_file( &rom ); return 1; } error = machine_load_rom_bank_from_buffer( bank_map, which, page_num, rom.buffer, rom.length, custom ); error |= utils_close_file( &rom ); return error; }
static void didaktik_from_snapshot( libspectrum_snap *snap ) { int i; if( !libspectrum_snap_didaktik80_active( snap ) ) return; if( libspectrum_snap_didaktik80_custom_rom( snap ) && libspectrum_snap_didaktik80_rom( snap, 0 ) && machine_load_rom_bank_from_buffer( didaktik_memory_map_romcs_rom, 0, libspectrum_snap_didaktik80_rom( snap, 0 ), ROM_SIZE, 1 ) ) return; if( libspectrum_snap_didaktik80_ram( snap, 0 ) ) { for( i = 0; i < MEMORY_PAGES_IN_2K; i++ ) memcpy( didaktik_memory_map_romcs_ram[ i ].page, libspectrum_snap_didaktik80_ram( snap, 0 ) + i * MEMORY_PAGE_SIZE, MEMORY_PAGE_SIZE ); } /* ignore drive count for now, there will be an issue with loading snaps where drives have been disabled libspectrum_snap_didaktik80_drive_count( snap ) */ didaktik_fdc->direction = libspectrum_snap_plusd_direction( snap ); didaktik_cr_write ( 0x0081, libspectrum_snap_didaktik80_status ( snap ) ); didaktik_tr_write ( 0x0083, libspectrum_snap_didaktik80_track ( snap ) ); didaktik_sec_write( 0x0085, libspectrum_snap_didaktik80_sector ( snap ) ); didaktik_dr_write ( 0x0087, libspectrum_snap_didaktik80_data ( snap ) ); didaktik_aux_write( 0x0089, libspectrum_snap_didaktik80_aux ( snap ) ); if( libspectrum_snap_didaktik80_paged( snap ) ) { didaktik80_page(); } else { didaktik80_unpage(); } }