view src/init.c @ 22:3fb0ec050ff3

malloc has been restructured to now work in a more logical manner malloc now allocates memory from the beginning of a block instead of the end. Additionally, memory is now 8-byte aligned instead of 16-byte aligned. malloc_init should now be called to set up all the memory information. Fixed a bug where malloc would not have iterated to find new memory locations.
author Jonathan Pevarnek <pevarnj@gmail.com>
date Wed, 16 Mar 2011 00:09:35 -0400
parents 7c2adb65ceac
children f68b59af5ea6
line wrap: on
line source

/*
 * This is where everything starts
 */

#include <std.h>
#include <operations.h>
#include <stack.h>

void dumpBuffer(char *a, int b)
{
	int i;
	for(i = 0; i < b; i++) {
		int foo = (int) a[i];
		char c[10];
		itoa(foo, c);
		sPrint(c);
		sPrint(" ");
		if(!((i + 1)%20)) sPrint("\n");
	}
}

void start(u64 __memsize)
{
  int i, n;
  char *buffer;
	char input[30];
	malloc_init(0x1400000); //20MB memory

	while(1) {
		sPrint("How long do you want the string? ");
		n = atoi(sGet(input, 30));

		buffer = (char*) malloc(n);
		if (!buffer) { //allocation failed, too large
			sPrint("ERROR\n");
			break;
		}

		for (i = 0; i < n; i++)
			buffer[i]='a'; //I need to make rand...
		buffer[n]='\0';

//		dumpBuffer(buffer, n);

		sPrint(append(itoa((unsigned long)buffer, input), "\n"));
		sPrint(buffer), sPrint("\n");
	}
/*
	struct Stack theStack;
	struct Stack *stack = &theStack;
	initStack(stack);
	while(1) {
		int opVal;
		char input[30];
		sPrint("Please enter an operation or value: ");
		opVal = arrayLookup(sGet(input, 30), operationNames, MAXOP);
		if(opVal != MAXOP) {
			(*operation[opVal]) (stack); //call the function array
		} else {
			push(stack, atof(input));
		}
	}
*/
	for(;;)
		;
}