| 4025 | }; |
| 4026 | |
| 4027 | struct zfile *read_executable_rom(struct zfile *z, int size, int maxblocks) |
| 4028 | { |
| 4029 | int len, outlen; |
| 4030 | uae_u8 *out; |
| 4031 | uae_u8 *file = zfile_getdata(z, 0, -1, &len); |
| 4032 | if (!file) |
| 4033 | return NULL; |
| 4034 | if (!debugmem_initialized) |
| 4035 | debugmem_init(false); |
| 4036 | if (!debugmem_initialized) |
| 4037 | return NULL; |
| 4038 | uae_u8 header[8] = { 0 }; |
| 4039 | zfile_fseek(z, 0, SEEK_SET); |
| 4040 | zfile_fread(header, 1, sizeof(header), z); |
| 4041 | zfile_fseek(z, 0, SEEK_SET); |
| 4042 | if (header[0] == 0x7f) |
| 4043 | out = loadelffile(file, len, NULL, 0, 0, -1, &outlen, NULL, NULL, ELFMODE_ROM); |
| 4044 | else |
| 4045 | out = loadhunkfile(file, len, 0, -1, &outlen, true); |
| 4046 | if (out) { |
| 4047 | if (outlen > size * maxblocks) { |
| 4048 | write_log(_T("read_executable_rom '%s' size %d larger than max %d\n"), zfile_getname(z), outlen, size); |
| 4049 | xfree(out); |
| 4050 | return NULL; |
| 4051 | } |
| 4052 | int romsize = ((outlen + size - 1) / size) * size; |
| 4053 | uae_u8 *temp = xcalloc(uae_u8, romsize); |
| 4054 | memcpy(temp, out, outlen); |
| 4055 | if (outlen < romsize && romsize == 524288) { |
| 4056 | if (outlen < size - 16) { |
| 4057 | memcpy(temp + size - 20, romend, sizeof(romend)); |
| 4058 | } |
| 4059 | kickstart_fix_checksum(temp, size); |
| 4060 | } |
| 4061 | struct zfile *zo = zfile_fopen_empty(NULL, zfile_getname(z), romsize); |
| 4062 | zfile_fwrite(temp, 1, romsize, zo); |
| 4063 | zfile_fseek(zo, 0, SEEK_SET); |
| 4064 | write_log(_T("read_executable_rom loaded '%s' size %d -> %d\n"), zfile_getname(z), outlen, romsize); |
| 4065 | return zo; |
| 4066 | } |
| 4067 | xfree(file); |
| 4068 | return NULL; |
| 4069 | } |
no test coverage detected