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