Skip to content

Commit

Permalink
Merge pull request #22 from danirod/devel
Browse files Browse the repository at this point in the history
Releasing CHIP-8 0.1.3
  • Loading branch information
danirod committed Mar 28, 2016
2 parents f521653 + 278891c commit f29c8bc
Show file tree
Hide file tree
Showing 19 changed files with 205 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# TODO: Migrate to container based builds

sudo: required
dist: trusty
branches:
only:
- master
- devel

language: c
compiler: gcc
Expand Down
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
2016-03-26 Dani Rodríguez <[email protected]>

* src/libsdl.c: fixed package not building under Windows and
MacOS X because name conflict between our sdl.h and SDL2's
SDL.h (non-case sensitive file systems).
* src/chip8.c: doesn't crash when the PC has no sound device,
emulator will just run muted. (Bug#19)
* src/chip8.c: added --mute flag.
* Makefile.am: extra files are now copied to datadir.
* debian/: added Debian control files for Debian packaging.

2016-03-24 Dani Rodríguez <[email protected]>

* Version 0.1.2 released.
* src/sdl.h: fixed SDL.h header file inclusion.

2016-03-02 Dani Rodríguez <[email protected]>
Expand Down Expand Up @@ -31,6 +43,7 @@

2015-03-12 Hugo Martin <[email protected]>

* Version 0.1.1 released.
* src/sdl.c: Drop SDL_WINDOW_OPENGL so that SDL can decide
the best graphics backend based on the user platform.
* src/sdl.c: Remove unrequired SDL_Surface.
Expand Down
12 changes: 12 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
SUBDIRS = src . tests

# Copy extra distribution files
docdir = $(datadir)/doc/$(PACKAGE)
doc_DATA = ChangeLog NEWS README COPYING

# Copy public domain examples
examples = examples/*
examplesdir = $(datadir)/doc/@PACKAGE@/roms
examples_DATA = $(examples)

# Extra files that should come with dist (like ROMs)
EXTRA_DIST = $(examples) debian/*
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Copyright (C) 2015-2016 Dani Rodríguez <[email protected]>
This file is about relevant changes for CHIP-8 users. Developers: Check
ChangeLog for an overview on relevant changes about the source code.

Version 0.1.3 - 2016-03-28
* Fixed: emulator won't crash if the PC has no sound device.
* Added: --mute flag was added, forcing emulator to not buzz.
* Added: support for DPKG distributions using a .deb file.

Version 0.1.2 - 2016-03-24
* Added sound support.
* Added more flags: --version and --usage.
Expand Down
26 changes: 23 additions & 3 deletions README
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
chip8 is a CHIP-8 emulator developed in C using the SDL2 multimedia library.
It emulates a standard CHIP-8 machine and implements all the opcodes that
the specification provides.
This is my own implementation of a CHIP-8 emulator made using C and the SDL2
multimedia library. At the moment it is able to emulate a standard CHIP-8
machine implementing all the opcodes provided by the specification.

To emulate a binary ROM just provide the file as an argument:

$ chip8 ~/roms/TETRIS.bin

To emulate an hexadecimal ROM you can use the `--hex` flag. Hexadecimal ROMs
are files that only contains ASCII characters representing hexadecimal code.
The ROM is compiled to binary during start up and executed as usual.

Keyboard controls are designed to emulate the classic CHIP-8 controller. This
is the mapping. On the left, the actual CHIP-8 keypad. On the right, the
keys in emulator. It will be possible in future releases to change the keys.
At the moment the only way for doing this is by manually patching the source
code.

Keypad: Emulation:
1 2 3 C 1 2 3 4
4 5 6 D Q W E R
7 8 9 E A S D F
A 0 B F Z X C V

In the subdirectory 'examples' you may find a few public domain ROMs that
can be emulated using this emulator as well as any other emulator you can
Expand Down
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
# chip8

[![Build Status](https://travis-ci.org/danirod/chip8.svg)](https://travis-ci.org/danirod/chip8)
[![GitHub tag](https://img.shields.io/github/tag/danirod/chip8.svg)](https://github.com/danirod/chip8/releases/latest)
[![GitHub license](https://img.shields.io/badge/license-GPL3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0.html)

# CHIP-8

This is my own implementation of a CHIP-8 emulator made using C and the SDL2
multimedia library. At the moment it is able to emulate a standard CHIP-8
machine implementing all the opcodes provided by the specification.

## Usage

To emulate a binary ROM just provide the file as an argument:

```sh
$ chip8 ~/roms/TETRIS.bin
```

## Introduction
To emulate an hexadecimal ROM you can use the `--hex` flag. Hexadecimal ROMs
are files that only contains ASCII characters representing hexadecimal code.
The ROM is compiled to binary during start up and executed as usual.

chip8 is a CHIP-8 emulator developed in C using the SDL2 multimedia library.
It emulates a standard CHIP-8 machine and implements all the opcodes that
the specification provides.
Keyboard controls are designed to emulate the classic CHIP-8 controller. This
is the mapping. On the left, the actual CHIP-8 keypad. On the right, the
keys in emulator. It will be possible in future releases to change the keys.
At the moment the only way for doing this is by manually patching the source
code.

```
Keypad: Emulation:
1 2 3 C 1 2 3 4
4 5 6 D Q W E R
7 8 9 E A S D F
A 0 B F Z X C V
```
## Screenshots

GNU/Linux:
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# configure.ac

AC_INIT([chip8], [0.1.2], [[email protected]])
AC_INIT([chip8], [0.1.3], [[email protected]])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])

# Check programs
Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
chip8 (0.1.3-1) unstable; urgency=low

* Initial release.

-- Dani Rodríguez <[email protected]> Sat, 26 Mar 2016 17:00:41 +0100
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
19 changes: 19 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Source: chip8
Section: games
Priority: optional
Maintainer: Dani Rodríguez <[email protected]>
Build-Depends: debhelper (>= 8.0.0), autotools-dev, check, libsdl2-dev (>= 2.0.0)
Standards-Version: 3.9.4
Homepage: http://github.com/danirod/chip8
Vcs-Git: git://github.com/danirod/chip8.git
Vcs-Browser: http://github.com/danirod/chip8

Package: chip8
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libsdl2-2.0-0 (>= 2.0.0)
Description: Multiplatform CHIP-8 emulator
chip8 is a CHIP-8 emulator using the SDL2 emulation library.
It is able to emulate CHIP-8 ROMs in binary and hexadecimal
format. CHIP-8 is under development and not all features
have been implemented.

19 changes: 19 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: chip8
Source: http://github.com/danirod/chip8

Files: *
Copyright: 2015-2016 Dani Rodríguez <[email protected]>
License: GPL-3+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
8 changes: 8 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
dh $@ --with autotools-dev
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (quilt)
23 changes: 23 additions & 0 deletions debian/source/include-binaries
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
examples/15PUZZLE
examples/BLINKY
examples/BLITZ
examples/BRIX
examples/CONNECT4
examples/GUESS
examples/HIDDEN
examples/INVADERS
examples/KALEID
examples/MAZE
examples/MERLIN
examples/MISSILE
examples/PONG
examples/PONG2
examples/PUZZLE
examples/SYZYGY
examples/TANK
examples/TETRIS
examples/TICTAC
examples/UFO
examples/VBRIX
examples/VERS
examples/WIPEOFF
Binary file modified doc/windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ lib8_a_SOURCES = cpu.c cpu.h
lib8_a_CFLAGS = -std=c99 -Wall

bin_PROGRAMS = chip8
chip8_SOURCES = chip8.c sdl.c sdl.h
chip8_SOURCES = chip8.c libsdl.c libsdl.h
chip8_CFLAGS = @SDL_CFLAGS@ -std=c99 -Wall
chip8_LDADD = lib8.a @SDL_LIBS@
33 changes: 24 additions & 9 deletions src/chip8.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

#include "cpu.h"
#include "sdl.h"
#include "libsdl.h"
#include "../config.h"

#include <getopt.h>
Expand All @@ -28,11 +28,15 @@
/* Flag set by '--hex' */
static int use_hexloader;

/* Flag set by '--mute' */
static int use_mute;

/* getopt parameter structure. */
static struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ "hex", no_argument, &use_hexloader, 1 },
{ "mute", no_argument, &use_mute, 1 },
{ 0, 0, 0, 0 }
};

