-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileIO.c
64 lines (45 loc) · 1.03 KB
/
fileIO.c
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Nibble Knowlege
* ------------------------------------------------------
* FileName: fileIO.c
* Description: Contains file IO functions
*
* Original Creator: Colton Schmidt
* Date of Creation: 06/10/15
* Last Editor: Colton Schmidt
* Date of Last Edit: 06/10/15
*/
//Includes
#include "ram.h"
int readBin(const char* fileName, uint16_t memLocation){
unsigned char buffer = 0;
nibble temp2;
nibble temp;
int counter = 0;
FILE *binFilePtr;
printf("Reading file...\n");
//Open the Bin File
binFilePtr = fopen(fileName, "rb");
if(!binFilePtr){
printf("Unable to open .bin file\n");
return 1;
}
while(1){
//Read a nibble at a time
fread(&buffer, sizeof(buffer), 1, binFilePtr);
temp.data = buffer;
//Check for end of File
if(feof(binFilePtr))
break;
//Store in Mem
temp2.data = (buffer >> 4);
writeMem( temp2, memLocation );
memLocation += 1;
writeMem(temp, memLocation);
memLocation++;
counter++; counter++;
}
fclose(binFilePtr);
printf("Finished reading file\n");
return counter/5;
}