]> git.sesse.net Git - pistorm/blob - platforms/amiga/piscsi/device_driver_amiga/makerom.c
[WIP] PiSCSI, Pi-NET and some other things
[pistorm] / platforms / amiga / piscsi / device_driver_amiga / makerom.c
1 #include <stdio.h>
2 #include <stdint.h>
3 #include <string.h>
4 #include <stdlib.h>
5
6 #define BOOTLDR_SIZE 0x400
7
8 char *rombuf, *zerobuf, *devicebuf;
9
10 int main(int argc, char *argv[]) {
11     FILE *rom = fopen("bootrom", "rb");
12     if (!rom) {
13         printf("Could not open file bootrom for reading.\n");
14         return 1;
15     }
16     FILE *out = fopen("../piscsi.rom", "wb+");
17     if (!out) {
18         printf("Could not open file piscsi.rom for writing.\n");
19         fclose(rom);
20         return 1;
21     }
22     FILE *device = fopen("pi-scsi.device", "rb");
23     if (!device) {
24         printf("Could not open file pi-scsi.device for reading.\n");
25         fclose(rom);
26         fclose(out);
27         return 1;
28     }
29
30     fseek(device, 0, SEEK_END);
31     fseek(rom, 0, SEEK_END);
32     uint32_t rom_size = ftell(rom);
33     uint32_t device_size = ftell(device);
34     fseek(rom, 0, SEEK_SET);
35     fseek(device, 0, SEEK_SET);
36
37     uint32_t pad_size = BOOTLDR_SIZE - rom_size;
38
39     rombuf = malloc(rom_size);
40     devicebuf = malloc(device_size);
41     zerobuf = malloc(pad_size);
42     memset(zerobuf, 0x00, pad_size);
43
44     fread(rombuf, rom_size, 1, rom);
45     fread(devicebuf, device_size, 1, device);
46
47     fwrite(rombuf, rom_size, 1, out);
48     fwrite(zerobuf, pad_size, 1, out);
49     fwrite(devicebuf, device_size, 1, out);
50
51     printf("piscsi.rom successfully created.\n");
52
53     free(rombuf);
54     free(zerobuf);
55     free(devicebuf);
56     
57     fclose(out);
58     fclose(device);
59     fclose(rom);
60
61     return 0;
62 }