summaryrefslogtreecommitdiff
path: root/includes/mipsmem.h
blob: f763af837c30d0486713e0238bdf11867513f1ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef __MIPSMEM_H__
#define __MIPSMEM_H__
#define PSXMEM 0x200000

#include <Exceptions.h>
#include <Handle.h>

enum tags_t {
    CODE,
    DATA,
    STOP,
    INVALID,
};

class memdata;

class func_t : public Base {
  public:
      func_t();
      virtual ~func_t();
    Uint32 endpc;
    Uint8 stacksize;
};

class refto_t;
class reffrom_t : public Base {
  public:
      reffrom_t(refto_t *, memdata *);
      virtual ~reffrom_t();
    memdata * getref();
    memdata * getmem();
    reffrom_t * getnext();
  private:
    refto_t * refto;
    reffrom_t * next, * prev;
    memdata * header;
};

class refto_t : public Base {
  public:
      refto_t(Uint32, memdata *);
      virtual ~refto_t();
    memdata * getref();
    memdata * getmem();
  private:
    reffrom_t * reffrom;
    memdata * mem;
};

class mipsmem;
class memdata : public Base {
  public:
      memdata(Uint32, mipsmem *);
      virtual ~memdata();
    Uint32 getaddress();
    memdata * getmem(Uint32);
    static memdata * getmem(Uint32, mipsmem *);
    func_t * getfunc();
    refto_t * getrefto();
    reffrom_t * getreffrom();
    void setfunc(func_t *);
    void setrefto(refto_t *);
    void setreffrom(reffrom_t *);
  private:
    void checkdestroy();
    Uint32 address;
    mipsmem * mm;
    func_t * func;
    refto_t * refto;
    reffrom_t * reffrom;
};

class mipsmem : public Base {
  public:
      mipsmem();
    Uint8 Read8(Uint32 addr);
    Uint16 Read16(Uint32 addr);
    Uint32 Read32(Uint32 addr);
    void Write8(Uint32 addr, Uint8);
    void Write16(Uint32 addr, Uint16);
    void Write32(Uint32 addr, Uint32);
    void unpatch8(Uint32 addr);
    void unpatch16(Uint32 addr);
    void unpatch32(Uint32 addr);
    bool IsPatched(Uint32 addr);
    void LoadPSYQ(Handle *);
    void SavePSYQ(Handle *);
    bool GetTag(Uint32 addr, char tag);
    void SetTag(Uint32 addr, char tag, bool);
    memdata * GetDatas(Uint32 addr);
    void SetDatas(Uint32 addr, memdata * p);
    Uint32 GetPC();
    Uint32 GetLower();
    Uint32 GetUpper();
  private:
    void patch(Uint32, int);
    void unpatch(Uint32, int);
    Uint8 psyqhead[0x800];
    Uint8 plainmemory[PSXMEM];
    Uint8 patches[PSXMEM];
    Uint8 patchesmap[PSXMEM / 8];
    Uint8 tags[PSXMEM];
    memdata * datas[PSXMEM];
    Uint32 paddr, psize, startpc;
    
    struct psyq {
	Uint8 id[8];
	Uint32 text, data, pc0, gp0, t_addr, t_size;
	Uint32 d_addr, d_size, b_addr, b_size, s_addr, s_size;
	Uint32 sp, fp, gp, ra, s0;
    };
};

#endif