chip8

CHIP-8 emulator
git clone git://git.christosmarg.xyz/chip8.git
Log | Files | Refs | README | LICENSE

commit 00f98716353245d5e15772e08de47a397a581423
parent bb6fee8774351e95af4e0a8d3d390853ad785417
Author: Christos Margiolis <christos@margiolis.net>
Date:   Wed, 14 Oct 2020 23:59:37 +0300

added LICENSE and updated Makefile

Diffstat:
ALICENSE | 29+++++++++++++++++++++++++++++
MMakefile | 43+++++++++++++++++++++++++++++++------------
Mchip8.c | 15++++++++++-----
3 files changed, 70 insertions(+), 17 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2020-present, Christos Margiolis. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of images.weserv.nl nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile @@ -1,40 +1,59 @@ BIN = chip8 +VERSION = 0.1 +DIST = ${BIN}-${VERSION} MAN1 = ${BIN}.1 PREFIX = /usr/local MAN_DIR = ${PREFIX}/man/man1 BIN_DIR = ${PREFIX}bin -SRC = ${wildcard *.c} -OBJ = ${SRC:%.c=%.o} +EXT = c +SRC = ${wildcard *.${EXT}} +OBJ = ${SRC:%.${EXT}=%.o} CC = gcc -CPPFLAGS += -Iinclude -pedantic -CFLAGS += -Wall -std=c99 -O3 +CPPFLAGS += -Iinclude -DVERSION=\"${VERSION}\" +CFLAGS += -Wall -std=c99 -pedantic -O3 LDFLAGS += -Llib LDLIBS += -lSDL2 -CP=cp -f +CP = cp -f +RM = rm -f +RM_DIR = rm -rf MKDIR = mkdir -p - -.PHONY: all clean +TAR = tar -cf +GZIP = gzip all: ${BIN} ${BIN}: ${OBJ} ${CC} ${LDFLAGS} $^ ${LDLIBS} -o $@ -%.o: %.c +%.o: %.${EXT} ${CC} ${CPPFLAGS} ${CFLAGS} -c $< -o $@ +dist: clean + ${MKDIR} ${DIST} + ${CP} -R roms ${SRC} LICENSE Makefile README.md ${DIST} + ${TAR} ${DIST}.tar ${DIST} + ${GZIP} ${DIST}.tar + ${RM_DIR} ${DIST} + run: ./${BIN} install: all - ${MKDIR} ${DESTDIR}${BIN_DIR} + ${MKDIR} ${DESTDIR}${BIN_DIR} ${DESTDIR}${MAN_DIR} ${CP} ${BIN} ${BIN_DIR} - #${MKDIR} ${DESTDIR}${MAN_DIR} - #${CP} ${MAN1} ${DESTDIR}${MAN_DIR} - #chmod 644 ${DESTDIR}${MAN_DIR}/${MAN1} + ${CP} ${MAN1} ${DESTDIR}${MAN_DIR} + sed "s/VERSION/${VERSION}/g" < ${MAN1} > ${DESTDIR}${MAN_DIR}/${MAN1} + chmod 644 ${DESTDIR}${BIN_DIR}/${BIN} + chmod 644 ${DESTDIR}${MAN_DIR}/${MAN1} + +uninstall: all + ${RM} ${DESTDIR}${BIN_DIR}/${BIN} + ${RM} ${DESTDIR}${MAN_DIR}/${MAN1} clean: ${RM} ${OBJ} ${BIN} + +.PHONY: all clean dist install uninstall run diff --git a/chip8.c b/chip8.c @@ -331,8 +331,10 @@ decode(struct Chip8 *chip8) void timers_update(struct Chip8 *chip8) { - if (delaytimer > 0) --delaytimer; - if (soundtimer > 0) --soundtimer; + if (delaytimer > 0) + --delaytimer; + if (soundtimer > 0) + --soundtimer; } #undef V @@ -355,7 +357,8 @@ evts(struct Chip8 *chip8) SDL_Event e; while (SDL_PollEvent(&e)) { - if (e.type == SDL_QUIT || e.key.keysym.sym == SDLK_ESCAPE) return FALSE; + if (e.type == SDL_QUIT || e.key.keysym.sym == SDLK_ESCAPE) + return FALSE; if (e.type == SDL_KEYDOWN) for (i = 0; i < 16; i++) if (e.key.keysym.sym == keymap[i]) @@ -412,10 +415,12 @@ main(int argc, char **argv) struct Chip8 chip8; chip8_init(&chip8); - if (!romload(&chip8, argv[1])) return EXIT_FAILURE; + if (!romload(&chip8, argv[1])) + return EXIT_FAILURE; for (; evts(&chip8); usleep(1500)) { emulate(&chip8); - if (chip8.drawflag) render(ren, tex, &chip8); + if (chip8.drawflag) + render(ren, tex, &chip8); } SDL_DestroyTexture(tex);