ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/ps2launchargs/source/uLaunchELF/hdl_info/hdd.c
Revision: 1101
Committed: Wed Feb 7 05:08:54 2018 UTC (7 years, 8 months ago) by iritscen
Content type: text/x-csrc
File size: 5963 byte(s)
Log Message:
Added following to ps2launchargs:\n-Source code.\n-DLL needed to run ps2client.\n-Instructions for building uLaunchELF.

File Contents

# Content
1 //--------------------------------------------------------------
2 //File name: hdd.c
3 //--------------------------------------------------------------
4 #include <thbase.h>
5 #include <sysclib.h>
6 #include <stdio.h>
7 #include <sysmem.h>
8 #include <dev9.h>
9 #include <atad.h>
10
11 #include "ps2_hdd.h"
12 #include "hdd.h"
13 #include "hdl.h"
14 #include "apa.h"
15
16 static hdl_games_list_t *games = NULL;
17 static hio_t *hio = NULL;
18
19 //--------------------------------------------------------------
20 static int iop_stat(hio_t *hio, u_long *size_in_kb)
21 {
22 hio_iop_t *iop = (hio_iop_t*) hio;
23 *size_in_kb = iop->size_in_sectors / 2;
24 return 0;
25 }
26 //------------------------------
27 //endfunc iop_stat
28 //--------------------------------------------------------------
29 static int iop_read(hio_t *hio, u_long start_sector, u_long num_sectors, void *output, u_long *bytes)
30 {
31 hio_iop_t *iop = (hio_iop_t*) hio;
32 int result = ata_device_dma_transfer(iop->unit, output, start_sector, num_sectors, ATA_DIR_READ);
33 if (result == 0)
34 {
35 *bytes = num_sectors * HDD_SECTOR_SIZE;
36 return 0;
37 }
38 else return -1;
39 }
40 //------------------------------
41 //endfunc iop_read
42 //--------------------------------------------------------------
43 static int iop_write(hio_t *hio, u_long start_sector, u_long num_sectors, const void *input, u_long *bytes)
44 {
45 hio_iop_t *iop = (hio_iop_t*) hio;
46 int result = ata_device_dma_transfer(iop->unit, (char*) input, start_sector, num_sectors, ATA_DIR_WRITE);
47 if (result == 0)
48 {
49 *bytes = num_sectors * HDD_SECTOR_SIZE;
50 return 0;
51 }
52 return -1;
53 }
54 //------------------------------
55 //endfunc iop_write
56 //--------------------------------------------------------------
57 static int iop_flush(hio_t *hio)
58 {
59 hio_iop_t *iop = (hio_iop_t*) hio;
60 int result = ata_device_flush_cache(iop->unit);
61 return result;
62 }
63 //------------------------------
64 //endfunc iop_flush
65 //--------------------------------------------------------------
66 static int iop_close(hio_t *hio)
67 {
68 FreeSysMemory (hio);
69 return 0;
70 }
71 //------------------------------
72 //endfunc iop_close
73 //--------------------------------------------------------------
74 static int iop_poweroff (hio_t *hio)
75 {
76 /* dev9 shutdown; borrowed from ps2link */
77 dev9IntrDisable(-1);
78 dev9Shutdown();
79
80 *((unsigned char *) 0xbf402017) = 0x00;
81 *((unsigned char *) 0xbf402016) = 0x0f;
82 return 0;
83 }
84 //------------------------------
85 //endfunc iop_poweroff
86 //--------------------------------------------------------------
87 static hio_t* iop_alloc (int unit, size_t size_in_sectors)
88 {
89 hio_iop_t *iop = AllocSysMemory (0, sizeof (hio_iop_t), NULL);
90 if (iop != NULL)
91 {
92 hio_t *hio = &iop->hio;
93 hio->stat = &iop_stat;
94 hio->read = &iop_read;
95 hio->write = &iop_write;
96 hio->flush = &iop_flush;
97 hio->close = &iop_close;
98 hio->poweroff = &iop_poweroff;
99 iop->unit = unit;
100 iop->size_in_sectors = size_in_sectors;
101 }
102 return ((hio_t*) iop);
103 }
104 //------------------------------
105 //endfunc iop_alloc
106 //--------------------------------------------------------------
107 int hio_iop_probe (const char *path, hio_t **hio)
108 {
109 if (path[0] == 'h' &&
110 path[1] == 'd' &&
111 path[2] == 'd' &&
112 (path[3] >= '0' && path[3] <= '9') &&
113 path[4] == ':' &&
114 path[5] == '\0')
115 {
116 int unit = path [3] - '0';
117 ata_devinfo_t *dev_info = ata_get_devinfo(unit);
118 if (dev_info != NULL && dev_info->exists)
119 {
120 *hio = iop_alloc (unit, dev_info->total_sectors);
121 if (*hio != NULL)
122 return (0);
123 else
124 return -2;
125 }
126 }
127 return 14;
128 }
129 //------------------------------
130 //endfunc hio_iop_probe
131 //--------------------------------------------------------------
132 int HdlGetGameInfo(char *PartName, GameInfo *GameInf){
133
134 int i, count=0, err;
135
136 hdl_glist_free(games); games = NULL;
137 if (hio != NULL) hio->close(hio); hio = NULL;
138
139 if(hio_iop_probe("hdd0:", &hio) == 0){
140 if((err = hdl_glist_read(hio, &games)) == 0){
141 for (i=0; i<games->count; ++i){
142 const hdl_game_info_t *game = &games->games[i];
143
144 if(!strcmp(PartName, game->partition_name)){
145 strcpy(GameInf->Partition_Name, game->partition_name);
146 strcpy(GameInf->Name, game->name);
147 strcpy(GameInf->Startup, game->startup);
148 GameInf->Is_Dvd = game->is_dvd;
149 return 0; //Return flag for no error
150 }
151 ++count;
152 } /* for */
153 return -3; //Return error flag for 'Game not found'
154 } /* if */
155 return err; //Return error flag for 'hdl_glist_read failed'
156 } /* if */
157 return -1; //Return error flag for 'hio_iop_probe failed'
158 }
159 //------------------------------
160 //endfunc HdlGetGameInfo
161 //--------------------------------------------------------------
162
163 int HdlRenameGame(void *Data){
164
165 int i, count=0, err;
166
167 int *Pointer = Data;
168 Rpc_Packet_Send_Rename *Packet = (Rpc_Packet_Send_Rename *)Pointer;
169
170 hdl_glist_free(games); games = NULL;
171 if (hio != NULL) hio->close(hio); hio = NULL;
172
173 if(hio_iop_probe("hdd0:", &hio) == 0){
174 if((err = hdl_glist_read(hio, &games)) == 0){
175 for (i=0; i<games->count; ++i){
176 hdl_game_info_t *game = &games->games[i];
177
178 if(!strcmp(Packet->OldName, game->name)){
179 printf("Renaming Game %s To %s.\n", game->name, Packet->NewName);
180 strcpy(game->name, Packet->NewName);
181 if((err = hdl_glist_write(hio, game))==0)
182 return 0; //Return flag for no error
183 else
184 return err; //Return error flag for 'hdl_glist_write failed'
185 }
186 ++count;
187 } /* for */
188 return -3; //Return error flag for 'Game not found'
189 } /* if */
190 return err; //Return error flag for 'hdl_glist_read failed'
191 } /* if */
192 return -1; //Return error flag for 'hio_iop_probe failed'
193 }
194 //------------------------------
195 //endfunc HdlRenameGame
196 //--------------------------------------------------------------
197 //End of file: hdd.c
198 //--------------------------------------------------------------

Properties

Name Value
svn:executable *