Mercurial > repos > blastem
comparison blastem.c @ 1682:a0aa9e3c9508
Fix SMD ROM support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 17 Jan 2019 19:14:09 -0800 |
parents | 357b4951d9b2 |
children | 7e044a84268d |
comparison
equal
deleted
inserted
replaced
1681:3f1c8258e20f | 1682:a0aa9e3c9508 |
---|---|
74 uint8_t block[SMD_BLOCK_SIZE]; | 74 uint8_t block[SMD_BLOCK_SIZE]; |
75 romseek(f, SMD_HEADER_SIZE, SEEK_SET); | 75 romseek(f, SMD_HEADER_SIZE, SEEK_SET); |
76 | 76 |
77 size_t filesize = 512 * 1024; | 77 size_t filesize = 512 * 1024; |
78 size_t readsize = 0; | 78 size_t readsize = 0; |
79 uint16_t *dst = malloc(filesize); | 79 uint16_t *dst, *buf; |
80 dst = buf = malloc(filesize); | |
80 | 81 |
81 | 82 |
82 size_t read; | 83 size_t read; |
83 do { | 84 do { |
84 if ((readsize + SMD_BLOCK_SIZE > filesize)) { | 85 if ((readsize + SMD_BLOCK_SIZE > filesize)) { |
85 filesize *= 2; | 86 filesize *= 2; |
86 dst = realloc(dst, filesize); | 87 buf = realloc(buf, filesize); |
88 dst = buf + readsize/sizeof(uint16_t); | |
87 } | 89 } |
88 read = romread(block, 1, SMD_BLOCK_SIZE, f); | 90 read = romread(block, 1, SMD_BLOCK_SIZE, f); |
89 if (read > 0) { | 91 if (read > 0) { |
90 for (uint8_t *low = block, *high = (block+read/2), *end = block+read; high < end; high++, low++) { | 92 for (uint8_t *low = block, *high = (block+read/2), *end = block+read; high < end; high++, low++) { |
91 *(dst++) = *low << 8 | *high; | 93 *(dst++) = *low << 8 | *high; |
93 readsize += read; | 95 readsize += read; |
94 } | 96 } |
95 } while(read > 0); | 97 } while(read > 0); |
96 romclose(f); | 98 romclose(f); |
97 | 99 |
98 *buffer = dst; | 100 *buffer = buf; |
99 | 101 |
100 return readsize; | 102 return readsize; |
101 } | 103 } |
102 | 104 |
103 uint32_t load_rom_zip(const char *filename, void **dst) | 105 uint32_t load_rom_zip(const char *filename, void **dst) |