PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
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#define MODNAME "imgdrv"
21
22IRX_ID(MODNAME, 1, 1);
23
24// Function prototypes
25static int imgdrv_read(iop_file_t *f, void *buf, int size);
26static int imgdrv_lseek(iop_file_t *f, int offset, int whence);
27
28/* The IOMAN operations structure is usually longer than this,
29 but the structure in the original was this short (probably to save space). */
31{
32 int (*init)(iop_device_t *);
33 int (*deinit)(iop_device_t *);
34 int (*format)(iop_file_t *);
35 int (*open)(iop_file_t *, const char *, int);
36 int (*close)(iop_file_t *);
37 int (*read)(iop_file_t *, void *, int);
38 int (*write)(iop_file_t *, void *, int);
39 int (*lseek)(iop_file_t *, int, int);
41
42IOMAN_RETURN_VALUE_IMPL(0);
43
44static iop_device_ops_short_t imgdrv_ops = {
45 IOMAN_RETURN_VALUE(0), // init
46 IOMAN_RETURN_VALUE(0), // deinit
47 IOMAN_RETURN_VALUE(0), // format
48 IOMAN_RETURN_VALUE(0), // open
49 IOMAN_RETURN_VALUE(0), // close
50 &imgdrv_read, // read
51 IOMAN_RETURN_VALUE(0), // write
52 &imgdrv_lseek, // lseek
53};
54
55#define MAX_IMAGES 2
56// These arrays will be manipulated by the EE-side code before the module is loaded.
57void *img[MAX_IMAGES] = {(void *)0xDEC1DEC1, 0};
58int img_size[MAX_IMAGES] = {0xDEC2DEC2, 0};
59
60static iop_device_t img_device = {
61 "img",
62 IOP_DT_FS,
63 1,
64 "img",
65 (iop_device_ops_t *)&imgdrv_ops,
66};
67
68int _start(int argc, char *argv[])
69{
70 return (AddDrv(&img_device) < 0) ? MODULE_NO_RESIDENT_END : MODULE_RESIDENT_END;
71}
72
73static int imgdrv_read(iop_file_t *f, void *buf, int size)
74{
75 int i;
76 const u32 *img_ptr;
77 u32 *img_out;
78
79 img_out = (u32 *)buf;
80 img_ptr = (const u32 *)img[f->unit];
81 for (i = size; i > 0; i -= 4, img_ptr++, img_out++)
82 *img_out = *img_ptr;
83
84 return size;
85}
86
87static int imgdrv_lseek(iop_file_t *f, int offset, int whence)
88{
89 return (whence == SEEK_SET ? 0 : img_size[f->unit]);
90}
int unit
Definition ioman.h:57