Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 26 oct 2010 */
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- FILE *fin, *fout;
- typedef uint8_t byte;
- typedef uint16_t word;
- typedef uint32_t ulong;
- byte readbyte(void) { byte b; fread(&b, 1, 1, fin); return b; }
- void writebyte(byte b) { fwrite(&b, 1, 1, fout); }
- #define SEEK(k) fseek(fin, k, SEEK_SET)
- #define TELL() ftell(fin)
- void getsamp(ulong start)
- {
- word off, n;
- ulong saveaddr;
- ulong newaddr = 0;
- ulong bankbase = start & 0xFF8000;
- saveaddr = start;
- for (;;) {
- SEEK(saveaddr);
- off = readbyte();
- if (off == 0)
- break;
- off |= (readbyte() << 8);
- if (off != 0xFF)
- newaddr = bankbase + (off & 0x7FFF);
- n = readbyte();
- n |= (readbyte() << 8);
- readbyte(); readbyte(); /* skip speed and padding byte */
- saveaddr = TELL();
- SEEK(NEWADDR);
- for (; n; n--)
- writebyte(readbyte);
- }
- }
- int main(int argc, char *argv[])
- {
- ulong addr;
- fin = fopen(argv[1], "rb");
- fout = fopen(argv[2], "wb");
- addr = strtoul(argv[3], NULL, 16);
- getsamp(addr);
- fclose(fin);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement