bios.c (969B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include "bios.h" 5 #include "types.h" 6 7 extern const unsigned char scph5501_bin[]; 8 extern const unsigned int scph5501_bin_len; 9 10 BIOS* 11 BIOS_new(const char* path) 12 { 13 BIOS *b; 14 (void)path; 15 //long pos; 16 //FILE* f; 17 18 //f = fopen(path, "rb"); 19 //if (f == NULL) 20 //{ 21 // perror("ERROR"); 22 // exit(EXIT_FAILURE); 23 //} 24 25 //fseek(f, 0, SEEK_END); 26 27 //pos = ftell(f); 28 ///* If not 512KB then exit */ 29 //if (pos != 512*1024) 30 //{ 31 // fprintf(stderr, "INVALID BIOS_SIZE\n"); exit(1); 32 //} 33 34 //fseek(f, 0, SEEK_SET); 35 36 b = (BIOS*)malloc(sizeof(BIOS)); 37 b->data = malloc(scph5501_bin_len); 38 39 memcpy(b->data, scph5501_bin, scph5501_bin_len); 40 41 //fclose(f); 42 43 return b; 44 } 45 46 u32 47 BIOS_load32(BIOS* b, u32 offset) 48 { 49 return (b->data[offset + 3] << 24) | 50 (b->data[offset + 2] << 16) | 51 (b->data[offset + 1] << 8) | 52 (b->data[offset + 0]); 53 } 54 55 u8 BIOS_load8(BIOS* b, u32 offset) { return b->data[offset]; }