teleporter.c 974 Bytes
#include <stdio.h>
#include <stdint.h>
#include <string.h>

uint16_t r0;
uint16_t r1;
uint16_t r7;
uint16_t stack[429496729];
uint32_t stack_pos = 0;

void push(uint16_t value)
{
	stack[stack_pos++] = value;
}

uint16_t pop()
{
	return stack[--stack_pos];
}

void func1()
{
	if(r0 == 0)
	{
        	r0 = (r1 + 1) % 0x8000;
                return;
	}
        if(r1 == 0)
	{
                r0 = (r0 + 0x7FFF) % 0x8000;
                r1 = r7;
                func1();
                return;
	}
        push(r0);
        r1 = (r1 + 0x7FFF) % 0x8000;
        func1();
        r1 = r0;
        r0 = pop();
        r0 = (r0 - 1) % 0x8000;
        func1();
        return;
}

int main()
{
	int i;
	for(i = 1; i < 32768; i++)
	{
		printf("Trying with %d... ",i);
		memset(stack,0x00,32768);
		stack_pos = 0;
		r0 = 4;
		r1 = 1;
		r7 = i;
		func1();
		printf("%d\n",r0);
		if(r0 == 6)
		{
			printf("===FOUND VALUE===\nr0: %d\nr1: %d\nr7: %d\n\n",r0,r1,r7);
		}
	}
	return 0;
}