Rev 7774 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5598 | pavelyakov | 1 | #ifndef INCLUDE_MEM_H |
2 | #define INCLUDE_MEM_H |
||
3107 | leency | 3 | |
5606 | pavelyakov | 4 | #ifndef INCLUDE_KOLIBRI_H |
5 | #include "../lib/kolibri.h" |
||
6 | #endif |
||
7 | |||
7981 | leency | 8 | inline fastcall void mem_init() |
3067 | leency | 9 | { |
6021 | leency | 10 | $mov eax, 68 |
11 | $mov ebx, 11 |
||
12 | $int 0x40 |
||
3067 | leency | 13 | } |
14 | |||
7160 | leency | 15 | :dword malloc(dword size) |
3067 | leency | 16 | { |
6021 | leency | 17 | $push ebx |
18 | $push ecx |
||
19 | |||
20 | $mov eax, 68 |
||
21 | $mov ebx, 12 |
||
22 | $mov ecx, size |
||
23 | $int 0x40 |
||
24 | |||
25 | $pop ecx |
||
26 | $pop ebx |
||
27 | return EAX; |
||
3067 | leency | 28 | } |
29 | |||
7160 | leency | 30 | :stdcall dword realloc(dword mptr, size) |
3067 | leency | 31 | { |
6021 | leency | 32 | $push ebx |
33 | $push ecx |
||
34 | $push edx |
||
3067 | leency | 35 | |
6021 | leency | 36 | $mov eax, 68 |
37 | $mov ebx, 20 |
||
38 | $mov ecx, size |
||
39 | $mov edx, mptr |
||
40 | $int 0x40 |
||
41 | |||
42 | $pop edx |
||
43 | $pop ecx |
||
44 | $pop ebx |
||
45 | return EAX; |
||
3067 | leency | 46 | } |
47 | |||
7160 | leency | 48 | :dword free(dword mptr) |
3067 | leency | 49 | { |
6021 | leency | 50 | $push eax |
51 | $push ebx |
||
52 | $push ecx |
||
53 | |||
54 | $mov eax, 68 |
||
55 | $mov ebx, 13 |
||
56 | $mov ecx, mptr |
||
57 | $test ecx, ecx |
||
58 | $jz end0 |
||
59 | $int 0x40 |
||
3067 | leency | 60 | @end0: |
6021 | leency | 61 | $pop ecx |
62 | $pop ebx |
||
63 | $pop eax |
||
64 | return 0; |
||
3067 | leency | 65 | } |
66 | |||
3107 | leency | 67 | inline fastcall memmov( EDI, ESI, ECX) |
3067 | leency | 68 | { |
69 | asm { |
||
70 | MOV EAX, ECX |
||
71 | CMP EDI, ESI |
||
72 | JG L1 |
||
73 | JE L2 |
||
74 | SAR ECX, 2 |
||
75 | JS L2 |
||
76 | REP MOVSD |
||
77 | MOV ECX, EAX |
||
78 | AND ECX, 3 |
||
79 | REP MOVSB |
||
80 | JMP SHORT L2 |
||
81 | L1: LEA ESI, DSDWORD[ ESI+ECX-4] |
||
82 | LEA EDI, DSDWORD[ EDI+ECX-4] |
||
83 | SAR ECX, 2 |
||
84 | JS L2 |
||
85 | STD |
||
86 | REP MOVSD |
||
87 | MOV ECX, EAX |
||
88 | AND ECX, 3 |
||
89 | ADD ESI, 3 |
||
90 | ADD EDI, 3 |
||
91 | REP MOVSB |
||
92 | CLD |
||
93 | L2: |
||
94 | } |
||
95 | } |
||
96 | |||
7774 | leency | 97 | #define SHM_OPEN 0x00 |
98 | #define SHM_OPEN_ALWAYS 0x04 |
||
99 | #define SHM_CREATE 0x08 |
||
100 | #define SHM_READ 0x00 |
||
101 | #define SHM_WRITE 0x01 |
||
7773 | leency | 102 | inline fastcall dword memopen(ECX, EDX, ESI) |
103 | { |
||
104 | $mov eax, 68 |
||
105 | $mov ebx, 22 |
||
106 | // ecx = area name, 31 symbols max |
||
107 | // edx = area size for SHM_CREATE SHM_OPEN_ALWAYS |
||
108 | // esi = flags, see the list below: |
||
109 | $int 0x40 |
||
110 | // eax, edx - please check system documentation |
||
111 | } |
||
3128 | leency | 112 | |
7773 | leency | 113 | inline fastcall dword memclose(ECX) |
114 | { |
||
115 | $mov eax, 68 |
||
116 | $mov ebx, 23 |
||
117 | $int 0x40 |
||
118 | // eax destroyed |
||
119 | } |
||
3128 | leency | 120 | |
3107 | leency | 121 | #define mem_Alloc malloc |
122 | #define mem_ReAlloc realloc |
||
123 | #define mem_Free free |
||
124 | #define mem_Init mem_init |
||
3067 | leency | 125 | |
5598 | pavelyakov | 126 | #endif |