-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdrom.c
76 lines (54 loc) · 1.13 KB
/
cdrom.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
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
//#include <libisofs/libisofs.h>
//IsoDataSource *src;
FILE *fcdrom;
uint32_t lba=0;
int cdromOpenIso(char *path)
{
fcdrom=fopen(path,"rb");
if(!fcdrom)
{
printf("ERROR: can't load game file, exiting\n");
return 0;
}
printf("INFO: game file loaded succesfully\n");
return 1;
}
int cdromCloseIso()
{
fclose(fcdrom);
return 1;
}
int cdromReadBlock(void *buffer,int sector)
{
fseek (fcdrom , 2048*sector , SEEK_SET);
fread(buffer,1,2048,fcdrom);
rewind(fcdrom);
printf("reading %d\n",sector*2048);
return 1;
}
char *cdromReadSize()
{
char *buffer=(char *)malloc(sizeof(char)*4);
rewind(fcdrom);
fseek (fcdrom , 80 , SEEK_SET);
fread(buffer,1,4,fcdrom);
rewind(fcdrom);
return buffer;
}
unsigned int cdromDiscSize()
{
unsigned int size;
char sectorZero[2048];
unsigned int temp;
char *ssize;
ssize=cdromReadSize();
memcpy(&temp,ssize,4);
size=(temp & 0x000000FFU) << 24 | (temp & 0x0000FF00U) << 8 |
(temp & 0x00FF0000U) >> 8 | (temp & 0xFF000000U) >> 24;
printf("INFO: disc size: %d sectors\n",size);
return size;
}