51 |
|
NATIVE_GET_IND_RESOURCE, |
52 |
|
NATIVE_GET_1_IND_RESOURCE, |
53 |
|
NATIVE_R_GET_RESOURCE, |
54 |
– |
NATIVE_DISABLE_INTERRUPT, |
55 |
– |
NATIVE_ENABLE_INTERRUPT, |
54 |
|
NATIVE_MAKE_EXECUTABLE, |
55 |
|
NATIVE_CHECK_LOAD_INVOC, |
56 |
+ |
NATIVE_SYNC_HOOK, |
57 |
+ |
NATIVE_BITBLT_HOOK, |
58 |
+ |
NATIVE_FILLRECT_HOOK, |
59 |
+ |
NATIVE_BITBLT, |
60 |
+ |
NATIVE_INVRECT, |
61 |
+ |
NATIVE_FILLRECT, |
62 |
|
NATIVE_OP_MAX |
63 |
|
}; |
64 |
|
|
90 |
|
class SheepMem { |
91 |
|
static uint32 align(uint32 size); |
92 |
|
protected: |
93 |
+ |
static uint32 page_size; |
94 |
|
static uintptr zero_page; |
95 |
|
static uintptr base; |
96 |
< |
static uintptr top; |
97 |
< |
static const uint32 size = 0x40000; // 256 KB |
96 |
> |
static uintptr data; |
97 |
> |
static uintptr proc; |
98 |
> |
static const uint32 size = 0x80000; // 512 KB |
99 |
|
public: |
100 |
|
static bool Init(void); |
101 |
|
static void Exit(void); |
102 |
< |
static uintptr ZeroPage(); |
103 |
< |
static uintptr Reserve(uint32 size); |
102 |
> |
static uint32 PageSize(); |
103 |
> |
static uint32 ZeroPage(); |
104 |
> |
static uint32 Reserve(uint32 size); |
105 |
|
static void Release(uint32 size); |
106 |
+ |
static uint32 ReserveProc(uint32 size); |
107 |
|
friend class SheepVar; |
108 |
|
}; |
109 |
|
|
113 |
|
return (size + 3) & -4; |
114 |
|
} |
115 |
|
|
116 |
< |
inline uintptr SheepMem::ZeroPage() |
116 |
> |
inline uint32 SheepMem::PageSize() |
117 |
> |
{ |
118 |
> |
return page_size; |
119 |
> |
} |
120 |
> |
|
121 |
> |
inline uint32 SheepMem::ZeroPage() |
122 |
|
{ |
123 |
|
return zero_page; |
124 |
|
} |
125 |
|
|
126 |
< |
inline uintptr SheepMem::Reserve(uint32 size) |
126 |
> |
inline uint32 SheepMem::Reserve(uint32 size) |
127 |
|
{ |
128 |
< |
top -= align(size); |
129 |
< |
assert(top >= base); |
130 |
< |
return top; |
128 |
> |
data -= align(size); |
129 |
> |
assert(data >= proc); |
130 |
> |
return data; |
131 |
|
} |
132 |
|
|
133 |
|
inline void SheepMem::Release(uint32 size) |
134 |
|
{ |
135 |
< |
top += align(size); |
135 |
> |
data += align(size); |
136 |
> |
} |
137 |
> |
|
138 |
> |
inline uint32 SheepMem::ReserveProc(uint32 size) |
139 |
> |
{ |
140 |
> |
uint32 mproc = proc; |
141 |
> |
proc += align(size); |
142 |
> |
assert(proc < data); |
143 |
> |
return mproc; |
144 |
> |
} |
145 |
> |
|
146 |
> |
static inline uint32 SheepProc(const uint8 *proc, uint32 proc_size) |
147 |
> |
{ |
148 |
> |
uint32 mac_proc = SheepMem::ReserveProc(proc_size); |
149 |
> |
Host2Mac_memcpy(mac_proc, proc, proc_size); |
150 |
> |
return mac_proc; |
151 |
|
} |
152 |
|
|
153 |
|
class SheepVar |
154 |
|
{ |
155 |
< |
uintptr m_base; |
156 |
< |
uint32 m_size; |
155 |
> |
uint32 m_base; |
156 |
> |
uint32 m_size; |
157 |
|
public: |
158 |
|
SheepVar(uint32 requested_size); |
159 |
|
~SheepVar() { SheepMem::Release(m_size); } |
160 |
< |
uintptr addr() const { return m_base; } |
133 |
< |
void *ptr() const { return (void *)addr(); } |
160 |
> |
uint32 addr() const { return m_base; } |
161 |
|
}; |
162 |
|
|
163 |
|
inline SheepVar::SheepVar(uint32 requested_size) |
168 |
|
|
169 |
|
// TODO: optimize for 32-bit platforms |
170 |
|
|
171 |
< |
template< int size > |
171 |
> |
template< int requested_size > |
172 |
|
struct SheepArray : public SheepVar |
173 |
|
{ |
174 |
< |
SheepArray() : SheepVar(size) { } |
148 |
< |
uint8 *ptr() const { return (uint8 *)addr(); } |
174 |
> |
SheepArray() : SheepVar(requested_size) { } |
175 |
|
}; |
176 |
|
|
177 |
|
struct SheepVar32 : public SheepVar |
180 |
|
SheepVar32(uint32 value) : SheepVar(4) { set_value(value); } |
181 |
|
uint32 value() const { return ReadMacInt32(addr()); } |
182 |
|
void set_value(uint32 v) { WriteMacInt32(addr(), v); } |
157 |
– |
uint32 *ptr() const { return (uint32 *)addr(); } |
183 |
|
}; |
184 |
|
|
185 |
|
struct SheepString : public SheepVar |
186 |
|
{ |
187 |
|
SheepString(const char *str) : SheepVar(strlen(str) + 1) |
188 |
< |
{ if (str) strcpy((char *)addr(), str); else WriteMacInt8(addr(), 0); } |
188 |
> |
{ if (str) strcpy(value(), str); else WriteMacInt8(addr(), 0); } |
189 |
|
char *value() const |
190 |
< |
{ return (char *)addr(); } |
166 |
< |
char *ptr() const |
167 |
< |
{ return (char *)addr(); } |
190 |
> |
{ return (char *)Mac2HostAddr(addr()); } |
191 |
|
}; |
192 |
|
|
193 |
|
#endif |