File: tobin.c

package info (click to toggle)
dgen 1.23-9
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 2,168 kB
  • ctags: 3,087
  • sloc: ansic: 45,403; cpp: 4,405; sh: 1,960; makefile: 116
file content (35 lines) | stat: -rw-r--r-- 843 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// A little utility to convert SMDs to BINs

#include <stdio.h>
#include <stdlib.h>

// No C header for the function, so I have to prototype them
int load_rom_into(char *name, unsigned char *into);

int main(int argc, char *argv[])
{
  int size;
  FILE *out;
  unsigned char *rom;

  if(argc < 3) { printf("Usage: %s from.smd to.bin\n", argv[0]); return 1; }
  // Get size, so we can malloc it
  size = load_rom_into(argv[1], NULL);
  if(size == -1)
    { fprintf(stderr, "Couldn't open source rom %s!\n", argv[1]); return 1; }
  rom = malloc(size);

  // Get the rom
  load_rom_into(argv[1], rom);

  // Write it to disk
  if(!(out = fopen(argv[2], "w")))
    { fprintf(stderr, "Couldn't write destination rom %s!\n", argv[2]); 
      return 1; }
  fwrite(rom, 1, size, out);
  fclose(out);
  free(rom);
  // That was easy. ;)
  return 0;
}