Skip to content

Commit

Permalink
Remove C library dependencies.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://jay/var/svn/wolf/trunk@75 32837ae5-38f0-4cfd-8401-3ff76d8497c4
  • Loading branch information
paul committed Aug 5, 2007
1 parent 4d69700 commit bc5d5b7
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 79 deletions.
7 changes: 4 additions & 3 deletions Makefile
Expand Up @@ -10,6 +10,7 @@ CFLAGS = -g -Wall -fno-common -DINTEGRATOR
#CFLAGS = -Os -Wall -pedantic #CFLAGS = -Os -Wall -pedantic
#CFLAGS = -Os -Wall -fomit-frame-pointer -ffast-math -march=pentiumpro #CFLAGS = -Os -Wall -fomit-frame-pointer -ffast-math -march=pentiumpro
#CFLAGS=-O3 -xiMK -tpp6 -c99 -wp_ipo -g #CFLAGS=-O3 -xiMK -tpp6 -c99 -wp_ipo -g

OBJS = objs.o misc.o id_ca.o id_vh.o id_us.o \ OBJS = objs.o misc.o id_ca.o id_vh.o id_us.o \
wl_act1.o wl_act2.o wl_act3.o wl_agent.o wl_game.o \ wl_act1.o wl_act2.o wl_act3.o wl_agent.o wl_game.o \
wl_inter.o wl_menu.o wl_play.o wl_state.o wl_main.o \ wl_inter.o wl_menu.o wl_play.o wl_state.o wl_main.o \
Expand All @@ -19,7 +20,7 @@ ROBJS = wl_draw.o
SOBJS = $(OBJS) $(ROBJS) vi_svga.o SOBJS = $(OBJS) $(ROBJS) vi_svga.o
XOBJS = $(OBJS) $(ROBJS) vi_xlib.o XOBJS = $(OBJS) $(ROBJS) vi_xlib.o
DOBJS = $(OBJS) $(ROBJS) vi_sdl.o DOBJS = $(OBJS) $(ROBJS) vi_sdl.o
EOBJS = $(OBJS) $(ROBJS) vi_bare.o EOBJS = $(OBJS) $(ROBJS) vi_bare.o arm_support.o


#LDLIBS = -lm -wp_ipo #LDLIBS = -lm -wp_ipo
LDLIBS = -lm LDLIBS = -lm
Expand All @@ -36,7 +37,7 @@ OBJS += sd_null.o
SLDLIBS = $(LDLIBS) -lvga SLDLIBS = $(LDLIBS) -lvga
XLDLIBS = $(LDLIBS) -L/usr/X11R6/lib -lX11 -lXext XLDLIBS = $(LDLIBS) -L/usr/X11R6/lib -lX11 -lXext
DLDLIBS = $(LDLIBS) $(shell sdl-config --libs) DLDLIBS = $(LDLIBS) $(shell sdl-config --libs)
ELDLIBS = $(LDLIBS) -T rdimon-ram.ld ELDLIBS = $(LDLIBS) -T integrator.ld -nodefaultlibs


NASM = nasm NASM = nasm


Expand All @@ -62,7 +63,7 @@ xwolf3d: $(XOBJS)
sdlwolf3d: $(DOBJS) sdlwolf3d: $(DOBJS)
$(CC) -o sdlwolf3d $(DOBJS) $(DLDLIBS) $(CC) -o sdlwolf3d $(DOBJS) $(DLDLIBS)


ewolf3d: $(EOBJS) ewolf3d: $(EOBJS) integrator-crt0.o
$(CC) -o ewolf3d $(EOBJS) $(ELDLIBS) $(CC) -o ewolf3d $(EOBJS) $(ELDLIBS)


tables.o: tables.c tables.o: tables.c
Expand Down
158 changes: 158 additions & 0 deletions arm_support.c
@@ -0,0 +1,158 @@
#include "wl_def.h"
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>

int __errno;

int atoi(const char *p)
{
int negative = 0;
int i;
if (*p == '-') {
negative = 1;
p++;
}
i = 0;
while (*p) {
i = (i * 10) + (*p - '0');
p++;
}
return i;
}

void abort()
{
while(1);
}

void *memset(void *s, int c, size_t n)
{
char *p = s;
while (n--)
*(p++) = c;
return s;
}

int strncmp(const char *s1, const char *s2, size_t n)
{
int i;

i = 0;
while (i < n && *s1 && *s2 && *s1 != *s2) {
s1++;
s2++;
}
return (int)*s2 - (int)*s1;
}