Expand All @@ -43,7 +47,11 @@ static struct option long_options[] = {
static void
usage(const char* name)
{
printf("Usage: %s [-h | --help] [-v | --version] [--hex] <file>\n", name);
/* How many characters has Usage: %s? */
int pad = strnlen(name, 10) + 7; // 7 = "Usage: "

printf("Usage: %s [-h | --help] [-v | --version]\n", name);
printf("%*c [--hex] [--mute] <file>\n", pad, ' ');
}

static char
Expand Down Expand Up @@ -186,19 +194,26 @@ main(int argc, char** argv)
exit(1);
}

/* Init emulator. */
srand(time(NULL));
init_machine(&mac);
mac.keydown = &is_key_down;
mac.speaker = &update_speaker;
load_data(argv[optind], &mac);

/* Initialize SDL Context. */
if (init_context()) {
fprintf(stderr, "Error initializing SDL graphical context:\n");
fprintf(stderr, "%s\n", SDL_GetError());
return 1;
}
if (!try_enable_sound()) {
fprintf(stderr, "Couldn't enable sound.\n");
use_mute = 1;
}

/* Init emulator. */
srand(time(NULL));
init_machine(&mac);
mac.keydown = &is_key_down;
if (!use_mute) {
mac.speaker = &update_speaker;
}
load_data(argv[optind], &mac);


int last_ticks = SDL_GetTicks();
int last_delta = 0, step_delta = 0, render_delta = 0;
Expand Down
14 changes: 8 additions & 6 deletions src/sdl.c → src/libsdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/


#include "sdl.h"
#include "libsdl.h"

#include <stdlib.h>
#include <math.h>
Expand Down Expand Up @@ -166,14 +166,16 @@ init_context()
clean_up();
return 1;
}
return 0;
}

int
try_enable_sound()
{
spec = init_audiospec();
device = SDL_OpenAudioDevice(NULL, 0, spec,
NULL, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
if (device == 0) {
clean_up();
return 1;
}
return 0;
return (device != 0);
}

void
Expand Down
15 changes: 5 additions & 10 deletions src/sdl.h → src/libsdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* After checking out SDL2 source code it has been found that the include
* guard for SDL2/SDL.h is named _SDL_H. Since coding conventions for this
* project have stablished that the underscore should go AFTER the H, a
* conflict may not happen. Let's just hope that SDL team never changes
* idea. (Why would they?)
*/
#ifndef SDL_H_
#define SDL_H_
#ifndef LIBSDL_H_
#define LIBSDL_H_

#include "cpu.h"

#include <SDL.h>

int init_context();

int try_enable_sound();

void destroy_context();

void render_display(struct machine_t* cpu);
Expand All @@ -42,4 +37,4 @@ int is_key_down(char);

void update_speaker(int);

#endif // SDL_H_
#endif // LIBSDL_H_

0 comments on commit f29c8bc

Please sign in to comment.