-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mem.c
168 lines (133 loc) · 3.61 KB
/
Mem.c
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*************************************
* Includes
************************************/
#include <stdio.h>
#include <math.h>
#include "Mem.h"
/*************************************
* Functions
************************************/
int MemCopy8(lua_State *L){
char *dest= (char*)lua_tonumber(L,1);
char *source= (char*)lua_tonumber(L,2);
int len=lua_tonumber(L,3);
unsigned counter;
for(counter=0;counter<len;counter++){
dest[counter]=source[counter];
}
return 0;
}
int MemCopy16(lua_State *L){
short *dest= (short*)lua_tonumber(L,1);
short *source= (short*)lua_tonumber(L,2);
int len=lua_tonumber(L,3);
unsigned counter;
for(counter=0;counter<len;counter++){
dest[counter]=source[counter];
}
return 0;
}
int MemCopy32(lua_State *L){
int *dest= (int*)lua_tonumber(L,1);
int *source= (int*)lua_tonumber(L,2);
int len=lua_tonumber(L,3);
unsigned counter;
for(counter=0;counter<len;counter++){
dest[counter]=source[counter];
}
return 0;
}
int MemCopy8WithAdd(lua_State *L){
char *dest= (char*)lua_tonumber(L,1);
char *source=(char*)lua_tonumber(L,2);
char add=lua_tonumber(L,3);
int len=lua_tonumber(L,4);
unsigned counter;
for(counter=0;counter<len;counter++){
dest[counter]=source[counter]+add;
}
return 0;
}
int MemCopy16WithAdd(lua_State *L){
unsigned short *dest= (unsigned short*)lua_tonumber(L,1);
unsigned short *source=(unsigned short*)lua_tonumber(L,2);
unsigned short add=lua_tonumber(L,3);
int len=lua_tonumber(L,4);
char num[20];
sprintf(num,"%x\n",add);
unsigned counter;
for(counter=0;counter<len;counter++){
dest[counter]=source[counter]+add;
}
return 0;
}
int MemCopy32WithAdd(lua_State *L){
int *dest= (int*)lua_tonumber(L,1);
int *source=(int*)lua_tonumber(L,2);
int add=lua_tonumber(L,3);
int len=lua_tonumber(L,4);
unsigned counter;
for(counter=0;counter<len;counter++){
dest[counter]=source[counter]+add;
}
return 0;
}
int MemFill8(lua_State *L){
char *dest=(char*)lua_tonumber(L,1);
char fillValue=lua_tonumber(L,2);
int len=lua_tonumber(L,3);
unsigned counter;
for(counter=0;counter<len;counter++){
dest[counter]=fillValue;
}
return 0;
}
int MemFill16(lua_State *L){
short *dest=(short*)lua_tonumber(L,1);
short fillValue=lua_tonumber(L,2);
int len=lua_tonumber(L,3);
unsigned counter;
for(counter=0;counter<len;counter++){
dest[counter]=fillValue;
}
return 0;
}
int MemFill32(lua_State *L){
int *dest=(int*)lua_tonumber(L,1);
int fillValue=lua_tonumber(L,2);
int len=lua_tonumber(L,3);
unsigned counter;
for(counter=0;counter<len;counter++){
dest[counter]=fillValue;
}
return 0;
}
int MemRead8(lua_State *L){
unsigned char *dest=(unsigned char*)lua_tonumber(L,1);
lua_pushnumber(L,*dest);
return 1;
}
int MemRead16(lua_State *L){
unsigned short *dest=(unsigned short*)lua_tonumber(L,1);
lua_pushnumber(L,*dest);
return 1;
}
int MemRead32(lua_State *L){
unsigned*dest=(unsigned*)lua_tonumber(L,1);
lua_pushnumber(L,*dest);
return 1;
}
void RegisterMem(lua_State* L){
lua_register(L,"MemCopy8",MemCopy8);
lua_register(L,"MemCopy16",MemCopy16);
lua_register(L,"MemCopy32",MemCopy32);
lua_register(L,"MemCopy8WithAdd",MemCopy8WithAdd);
lua_register(L,"MemCopy16WithAdd",MemCopy16WithAdd);
lua_register(L,"MemCopy32WithAdd",MemCopy32WithAdd);
lua_register(L,"MemFill8",MemFill8);
lua_register(L,"MemFill16",MemFill16);
lua_register(L,"MemFill32",MemFill32);
lua_register(L,"MemRead8",MemRead8);
lua_register(L,"MemRead16",MemRead16);
lua_register(L,"MemRead32",MemRead32);
}