ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
imgdrv.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Licenced under Academic Free License version 2.0
7 # Review ps2sdk README & LICENSE files for further details.
8 */
9 
16 #include <ioman.h>
17 #include <irx.h>
18 #include <loadcore.h>
19 
20 //Function prototypes
21 static int imgdrv_dummy(void);
22 static int imgdrv_read(iop_file_t *f, void *buf, int size);
23 static int imgdrv_lseek(iop_file_t *f, int offset, int whence);
24 
25 /* The IOMAN operations structure is usually longer than this,
26  but the structure in the original was this short (probably to save space). */
27 typedef struct _iop_device_ops_short {
28  int (*init)(iop_device_t *);
29  int (*deinit)(iop_device_t *);
30  int (*format)(iop_file_t *);
31  int (*open)(iop_file_t *, const char *, int);
32  int (*close)(iop_file_t *);
33  int (*read)(iop_file_t *, void *, int);
34  int (*write)(iop_file_t *, void *, int);
35  int (*lseek)(iop_file_t *, int, int);
37 
39  (void*)imgdrv_dummy, //init
40  (void*)imgdrv_dummy, //deinit
41  NULL, //format
42  (void*)imgdrv_dummy, //open
43  (void*)imgdrv_dummy, //close
44  &imgdrv_read, //read
45  NULL, //write
46  &imgdrv_lseek, //lseek
47 };
48 
49 #define MAX_IMAGES 2
50 //These arrays will be manipulated by the EE-side code before the module is loaded.
51 const void *img[MAX_IMAGES] = {0};
52 int img_size[MAX_IMAGES] = {0};
53 
54 static iop_device_t img_device = {
55  "img",
56  IOP_DT_FS,
57  1,
58  "img",
59  (iop_device_ops_t*)&imgdrv_ops
60 };
61 
62 int _start(int argc, char *argv[])
63 {
64  return AddDrv(&img_device) < 0;
65 }
66 
67 static int imgdrv_dummy(void)
68 {
69  return 0;
70 }
71 
72 static int imgdrv_read(iop_file_t *f, void *buf, int size)
73 {
74  int i;
75  const u32 *img_ptr;
76  u32 *img_out;
77 
78  img_out = (u32*)buf;
79  img_ptr = (const u32*)img[f->unit];
80  for(i = size; i > 0; i-=4,img_ptr++,img_out++)
81  *img_out = *img_ptr;
82 
83  return size;
84 }
85 
86 static int imgdrv_lseek(iop_file_t *f, int offset, int whence)
87 {
88  return(whence == SEEK_SET ? 0 : img_size[f->unit]);
89 }
int img_size[MAX_IMAGES]
Definition: imgdrv.c:52
const void * img[MAX_IMAGES]
Definition: imgdrv.c:51
static int imgdrv_read(iop_file_t *f, void *buf, int size)
Definition: imgdrv.c:72
#define MAX_IMAGES
Definition: imgdrv.c:49
static iop_device_ops_short_t imgdrv_ops
Definition: imgdrv.c:38
int _start(int argc, char *argv[])
Definition: imgdrv.c:62
static int imgdrv_lseek(iop_file_t *f, int offset, int whence)
Definition: imgdrv.c:86
static iop_device_t img_device
Definition: imgdrv.c:54
static int imgdrv_dummy(void)
Definition: imgdrv.c:67
#define NULL
Definition: tamtypes.h:91
unsigned int u32
Definition: tamtypes.h:30