#include „prob-16-kern.h”
#include <iostream>
void enqueue(void);
void dequeue(void);
int currentpoint; // aktualnie obslugiwany punkt, ekwiwalent ant.p
extern int sizeofpoint; // ilosć danych w punkcie
extern int pointdata; // dane punktowe, w main, jedna zmienna
typedef struct {
int p;
unsigned sp, bp;
unsigned stack[SIZEOFSTACK];
} antstr;
antstr ant;
antstr antqueue[MAXQUEUE];
antstr* back = antqueue;
antstr* front = antqueue;
void* space[SPACESIZE];
int s; // parametr do enqueue
void enqueue(void)
{
if (space[currentpoint] == NULL)
space[currentpoint] = malloc(sizeofpoint);
memmove(space[currentpoint], &pointdata, sizeofpoint);
currentpoint = currentpoint ^ s;
if (space[currentpoint] == NULL)
space[currentpoint] = malloc(sizeofpoint);
ant.p = currentpoint;
memmove(back, &ant, sizeof(ant));
if (back == &antqueue[MAXQUEUE – 1])
back = antqueue; else back++;
}
void dequeue(void)
{
memmove(&ant, front, sizeof(ant));
if (front == &antqueue[MAXQUEUE – 1])
front = antqueue; else front++;
currentpoint = ant.p;
memmove(&pointdata, space[currentpoint], sizeofpoint);
}
__declspec(naked) void tx(int r)
{
__asm
{
push ebp
mov ebp, esp
sub esp, 4
mov ant.sp, esp // SAVE
mov ant.bp, ebp // SAVE
push eax
push ebx
push ecx
push edi
push esi
}
memmove(ant.stack, (unsigned*)ant.sp, SIZEOFSTACK);
s = 0; enqueue();
s = r; enqueue();
dequeue();
memmove((unsigned*)ant.sp, ant.stack, SIZEOFSTACK);
__asm
{
pop esi
pop edi
pop ecx
pop ebx
pop eax
mov ebp, ant.bp // RESTORE
// mov esp, ant.sp // RESTORE
mov esp, ebp
pop ebp
ret
}
}
__declspec(naked) void t(int r)
{
__asm
{
push ebp
mov ebp, esp
sub esp, 4
mov ant.sp, esp // SAVE
mov ant.bp, ebp // SAVE
push eax
push ebx
push ecx
push edi
push esi
}
memmove(ant.stack, (unsigned*)ant.sp, SIZEOFSTACK);
s = r; enqueue();
dequeue();
memmove((unsigned*)ant.sp, ant.stack, SIZEOFSTACK);
__asm
{
pop esi
pop edi
pop ecx
pop ebx
pop eax
mov ebp, ant.bp // RESTORE
// mov esp, ant.sp // RESTORE
mov esp, ebp
pop ebp
ret
}
}
__declspec(naked) void o(void)
{
__asm
{
push ebp
mov ebp, esp
mov ant.sp, esp // SAVE
mov ant.bp, ebp // SAVE
push eax
push ebx
push ecx
push edi
push esi
}
memcpy(ant.stack, (unsigned*)ant.sp, SIZEOFSTACK);
if (front == back) exit(0);
dequeue();
memcpy((unsigned*)ant.sp, ant.stack, SIZEOFSTACK);
__asm
{
pop esi
pop edi
pop ecx
pop ebx
pop eax
mov ebp, ant.bp // RESTORE
// mov esp, ant.sp // RESTORE
mov esp, ebp
pop ebp
ret
}
}