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