1 #ifndef __MDFN_CDACCESS_PBP_H
2 #define __MDFN_CDACCESS_PBP_H
3 
4 #include <boolean.h>
5 
6 #include <map>
7 #include "CDAccess_Image.h"
8 
9 class Stream;
10 
11 class CDAccess_PBP : public CDAccess
12 {
13    public:
14 
15       CDAccess_PBP(const char *path, bool image_memcache);
16       virtual ~CDAccess_PBP();
17 
18       virtual bool Read_Raw_Sector(uint8_t *buf, int32_t lba);
19 
20       virtual bool Read_Raw_PW(uint8_t *buf, int32_t lba);
21 
22       virtual bool Read_TOC(TOC *toc);
23 
24       virtual void Eject(bool eject_status);
25 
26    private:
27       Stream* fp;
28 
29       enum PBP_FILES{
30          PARAM_SFO,
31          ICON0_PNG,
32          ICON1_PMF,
33          PIC0_PNG,
34          PIC1_PNG,
35          SND0_AT3,
36          DATA_PSP,
37          DATA_PSAR,
38 
39          PBP_NUM_FILES
40       };
41       uint32_t pbp_file_offsets[PBP_NUM_FILES];
42 
43       ////////////////
44       uint8_t buff_raw[16][2352];
45       uint8_t buff_compressed[2352 * 16];
46       uint32_t *index_table;
47       uint32_t index_len;
48       uint32_t current_block;
49       uint32_t sector_in_blk;
50       ////////////////
51 
52       int32_t NumTracks;
53       int32_t FirstTrack;
54       int32_t LastTrack;
55       int32_t total_sectors;
56       uint8_t disc_type;
57 
58       std::string sbi_path;
59       uint32_t discs_start_offset[5];
60       uint32_t psisoimg_offset;
61 
62       uint16_t fixed_sectors;
63       bool is_official;    // TODO: find more consistent ways to check for used compression algorithm, compressed (and/or encrypted?) audio tracks and messed up sectors
64 
65       bool ImageOpen(const char *path, bool image_memcache);
66       int LoadSBI(const char* sbi_path);
67       void Cleanup(void);
68 
69       CDRFILE_TRACK_INFO Tracks[100]; // Track #0(HMM?) through 99
70       struct cpp11_array_doodad
71       {
72          uint8 data[12];
73       };
74       std::map<uint32, cpp11_array_doodad> SubQReplaceMap;
75       void MakeSubPQ(int32 lba, uint8 *SubPWBuf);
76 
77       int decompress2(void *out, uint32_t *out_size, void *in, uint32_t in_size);
78 
79       int decode_range(unsigned int *range, unsigned int *code, unsigned char **src);
80       int decode_bit(unsigned int *range, unsigned int *code, int *index, unsigned char **src, unsigned char *c);
81       int decode_word(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src);
82       int decode_number(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src);
83       int decompress(unsigned char *out, unsigned char *in, unsigned int size);
84 
85       int decrypt_pgd(unsigned char* pgd_data, int pgd_size);
86       int fix_sector(uint8_t* sector, int32_t lba);
87 };
88 
89 
90 #endif
91