/* Only used for file timestamps. */
time_t time(time_t *p)
{
return 0;
}

char *strcpy(char *dest, const char *src)
{
char *p = dest;
while (*src) {
*(p++) = *(src++);
}
*p = 0;
return dest;
}

size_t strlen(const char *s)
{
const char *p = s;
while (*p)
p++;
return p - s;
}

char *strcat(char *dest, const char *src)
{
char *p = dest + strlen(dest);
strcpy(p, src);
return dest;
}

void *memcpy(void *dest, const void *src, size_t n)
{
char *a = dest;
const char *b = src;
while (n--)
*(a++) = *(b++);
return dest;
}

static uint32_t angel(int reason, uint32_t *args)
{
register uint32_t r0 asm ("r0");
register uint32_t r1 asm ("r1");

r0 = reason;
r1 = (uint32_t)args;
asm volatile ("swi 0x123456"
: "=r" (r0), "=r"(r1)
: "0"(r0), "1"(r1)
: "r2", "r3", "lr", "ip", "cc", "memory");
return r0;
}

int open(const char *filename, int flags, ...)
{
uint32_t block[3];
if (flags & O_CREAT)
Quit("Can't creat\n");
#ifdef O_BINARY
flags &= ~O_BINARY;
#endif
if (flags != O_RDONLY)
Quit("Can only open readonly\n");
block[0] = (uint32_t)filename;
block[1] = 1;
block[2] = strlen(filename);
return angel(1, block);
}

ssize_t read(int fd, void *buf, size_t count)
{
uint32_t block[3];
int rc;

block[0] = fd;
block[1] = (uint32_t)buf;
block[2] = count;
rc = angel(6, block);
if (rc)
Quit("Read Failed\n");
return count - rc;
}

ssize_t write(int fd, const void *buf, size_t count)
{
Quit("Can't write\n");
return 0;
}

int close(int fd)
{
uint32_t arg = fd;
angel(2, &arg);
return 0;
}

off_t lseek(int fd, off_t ptr, int whence)
{
uint32_t block[2];
int rc;
if (whence != SEEK_SET)
Quit("Bad Seek whence\n");
block[0] = fd;
block[1] = ptr;
rc = angel(10, block);
if (rc)
return -1;
return ptr;
}
105 changes: 52 additions & 53 deletions id_ca.c
Expand Up @@ -455,7 +455,6 @@ static void CAL_SetupMapFile()
mapheaderseg[i]->planelength[2] = ReadInt16(maphandle); mapheaderseg[i]->planelength[2] = ReadInt16(maphandle);
mapheaderseg[i]->width = ReadInt16(maphandle); mapheaderseg[i]->width = ReadInt16(maphandle);
mapheaderseg[i]->height = ReadInt16(maphandle); mapheaderseg[i]->height = ReadInt16(maphandle);
ReadSeek(maphandle, 16, SEEK_CUR);
} }


CloseRead(handle); CloseRead(handle);
Expand Down Expand Up @@ -688,12 +687,13 @@ memptr CA_GetChunk(myint chunk)


ReadSeek(grhandle, pos, SEEK_SET); ReadSeek(grhandle, pos, SEEK_SET);


MM_GetPtr((memptr)&source, compressed); source = MM_AllocPool(NULL, compressed);
//MM_GetPtr((memptr)&source, compressed);
ReadBytes(grhandle, source, compressed); ReadBytes(grhandle, source, compressed);


dest = CAL_ExpandGrChunk(chunk, source); dest = CAL_ExpandGrChunk(chunk, source);


MM_FreePtr((memptr)&source); //MM_FreePtr((memptr)&source);
return dest; return dest;
} }


Expand Down Expand Up @@ -735,12 +735,14 @@ void CA_CacheMap(myint mapnum, myint plane)


ReadSeek(maphandle, pos, SEEK_SET); ReadSeek(maphandle, pos, SEEK_SET);


MM_GetPtr((void *)&source, compressed); source = MM_AllocPool(NULL, compressed);
//MM_GetPtr((void *)&source, compressed);


ReadBytes(maphandle, (byte *)source, compressed); ReadBytes(maphandle, (byte *)source, compressed);


expanded = source[0] | (source[1] << 8); expanded = source[0] | (source[1] << 8);
MM_GetPtr(&buffer2seg, expanded); buffer2seg = MM_AllocPool(NULL, expanded);
//MM_GetPtr(&buffer2seg, expanded);


