diff --git a/.gitmodules b/.gitmodules index bc4fe37..d87f973 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "external/glfw"] path = external/glfw url = https://github.com/glfw/glfw.git +[submodule "external/coveralls-cmake"] + path = external/coveralls-cmake + url = https://github.com/JoakimSoderberg/coveralls-cmake.git diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a78071d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,40 @@ +language: c +os: + - linux + - osx +matrix: + allow_failures: + - os: osx + +addons: + apt: + packages: + - lcov + - curl + - xorg-dev + - libglu1-mesa-dev + +compiler: + - clang + - gcc + +script: + - mkdir build + - cd build + - cmake -DUSE_ALLEGRO=OFF -DUSE_PROFILING=OFF -DCOVERALLS=OFF -DCMAKE_BUILD_TYPE=Release .. + - cmake --build . + - cd .. + - mkdir coverage + - cd coverage + - cmake -DUSE_ALLEGRO=OFF -DUSE_PROFILING=OFF -DCOVERALLS=ON -DCMAKE_BUILD_TYPE=Debug .. + - cmake --build . + - cmake --build . --target coveralls + +before_install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install glew; fi + +install: true + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/CMakeLists.txt b/CMakeLists.txt index 543edf3..ae0fd29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,9 @@ add_subdirectory("external/glfw") find_package(OpenGL REQUIRED) include_directories(${OPENGL_INCLUDE_DIR}) -link_libraries(${OPENGL_gl_LIBRARY}) + +if (COVERALLS) + enable_testing() +endif (COVERALLS) add_subdirectory (src) diff --git a/README.md b/README.md index 57e03a4..bd47340 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ TI-NESulator ============ -This is a cleaned version of the TI-NESulator repository (all data has been removed) +[![Coverage Status](https://coveralls.io/repos/github/Godzil/TI-NESulator/badge.svg?branch=master)](https://coveralls.io/github/Godzil/TI-NESulator?branch=master) [![codecov](https://codecov.io/gh/Godzil/TI-NESulator/branch/master/graph/badge.svg)](https://codecov.io/gh/Godzil/TI-NESulator) [![travis](https://travis-ci.org/Godzil/TI-NESulator.svg?branch=master)](https://travis-ci.org/Godzil/TI-NESulator) + +This is a cleaned version of the TI-NESulator repository (all non free data has been removed) Some part of the original subversion has been lost because of harddrive crash so the early stage of the project is completely lost. Or I would need to check all the diff --git a/data/bad_apple_2.nes b/data/bad_apple_2.nes new file mode 100644 index 0000000..2671987 Binary files /dev/null and b/data/bad_apple_2.nes differ diff --git a/external/coveralls-cmake b/external/coveralls-cmake new file mode 160000 index 0000000..e37d5b8 --- /dev/null +++ b/external/coveralls-cmake @@ -0,0 +1 @@ +Subproject commit e37d5b8674dab235185b07ad9208c88d84f81823 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5f711e5..4f358fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,12 +22,16 @@ set(USE_PROFILING OFF CACHE BOOL "Use profiling tools? (Will slow down a lot.)") set(USE_ALLEGRO ON CACHE BOOL "Use Allegro backend") +option(COVERALLS "Generate coveralls data" OFF) + ########################## # Link & Compile flags ########################## -set (CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -Werror ${PLATFORM_FLAGS}") -set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -Werror ${PLATFORM_FLAGS}") +set (CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Werror ${PLATFORM_FLAGS}") +set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Werror ${PLATFORM_FLAGS}") + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/external/coveralls-cmake/cmake) add_definitions (-DNO_DECIMAL) @@ -59,6 +63,12 @@ if (USE_PROFILING) set(CMAKE_C_FLAGS -pg) endif (USE_PROFILING) +if (COVERALLS) + add_definitions (-DRUN_COVERAGE) + include(Coveralls) + coveralls_turn_on_coverage() +endif() + include_directories(include) add_subdirectory(apu) @@ -79,6 +89,18 @@ endif (TARGET_TI68k) find_library(PTHREADLIB pthread) +if (COVERALLS) + set(COVERAGE_SRCS src/main.c src/paddle.c src/NESCarts.c ${COVERAGE_SRCS}) + + # Create the coveralls target. + coveralls_setup( + "${COVERAGE_SRCS}" # The source files. + ON # If we should upload. + ) # (Optional) Alternate project cmake module path. +endif() + + add_executable(tines main.c paddle.c NESCarts.c) -target_compile_options(tines PRIVATE -pthread) -target_link_libraries(tines apu corecpu mappermanager memorymanager pluginsmanager ppu oslib) #${PTHREADLIB} \ No newline at end of file +target_link_libraries(tines apu corecpu mappermanager memorymanager pluginsmanager ppu oslib ${PTHREADLIB}) + +add_test(NAME tines_test COMMAND $ ${PROJECT_SOURCE_DIR}/data/bad_apple_2.nes) diff --git a/src/corecpu/CMakeLists.txt b/src/corecpu/CMakeLists.txt index c561f3b..9041ee4 100644 --- a/src/corecpu/CMakeLists.txt +++ b/src/corecpu/CMakeLists.txt @@ -9,4 +9,8 @@ # $HeadURL$ # $Revision$ -add_library(corecpu corecpu.c) \ No newline at end of file +if (COVERALLS) + set(COVERAGE_SRCS src/corecpu/corecpu.c ${COVERAGE_SRCS} PARENT_SCOPE) +endif() + +add_library(corecpu corecpu.c) diff --git a/src/main.c b/src/main.c index 5975e83..d865fd0 100755 --- a/src/main.c +++ b/src/main.c @@ -73,7 +73,7 @@ double APU_BASEFREQ = 1.7897725; /* TI-NESulator Version */ #define V_MAJOR 0 -#define V_MINOR 70 +#define V_MINOR 71 #ifdef USE_SOUND #undef USE_SOUND @@ -257,12 +257,20 @@ void LoadPalette(char *filename, Palette *pal) } } +#ifdef RUN_COVERAGE +void alarmHandler(int sig) +{ + signal(SIGALRM, SIG_IGN); + WantClosing = 1; +} +#endif + void signalhandler(int sig) { static int state=0; char name[512]; - + static FILE *fp = NULL; sprintf(name, "crashdump-%d.txt", (int)time(NULL)); if (state != 0) @@ -642,7 +650,11 @@ int main(int argc, char *argv[]) console_printf(Console_Default, "S"); signal(SIGTERM, signalhandler); console_printf(Console_Default, "T]\n"); - + +#ifdef RUN_COVERAGE + signal(SIGALRM, alarmHandler); +#endif + /* */ console_printf(Console_Default, "Initialize memory...\t\t"); InitMemory(); @@ -956,6 +968,10 @@ int main(int argc, char *argv[]) */ gettimeofday(&timeStart, NULL); + +#ifdef RUN_COVERAGE + alarm(1 * 60); /* Run for 1 minutes */ +#endif while(!WantClosing) { diff --git a/src/mappersmanager/CMakeLists.txt b/src/mappersmanager/CMakeLists.txt index da1e1b5..2f80973 100644 --- a/src/mappersmanager/CMakeLists.txt +++ b/src/mappersmanager/CMakeLists.txt @@ -10,4 +10,9 @@ # $Revision$ file(GLOB mappers_list mappers/*.c) -add_library(mappermanager utils.c manager.c ${mappers_list} ) \ No newline at end of file + +if (COVERALLS) + set(COVERAGE_SRCS src/mappersmanager/manager.c src/mappersmanager/utils.c ${COVERAGE_SRCS} PARENT_SCOPE) +endif() + +add_library(mappermanager utils.c manager.c ${mappers_list} ) diff --git a/src/memorymanager/CMakeLists.txt b/src/memorymanager/CMakeLists.txt index d1a2c87..5d2ceb2 100644 --- a/src/memorymanager/CMakeLists.txt +++ b/src/memorymanager/CMakeLists.txt @@ -9,4 +9,8 @@ # $HeadURL$ # $Revision$ -add_library(memorymanager memory.c) \ No newline at end of file +if (COVERALLS) + set(COVERAGE_SRCS src/memorymanager/memory.c ${COVERAGE_SRCS} PARENT_SCOPE) +endif() + +add_library(memorymanager memory.c) diff --git a/src/os/unix/CMakeLists.txt b/src/os/unix/CMakeLists.txt index b14fa40..79a9e20 100644 --- a/src/os/unix/CMakeLists.txt +++ b/src/os/unix/CMakeLists.txt @@ -9,6 +9,11 @@ # $HeadURL$ # $Revision$ -add_library(oslib loadfile.c graphics.c sound.c io.c) +if (COVERALLS) + set(COVERAGE_SRCS src/os/unix/loadfile.c src/os/unix/graphics_dummy.c src/os/unix/sound.c src/os/unix/io.c ${COVERAGE_SRCS} PARENT_SCOPE) + add_library(oslib loadfile.c graphics_dummy.c sound.c io.c) +else() + add_library(oslib loadfile.c graphics.c sound.c io.c) +endif() -target_link_libraries(oslib glfw ${OPENGL_glu_LIBRARY}) \ No newline at end of file +target_link_libraries(oslib glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY}) diff --git a/src/os/unix/graphics.c b/src/os/unix/graphics.c index 11b9f48..9a490dd 100644 --- a/src/os/unix/graphics.c +++ b/src/os/unix/graphics.c @@ -18,12 +18,8 @@ #include +#define GLFW_INCLUDE_GLEXT #include -#ifdef __MACOSX__ -#include -#else -#include -#endif #include @@ -47,10 +43,6 @@ struct GLWindow_t int HEIGHT; }; -#ifndef GL_TEXTURE_RECTANGLE_EXT -#define GL_TEXTURE_RECTANGLE_EXT GL_TEXTURE_RECTANGLE_NV -#endif - static int window_num = 0; void GLWindowInitEx(GLWindow *g, int w, int h) @@ -67,10 +59,10 @@ void GLWindowInit(GLWindow *g) void ShowScreen(GLWindow *g, int w, int h) { - glBindTexture(GL_TEXTURE_RECTANGLE_EXT, g->videoTexture); + glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture); // glTexSubImage2D is faster when not using a texture range - glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory); + glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); @@ -108,20 +100,20 @@ void setupGL(GLWindow *g, int w, int h) glLoadIdentity(); glDisable(GL_TEXTURE_2D); - glEnable(GL_TEXTURE_RECTANGLE_EXT); - glBindTexture(GL_TEXTURE_RECTANGLE_EXT, g->videoTexture); + glEnable(GL_TEXTURE_RECTANGLE); + glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture); // glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_NV_EXT, 0, NULL); // glTexParameteri(GL_TEXTURE_RECTANGLE_NV_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE); // glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); - glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, w, + glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory); glDisable(GL_DEPTH_TEST); @@ -144,7 +136,7 @@ void restoreGL(GLWindow *g, int w, int h) glLoadIdentity(); glDisable(GL_TEXTURE_2D); - glEnable(GL_TEXTURE_RECTANGLE_EXT); + glEnable(GL_TEXTURE_RECTANGLE); glDisable(GL_DEPTH_TEST); } @@ -223,7 +215,6 @@ void drawPixel(GLWindow *gw, int x, int y, uint32_t colour) r = (colour >> 16) & 0xFF; a = (colour >> 24) & 0xFF; - gw->videoMemory[offset + 0] = a; gw->videoMemory[offset + 1] = r; gw->videoMemory[offset + 2] = g; diff --git a/src/os/unix/graphics_dummy.c b/src/os/unix/graphics_dummy.c new file mode 100644 index 0000000..f652014 --- /dev/null +++ b/src/os/unix/graphics_dummy.c @@ -0,0 +1,138 @@ +/* + * Graphic Manager - The TI-NESulator Project + * os/macos/graphics.c + * + * Created by Manoel TRAPIER on 08/05/08. + * Copyright (c) 2003-2016 986-Studio. All rights reserved. + * + * $LastChangedDate$ + * $Author$ + * $HeadURL$ + * $Revision$ + * + */ +#include +#include +#include +#include + +#include + +#include +//#include + +#include + +typedef struct GLWindow_t GLWindow; + +struct KeyArray +{ + unsigned char lastState; + unsigned char curState; + unsigned char debounced; + GLFWwindow* window; +}; + +struct GLWindow_t +{ + struct KeyArray keyArray[512]; + GLFWwindow* windows; + unsigned char *videoMemory; + GLint videoTexture; + int WIDTH; + int HEIGHT; +}; + +#ifndef GL_TEXTURE_RECTANGLE_EXT +#define GL_TEXTURE_RECTANGLE_EXT GL_TEXTURE_RECTANGLE_NV +#endif + +void GLWindowInitEx(GLWindow *g, int w, int h) +{ +} + +void GLWindowInit(GLWindow *g) +{ +} + +void ShowScreen(GLWindow *g, int w, int h) +{ +} + +void setupGL(GLWindow *g, int w, int h) +{ +} + +void restoreGL(GLWindow *g, int w, int h) +{ +} + +void kbHandler(GLFWwindow* window, int key, int scan, int action, int mod ) +{ +} + +void sizeHandler(GLFWwindow* window,int xs,int ys) +{ +} + + +void initDisplay(GLWindow *g) +{ +} + +void drawPixel(GLWindow *gw, int x, int y, uint32_t colour) +{ +} + +void drawLine(GLWindow *g, int x0, int y0, int x1, int y1, uint32_t colour) +{ +} + +void drawCircle(GLWindow *g, int xc, int yc, int radius, uint32_t colour) +{ +} + +void drawRect(GLWindow *g, int x0, int y0, int w, int h, uint32_t colour) +{ +} + +void drawFillrect(GLWindow *g, int x0, int y0, int w, int h, uint32_t colour) +{ +} + +void clearScreen(GLWindow *g) +{ +} + +void updateScreen(GLWindow *g) +{ +} + +void updateScreenAndWait(GLWindow *g) +{ +} + +int graphics_init() +{ + return 0; +} + +int graphics_drawpixel(long x, long y, long color) +{ + return 0; +} + +int graphics_drawline(long x, long y, long x1, long y1, long color) +{ + return 0; +} + +int graphics_blit(long x, long y, long w, long h) +{ + return 0; +} + +int getKeyStatus(int key) +{ + return 0; +} diff --git a/src/os/unix/io.c b/src/os/unix/io.c index a4e0f01..2a34804 100644 --- a/src/os/unix/io.c +++ b/src/os/unix/io.c @@ -40,11 +40,10 @@ int console_vprintf(const ConsoleLevel level, const char *format, va_list ap) int console_printf(const ConsoleLevel level, const char *format, ...) { - int ret = 0; va_list ap; va_start(ap, format); - ret = console_vprintf(level, format, ap); + console_vprintf(level, format, ap); va_end(ap); return ret; @@ -58,4 +57,4 @@ int console_printf_d(const char *format, ...) console_vprintf (Console_Debug, format, ap); return 0; -} \ No newline at end of file +} diff --git a/src/os/unix/loadfile.c b/src/os/unix/loadfile.c index 4d79168..8235591 100644 --- a/src/os/unix/loadfile.c +++ b/src/os/unix/loadfile.c @@ -30,5 +30,10 @@ void *LoadFilePtr(char * filename) close(fd); + if ( RetPtr == MAP_FAILED ) + { + RetPtr = NULL; + } + return RetPtr; } diff --git a/src/pluginsmanager/CMakeLists.txt b/src/pluginsmanager/CMakeLists.txt index a0b0965..8ae184a 100644 --- a/src/pluginsmanager/CMakeLists.txt +++ b/src/pluginsmanager/CMakeLists.txt @@ -10,4 +10,9 @@ # $Revision$ file(GLOB plugins_list plugins/*.c) -add_library(pluginsmanager manager.c ${plugins_list}) \ No newline at end of file + +if (COVERALLS) + set(COVERAGE_SRCS src/pluginsmanager/manager.c ${COVERAGE_SRCS} PARENT_SCOPE) +endif() + +add_library(pluginsmanager manager.c ${plugins_list}) diff --git a/src/ppu/CMakeLists.txt b/src/ppu/CMakeLists.txt index c3b40b6..6d39434 100644 --- a/src/ppu/CMakeLists.txt +++ b/src/ppu/CMakeLists.txt @@ -10,4 +10,10 @@ # $Revision$ file(GLOB ppu_debug_list debug/*.c) -add_library(ppu ppu.c ppu.memory.c ${ppu_debug_list}) \ No newline at end of file + +if (COVERALLS) + set(COVERAGE_SRCS src/ppu/ppu.c src/ppu/ppu.memory.c ${COVERAGE_SRCS} PARENT_SCOPE) +endif() + + +add_library(ppu ppu.c ppu.memory.c ${ppu_debug_list}) diff --git a/src/ppu/debug/ppu.debug.c b/src/ppu/debug/ppu.debug.c index bf32cd7..0f88541 100644 --- a/src/ppu/debug/ppu.debug.c +++ b/src/ppu/debug/ppu.debug.c @@ -14,6 +14,7 @@ #include #include + #if 0 /* Allegro includes */ #ifdef __APPLE__ @@ -21,7 +22,7 @@ #include #else #define USE_CONSOLE -//#include +#include #endif #define __TINES_PPU_INTERNAL__ @@ -367,4 +368,4 @@ void ppu_dumpPalette(int x, int y) rectfill(Buffer, x + 91 + (i % 4) * 20, y + 21 +(i / 4) * 20, x + 91 + (i % 4) * 20 + 20, y + 21 +(i / 4) * 20 + 20, ppu_readMemory(0x3F, i+0x10)); } } -#endif \ No newline at end of file +#endif