PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
hdl.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11/* Unofficial add-on to HDSK to support HDLoader games.
12 The HDLoader format stores the LBAs and sizes of each partition at offset 0x100000
13 of the main partition's extended attribute area. If the main partition or its sub-partitions
14 are moved, then the game is broken. */
15
16#include <atad.h>
17#include <errno.h>
18#include <iomanX.h>
19#include <stdio.h>
20#include <sysclib.h>
21#include <irx.h>
22#include <hdd-ioctl.h>
23
24#include "libapa.h"
25#include "hdsk.h"
26
27#define HDL_INFO_MAGIC 0xDEADFEED
28#define HDL_GAME_DATA_OFFSET 0x100000
29
30#define HDLFS_GAME_TITLE_LEN 160
31#define HDLFS_STARTUP_PTH_LEN 60
32
33typedef struct
34{
35 u32 part_offset; // In CD-ROM (2048-byte) sectors
36 u32 data_start; // In 512-byte HDD sectors
37 u32 part_size; // In bytes
39
40typedef struct // size = 1024 bytes
41{
42 u32 magic;
43 u16 reserved;
44 u16 version;
45 s8 gamename[HDLFS_GAME_TITLE_LEN];
46 u8 hdl_compat_flags;
47 u8 ops2l_compat_flags;
48 u8 dma_type;
49 u8 dma_mode;
50 s8 startup[HDLFS_STARTUP_PTH_LEN]; /* NOTE: The startup file name here must be without the ";1" suffix. */
51 u32 layer1_start;
52 u32 discType;
53 s32 num_partitions;
54 part_specs_t part_specs[65];
56
57extern u8 IOBuffer[IOBUFFER_SIZE_SECTORS * 512];
58
59int hdlUpdateGameSliceInfo(int device, u32 main, int part, u32 OldPartStart, u32 NewPartStart)
60{
61 u32 InfoLBA, DataOffset;
62 int result;
63
64 /* Note: The APA specification states that there is a 4KB area used for storing the partition's information,
65 before the extended attribute area. */
66 InfoLBA = main + (HDL_GAME_DATA_OFFSET + 4096) / 512;
67
68 if ((result = sceAtaDmaTransfer(device, IOBuffer, InfoLBA, sizeof(hdl_game_info_t) / 512, ATA_DIR_READ)) == 0) {
69 if (((hdl_game_info_t *)IOBuffer)->magic == HDL_INFO_MAGIC) {
70 DataOffset = ((hdl_game_info_t *)IOBuffer)->part_specs[part].data_start - OldPartStart;
71 ((hdl_game_info_t *)IOBuffer)->part_specs[part].data_start = NewPartStart + DataOffset;
72 result = sceAtaDmaTransfer(device, IOBuffer, InfoLBA, sizeof(hdl_game_info_t) / 512, ATA_DIR_WRITE);
73 } else {
74 result = -1;
75 }
76 }
77
78 return result;
79}
unsigned int version
Definition fileXio.h:3