/* NOTE: CarmackExpand implicitly fixes endianness, a RLEW'd only map /* NOTE: CarmackExpand implicitly fixes endianness, a RLEW'd only map
would (likely) need to be swapped in CA_RLEWexpand would (likely) need to be swapped in CA_RLEWexpand
Expand All @@ -750,10 +752,10 @@ void CA_CacheMap(myint mapnum, myint plane)
and the like. and the like.
*/ */
CAL_CarmackExpand(source+2, (word *)buffer2seg, expanded); CAL_CarmackExpand(source+2, (word *)buffer2seg, expanded);
MM_FreePtr((void *)&source); //MM_FreePtr((void *)&source);


CA_RLEWexpand(((word *)buffer2seg)+1, mapseg0, plane ? 16 : 0); CA_RLEWexpand(((word *)buffer2seg)+1, mapseg0, plane ? 16 : 0);
MM_FreePtr(&buffer2seg); //MM_FreePtr(&buffer2seg);
} }


/* ======================================================================== */ /* ======================================================================== */
Expand Down Expand Up @@ -785,59 +787,55 @@ void MM_Shutdown()


memptr MM_AllocPool(pool_id *id, unsigned long size) memptr MM_AllocPool(pool_id *id, unsigned long size)
{ {
pool_header *h; pool_header *h;
pool_header *next; pool_header *next;
h = (pool_header *)(MM_Pool + pool_offset); h = (pool_header *)(MM_Pool + pool_offset);
size = (size + 7) & ~7; size = (size + 7) & ~7;
if (size > POOL_SIZE - 8) if (size > POOL_SIZE - 8)
{ Quit("Pool allocation too big\n");
fprintf(stderr, "Pool allocation too big (%d)\n", (int)size); /* Reclaim entries until we have enough space. */
abort(); while (h->size < size)
{
/* Wrap back to the start of the pool. */
if (pool_offset + h->size + 8 == POOL_SIZE)
{
pool_offset = 0;
h = (pool_header *)MM_Pool;
continue;
}
next = (pool_header *)(MM_Pool + pool_offset + h->size + 8);
if (next->owner)
*next->owner = 0;
h->size += next->size + 8;
}
/* Make sure this entry is free. */
if (h->owner)
{
*h->owner = 0;
}
if (size < h->size - 8) {
next = (pool_header *)(MM_Pool + pool_offset + size + 8);
next->owner = NULL;
next->size = h->size - (size + 8);
h->size = size;
} }
/* Reclaim entries until we have enough space. */ h->owner = id;
while (h->size < size) if (id)
{ *id = pool_offset + 8;
/* Wrap back to the start of the pool. */ pool_offset += h->size + 8;
if (pool_offset + h->size + 8 == POOL_SIZE) if (pool_offset == POOL_SIZE)
{ pool_offset = 0;
pool_offset = 0; return (memptr)(h + 1);
h = (pool_header *)MM_Pool;
continue;
}
next = (pool_header *)(MM_Pool + pool_offset + h->size + 8);
if (next->owner)
*next->owner = 0;
h->size += next->size + 8;
}
/* Make sure this entry is free. */
if (h->owner)
{
*h->owner = 0;
}
if (size < h->size - 8) {
next = (pool_header *)(MM_Pool + pool_offset + size + 8);
next->owner = NULL;
next->size = h->size - (size + 8);
h->size = size;
}
h->owner = id;
*id = pool_offset + 8;
pool_offset += h->size + 8;
if (pool_offset == POOL_SIZE)
pool_offset = 0;
return (memptr)(h + 1);
} }


memptr MM_PoolPtr(pool_id id) memptr MM_PoolPtr(pool_id id)
{ {
if (!id) if (!id)
{ Quit("Pool entry absent\n");
fprintf(stderr, "Pool entry absent\n"); return (memptr)(MM_Pool + id);
abort();
}
return (memptr)(MM_Pool + id);
} }


#ifndef EMBEDDED
static int total_size = 0; static int total_size = 0;
static int lastmalloc; static int lastmalloc;
void MM_GetPtr(memptr *baseptr, unsigned long size) void MM_GetPtr(memptr *baseptr, unsigned long size)
Expand Down Expand Up @@ -869,6 +867,7 @@ void MM_SetLock(memptr *baseptr, boolean locked)
total_locked += lastmalloc; total_locked += lastmalloc;
#endif #endif
} }
#endif


void MM_SortMem() void MM_SortMem()
{ {
Expand Down

0 comments on commit bc5d5b7

Please sign in to comment.