view mem.c @ 345:29d2ca563499

Don't sync the 68K clock to the VDP clock unless the 68K had to wait for the VDP. This unfortunately breaks the direct color DMA demos, but should be more correct overall.
author Mike Pavone <pavone@retrodev.com>
date Sun, 19 May 2013 13:47:47 -0700
parents 3e7bfde7606e
children 140af5509ce7
line wrap: on
line source

#include <sys/mman.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include "mem.h"

/*
void * alloc_code(size_t *size)
{
	*size += PAGE_SIZE - (*size & (PAGE_SIZE - 1));
	return mmap(NULL, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
}
*/

/*
void * alloc_code(size_t *size)
{
	char * ret = malloc(*size);
	char * base = (char *)(((intptr_t)ret) & (~(PAGE_SIZE-1)));
	mprotect(base, (ret + *size) - base, PROT_EXEC | PROT_READ | PROT_WRITE);
	return ret;
}
*/

void * alloc_code(size_t *size)
{
	*size += PAGE_SIZE - (*size & (PAGE_SIZE - 1));
	void * ret = sbrk(*size);
	if (ret == ((void *)-1)) {
		return NULL;
	}
	mprotect(ret, *size, PROT_EXEC | PROT_READ | PROT_WRITE);
	return ret;
}