summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2018-03-23 22:23:39 -0700
committerMichael Pavone <pavone@retrodev.com>2018-03-23 22:23:39 -0700
commit33cb28448b3af298e611cfd4c98edabb1de63e52 (patch)
tree6a95a02c9ce5d8de3baf5b058010e4c665e9e004
parentc2653ab569c2a0139089db6586f1213884b03b2c (diff)
Updated fibonacci benchmark code to work with current test harness
-rw-r--r--Makefile16
-rw-r--r--blastem.c99
-rw-r--r--fib.s684
3 files changed, 90 insertions, 29 deletions
diff --git a/Makefile b/Makefile
index 67f1a01..f1fbc2c 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ LIBS=sdl2 glew gl
endif #Darwin
HAS_PROC:=$(shell if [ -d /proc ]; then /bin/echo -e -DHAS_PROC; fi)
-CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -Wno-unused-value $(HAS_PROC)
+CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -Wno-unused-value $(HAS_PROC) -DHAVE_UNISTD_H
ifeq ($(OS),Darwin)
#This should really be based on whether or not the C compiler is clang rather than based on the OS
CFLAGS+= -Wno-logical-op-parentheses
@@ -126,8 +126,18 @@ endif
Z80OBJS=z80inst.o z80_to_x86.o
AUDIOOBJS=ym2612.o psg.o wave.o
CONFIGOBJS=config.o tern.o util.o
+LIBZOBJS=zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/gzclose.o zlib/gzlib.o zlib/gzread.o\
+ zlib/gzwrite.o zlib/infback.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/trees.o zlib/uncompr.o zlib/zutil.o
-MAINOBJS=blastem.o system.o genesis.o debug.o gdb_remote.o vdp.o render_sdl.o ppm.o io.o romdb.o hash.o menu.o xband.o realtec.o i2c.o nor.o sega_mapper.o multi_game.o megawifi.o net.o serialize.o $(TERMINAL) $(CONFIGOBJS) gst.o $(M68KOBJS) $(TRANSOBJS) $(AUDIOOBJS)
+MAINOBJS=blastem.o system.o genesis.o debug.o gdb_remote.o vdp.o render_sdl.o ppm.o io.o romdb.o hash.o menu.o xband.o\
+ realtec.o i2c.o nor.o sega_mapper.o multi_game.o megawifi.o net.o serialize.o $(TERMINAL) $(CONFIGOBJS) gst.o\
+ $(M68KOBJS) $(TRANSOBJS) $(AUDIOOBJS)
+
+ifdef NOZLIB
+CFLAGS+= -DDISABLE_ZLIB
+else
+MAINOBJS+= $(LIBZOBJS)
+endif
ifeq ($(CPU),x86_64)
CFLAGS+=-DX86_64 -m64
@@ -252,4 +262,4 @@ font.tiles : font.png
menu.bin : font_interlace_variable.tiles arrow.tiles cursor.tiles button.tiles font.tiles
clean :
- rm -rf $(ALL) trans ztestrun ztestgen *.o
+ rm -rf $(ALL) trans ztestrun ztestgen *.o zlib/*.o
diff --git a/blastem.c b/blastem.c
index 9a9d84d..eeb201c 100644
--- a/blastem.c
+++ b/blastem.c
@@ -47,37 +47,65 @@ tern_node * config;
#define SMD_MAGIC3 0xBB
#define SMD_BLOCK_SIZE 0x4000
-int load_smd_rom(long filesize, FILE * f, void **buffer)
+#ifdef DISABLE_ZLIB
+#define ROMFILE FILE*
+#define romopen fopen
+#define romread fread
+#define romseek fseek
+#define romgetc fgetc
+#define romclose fclose
+#else
+#include "zlib/zlib.h"
+#define ROMFILE gzFile
+#define romopen gzopen
+#define romread gzfread
+#define romseek gzseek
+#define romgetc gzgetc
+#define romclose gzclose
+#endif
+
+int load_smd_rom(ROMFILE f, void **buffer)
{
uint8_t block[SMD_BLOCK_SIZE];
- filesize -= SMD_HEADER_SIZE;
- fseek(f, SMD_HEADER_SIZE, SEEK_SET);
+ romseek(f, SMD_HEADER_SIZE, SEEK_SET);
- uint16_t *dst = *buffer = malloc(nearest_pow2(filesize));
- int rom_size = filesize;
- while (filesize > 0) {
- fread(block, 1, SMD_BLOCK_SIZE, f);
- for (uint8_t *low = block, *high = (block+SMD_BLOCK_SIZE/2), *end = block+SMD_BLOCK_SIZE; high < end; high++, low++) {
- *(dst++) = *low << 8 | *high;
+ size_t filesize = 512 * 1024;
+ size_t readsize = 0;
+ uint16_t *dst = malloc(filesize);
+
+
+ size_t read;
+ do {
+ if ((readsize + SMD_BLOCK_SIZE > filesize)) {
+ filesize *= 2;
+ dst = realloc(dst, filesize);
}
- filesize -= SMD_BLOCK_SIZE;
- }
- return rom_size;
+ read = romread(block, 1, SMD_BLOCK_SIZE, f);
+ if (read > 0) {
+ for (uint8_t *low = block, *high = (block+read/2), *end = block+read; high < end; high++, low++) {
+ *(dst++) = *low << 8 | *high;
+ }
+ readsize += read;
+ }
+ } while(read > 0);
+ romclose(f);
+
+ *buffer = dst;
+
+ return readsize;
}
uint32_t load_rom(char * filename, void **dst, system_type *stype)
{
uint8_t header[10];
- FILE * f = fopen(filename, "rb");
+ ROMFILE f = romopen(filename, "rb");
if (!f) {
return 0;
}
- if (sizeof(header) != fread(header, 1, sizeof(header), f)) {
+ if (sizeof(header) != romread(header, 1, sizeof(header), f)) {
fatal_error("Error reading from %s\n", filename);
}
- fseek(f, 0, SEEK_END);
- long filesize = ftell(f);
- fseek(f, 0, SEEK_SET);
+
if (header[1] == SMD_MAGIC1 && header[8] == SMD_MAGIC2 && header[9] == SMD_MAGIC3) {
int i;
for (i = 3; i < 8; i++) {
@@ -92,15 +120,38 @@ uint32_t load_rom(char * filename, void **dst, system_type *stype)
if (stype) {
*stype = SYSTEM_GENESIS;
}
- return load_smd_rom(filesize, f, dst);
+ return load_smd_rom(f, dst);
}
}
- *dst = malloc(nearest_pow2(filesize));
- if (filesize != fread(*dst, 1, filesize, f)) {
- fatal_error("Error reading from %s\n", filename);
- }
- fclose(f);
- return filesize;
+
+ size_t filesize = 512 * 1024;
+ size_t readsize = sizeof(header);
+
+ char *buf = malloc(filesize);
+ memcpy(buf, header, readsize);
+
+ size_t read;
+ do {
+ read = romread(buf + readsize, 1, filesize - readsize, f);
+ if (read > 0) {
+ readsize += read;
+ if (readsize == filesize) {
+ int one_more = romgetc(f);
+ if (one_more >= 0) {
+ filesize *= 2;
+ buf = realloc(buf, filesize);
+ buf[readsize++] = one_more;
+ } else {
+ read = 0;
+ }
+ }
+ }
+ } while (read > 0);
+
+ *dst = buf;
+
+ romclose(f);
+ return readsize;
}
diff --git a/fib.s68 b/fib.s68
index c8cf58b..f396a27 100644
--- a/fib.s68
+++ b/fib.s68
@@ -1,8 +1,8 @@
dc.l $0, start
start:
- moveq #36, d0
+ moveq #42, d0
bsr fib
- illegal
+ reset
fib:
cmp.l #2, d0
blt base