# HG changeset patch # User Michael Pavone # Date 1521869019 25200 # Node ID f7fe240a7da655b28ccfe7a10b48662103f6d578 # Parent 1f745318f10a41987f6cc5546fa127b1d199a704 Updated fibonacci benchmark code to work with current test harness diff -r 1f745318f10a -r f7fe240a7da6 Makefile --- a/Makefile Wed Jan 31 22:05:10 2018 -0800 +++ b/Makefile Fri Mar 23 22:23:39 2018 -0700 @@ -35,7 +35,7 @@ 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 @@ 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 @@ 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 -r 1f745318f10a -r f7fe240a7da6 blastem.c --- a/blastem.c Wed Jan 31 22:05:10 2018 -0800 +++ b/blastem.c Fri Mar 23 22:23:39 2018 -0700 @@ -47,37 +47,65 @@ #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); + + size_t filesize = 512 * 1024; + size_t readsize = 0; + uint16_t *dst = malloc(filesize); + - 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 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 @@ 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 -r 1f745318f10a -r f7fe240a7da6 fib.s68 --- a/fib.s68 Wed Jan 31 22:05:10 2018 -0800 +++ b/fib.s68 Fri Mar 23 22:23:39 2018 -0700 @@ -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