33 Commits

Author SHA1 Message Date
Godzil
5336cf6272 Add Joe Granato's Troll Burner Demo as a test for mapper #30
More about that game/demo of NESMaker here:
http://troll.thenew8bitheroes.com/
2018-01-30 16:24:21 +00:00
Godzil
29a2deb1f3 Not sure what was done here before. 2018-01-30 16:18:12 +00:00
Godzil
05f17740fd Merge remote-tracking branch 'origin/master'
# Conflicts:
#	CMakeLists.txt
#	src/CMakeLists.txt
#	src/NESCarts.c
#	src/os/unix/graphics.c
#	src/ppu/debug/ppu.debug.c
2018-01-30 16:16:33 +00:00
Godzil
6e179a5866 Update glfw, and make TI-NESulator great again (and add Mapper #30 support) 2018-01-30 16:12:53 +00:00
Manoël Trapier
a6586b3467 Make travis happy, again (or try to) 2017-12-27 03:26:57 +01:00
Godzil
79e43a98e4 glext.h was not included hence the error. Using GLFW3 facility to include it as some OS have OpenGL/xxx other GL/xxx for include file... NASTY! 2017-03-17 14:59:18 +01:00
Godzil
9413fc5e27 Damn travis, be a bit more smart please! 2017-03-17 14:44:47 +01:00
Godzil
1158daab8b Change apt commands to be Linux only, switch to GL_TEXTURE_RECTANGLE, will it work? 2017-03-17 14:33:29 +01:00
Godzil
6f2bf79917 Need to investigate why travis OS X build miss GL_TEXTURE_RECTANGLE_ARB 2017-03-17 13:51:38 +01:00
Godzil
c7c21ce752 Switch GL_TEXTURE_RECTANGLE_EXT to the official GL_TEXTURE_RECTANGLE_ARB 2017-03-17 13:45:15 +01:00
Godzil
8b34ba6c26 We probably miss Glew on OS X 2017-03-17 13:35:29 +01:00
Godzil
e8171d4705 Add OS X build 2017-03-17 13:27:14 +01:00
Godzil
f5c15c741b Stupid me, stupid me.. 2017-03-17 13:25:09 +01:00
Godzil
1ac164cbda Slight version bump 2017-03-17 12:59:59 +01:00
Godzil
4da1c434cd Merge branch 'master' of github.com:Godzil/TI-NESulator 2017-03-17 12:31:54 +01:00
Godzil
6a1064a852 Some more update on coverages thingys 2017-03-17 12:31:20 +01:00
Manoël Trapier
0a0d086f31 Shut up GCC with your stupid warnings. 2017-03-17 09:03:46 +00:00
Godzil
a09f33fe33 Correct test call 2017-03-16 20:03:37 +01:00
Godzil
b6c4793f44 Update code coverage test to run headless for a full minute, correct some warning and bugs 2017-03-16 19:54:00 +01:00
Godzil
b0ed951235 More Travis/Code coverage things 2017-03-16 16:13:06 +01:00
Godzil
ff80e60879 Should now build under Linux. 2017-03-16 15:18:52 +01:00
Godzil
bfd4597afa Merge branch 'master' of github.com:Godzil/TI-NESulator 2017-03-16 13:23:19 +01:00
Godzil
7ffe343e7a More travis test 2017-03-16 13:23:11 +01:00
Godzil
75bac739ee Test travis CI 2017-03-16 13:14:32 +01:00
Manoël Trapier
779a22006c Update README.md 2017-03-16 12:06:47 +00:00
Manoël Trapier
3d3d6729f6 Update README.md 2017-03-16 11:35:55 +00:00
Godzil
d26bd788cf Update Win32 source folder 2017-02-24 12:16:03 +00:00
Godzil
cc9fe51828 Switch graphic & key management to OpenGL/GLFW3, correct sprite behaviour, still not perfect, but way better (no more issue with overlapping and overflow is correctly handled now)
->PPU still need a complete rewrite.
 Bump version to 0.7!
2016-12-29 18:21:39 +01:00
Godzil
866dcfa969 Add glfw as a submodule 2016-12-29 18:06:48 +01:00
Manoël Trapier
54a685cdaa Update memory.c
Correct a "bug" in the define of DEBUG, only one of define and undef should be enable at the same...
2016-11-17 14:40:31 +00:00
Godzil
bcf60e8d96 And add a link to it for markdown rendering 2016-11-17 08:36:22 +00:00
Godzil
0d6ed068ca Add a slightly proper readme file 2016-11-17 08:35:38 +00:00
godzil
bc65a7a4f0 Merge newcore branch into master/trunk. Correct lots of warning. (now warning are threat as error by default)
Signed-off-by: Godzil <godzil@godzil.net>
2012-01-31 15:15:55 +00:00
78 changed files with 3052 additions and 1148 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
#Temp files
/build*
*~
*.swp

6
.gitmodules vendored Normal file
View File

@@ -0,0 +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

40
.travis.yml Normal file
View File

@@ -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)

View File

@@ -9,8 +9,20 @@
# $HeadURL$ # $HeadURL$
# $Revision$ # $Revision$
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 2.4)
project (TINES) project (TINES)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory("external/glfw")
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
if (COVERALLS)
enable_testing()
endif (COVERALLS)
add_subdirectory (src) add_subdirectory (src)

21
README.md Normal file
View File

@@ -0,0 +1,21 @@
TI-NESulator
============
[![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
backups arount to recreate part of that history, but that not a fun thing to do to be
honest, and there is virtually nothing to gain from that.
The source is given as is, I have to select a proper licence for this code, but concider
it to be in a 3 clause BSD with a non commercial clause:
- You are free to use that code and integrate some part in your project
- Will need to state where some of your code come from
- This code is given as-is without any waranty of working as expected
- You CAN'T use that code for commercial product without my prior consent.

19
README.txt Normal file
View File

@@ -0,0 +1,19 @@
TI-NESulator
============
This is a cleaned version of the TI-NESulator repository (all 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
backups arount to recreate part of that history, but that not a fun thing to do to be
honest, and there is virtually nothing to gain from that.
The source is given as is, I have to select a proper licence for this code, but concider
it to be in a 3 clause BSD with a non commercial clause:
- You are free to use that code and integrate some part in your project
- Will need to state where some of your code come from
- This code is given as-is without any waranty of working as expected
- You CAN'T use that code for commercial product without my prior consent.

BIN
data/bad_apple_2.nes Normal file

Binary file not shown.

BIN
data/trollburner_demo.nes Normal file

Binary file not shown.

1
external/coveralls-cmake vendored Submodule

1
external/glfw vendored Submodule

Submodule external/glfw added at 525ad7bfb8

View File

@@ -2,15 +2,13 @@
# TI-NES CMake # TI-NES CMake
# #
# Created by Manoel TRAPIER. # Created by Manoel TRAPIER.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2003-2016 986-Studio. All rights reserved.
# #
# $LastChangedDate$ # $LastChangedDate$
# $Author$ # $Author$
# $HeadURL$ # $HeadURL$
# $Revision$ # $Revision$
include_directories($(TINES_SOURCE_DIR)/include)
########################## ##########################
# Configurations variables # Configurations variables
########################## ##########################
@@ -22,25 +20,20 @@ set(DETECT_BUS_CONFLICT OFF CACHE BOOL "Activate the bus conflit detector? (Coul
set(USE_EFENCE OFF CACHE BOOL "Use electricfence memory debugger?") set(USE_EFENCE OFF CACHE BOOL "Use electricfence memory debugger?")
set(USE_PROFILING OFF CACHE BOOL "Use profiling tools? (Will slow down a lot.)") set(USE_PROFILING OFF CACHE BOOL "Use profiling tools? (Will slow down a lot.)")
set(USE_ALLEGRO ON CACHE BOOL "Use Allegro backend" FORCE) set(USE_ALLEGRO ON CACHE BOOL "Use Allegro backend")
IF(NOT CMAKE_BUILD_TYPE) option(COVERALLS "Generate coveralls data" OFF)
SET(CMAKE_BUILD_TYPE Debug CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
if (APPLE)
SET (CMAKE_FIND_FRAMEWORK LAST)
endif (APPLE)
########################## ##########################
# Link & Compile flags # Link & Compile flags
########################## ##########################
add_definitions (-DNO_DECIMAL -DFAST_RDOP) 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_EXE_LINKER_FLAGS "-mmacosx-version-min=10.4") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/external/coveralls-cmake/cmake)
add_definitions (-DNO_DECIMAL)
if (PPU_ISPAL) if (PPU_ISPAL)
add_definitions (-DISPAL) add_definitions (-DISPAL)
@@ -60,15 +53,6 @@ if (DETECT_BUS_CONFLICT)
add_definitions (-DDETECT_BUS_CONFLICT) add_definitions (-DDETECT_BUS_CONFLICT)
endif (DETECT_BUS_CONFLICT) endif (DETECT_BUS_CONFLICT)
if (USE_EFENCE)
if (CMAKE_BUILD_TYPE MATCHES Release)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Debug info is forced" FORCE)
else(CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Debug info is forced" FORCE)
endif(CMAKE_BUILD_TYPE)
endif (USE_EFENCE)
if (USE_PROFILING) if (USE_PROFILING)
if (CMAKE_BUILD_TYPE MATCHES Rel) if (CMAKE_BUILD_TYPE MATCHES Rel)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Debug info is forced" FORCE) SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Debug info is forced" FORCE)
@@ -79,18 +63,13 @@ if (USE_PROFILING)
set(CMAKE_C_FLAGS -pg) set(CMAKE_C_FLAGS -pg)
endif (USE_PROFILING) endif (USE_PROFILING)
if (APPLE) if (COVERALLS)
include_directories(BEFORE /usr/include) add_definitions (-DRUN_COVERAGE)
endif (APPLE) include(Coveralls)
coveralls_turn_on_coverage()
endif()
#if the CPU is LSB set the define include_directories(include)
if (CMAKE_SYSTEM_PROCESSOR MATCHES i386 OR CMAKE_SYSTEM_PROCESSOR MATCHES [aA][rR][mM])
add_definitions (-DLSB_FIRST)
endif (CMAKE_SYSTEM_PROCESSOR MATCHES i386 OR CMAKE_SYSTEM_PROCESSOR MATCHES [aA][rR][mM])
#Add release mode extra C Flags
set (CMAKE_C_FLAGS_RELEASE "-fomit-frame-pointer -funroll-loops -Wall ${CMAKE_C_FLAGS_RELEASE}")
set (CMAKE_C_FLAGS_RELWITHDEBINFO "-fomit-frame-pointer -funroll-loops -Wall ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
add_subdirectory(apu) add_subdirectory(apu)
add_subdirectory(corecpu) add_subdirectory(corecpu)
@@ -102,36 +81,26 @@ add_subdirectory(ppu)
if (TARGET_TI68k) if (TARGET_TI68k)
add_subdirectory(os/ti68k) add_subdirectory(os/ti68k)
elseif (APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") elseif (WIN32)
add_subdirectory(os/macos)
elseif (UNIX)
add_subdirectory(os/win32) add_subdirectory(os/win32)
else (TARGET_TI68k) else (TARGET_TI68k)
#So we target UNIX like OS
add_subdirectory(os/unix) add_subdirectory(os/unix)
endif (TARGET_TI68k) endif (TARGET_TI68k)
add_library (main main.c paddle.c NESCarts.c)
add_executable(tines main.c)
set(CMAKE_FIND_FRAMEWORK LAST)
find_library(ALLEGROLIB allegro)
find_library(PTHREADLIB pthread) find_library(PTHREADLIB pthread)
if (USE_EFENCE) if (COVERALLS)
find_library(EFENCELIB efence) set(COVERAGE_SRCS src/main.c src/paddle.c src/NESCarts.c ${COVERAGE_SRCS})
target_link_libraries(tines ${EFENCELIB})
endif (USE_EFENCE)
if (USE_ALLEGRO) # Create the coveralls target.
target_link_libraries(tines debug alld-main) coveralls_setup(
target_link_libraries(tines optimized alleg-main) "${COVERAGE_SRCS}" # The source files.
if (APPLE) ON # If we should upload.
find_library(COCOALIB Cocoa) ) # (Optional) Alternate project cmake module path.
target_link_libraries(tines ${COCOALIB}) endif()
endif (APPLE)
endif (USE_ALLEGRO)
target_link_libraries(tines main apu corecpu mappermanager memorymanager pluginsmanager ppu oslib ${ALLEGROLIB} ${PTHREADLIB}) add_executable(tines main.c paddle.c NESCarts.c)
target_link_libraries(tines apu corecpu mappermanager memorymanager pluginsmanager ppu oslib ${PTHREADLIB})
add_test(NAME tines_test COMMAND $<TARGET_FILE:tines> ${PROJECT_SOURCE_DIR}/data/bad_apple_2.nes)

View File

@@ -3,7 +3,7 @@
* NESCart.c * NESCart.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -29,6 +29,7 @@
#include <NESCarts.h> #include <NESCarts.h>
#include <os_dependent.h> #include <os_dependent.h>
#include <mappers/manager.h> #include <mappers/manager.h>
#include <sys/mman.h>
void DumpCartProperties(FILE *out, NesCart * cart) void DumpCartProperties(FILE *out, NesCart * cart)
{ {
@@ -57,7 +58,7 @@ int LoadCart(const char *filename, NesCart * cart)
cart->File = (byte *)LoadFilePtr((char *)filename); cart->File = (byte *)LoadFilePtr((char *)filename);
if ((cart->File == NULL) || ((int)cart->File == -1)) if ((cart->File == NULL) || (cart->File == MAP_FAILED))
return -1; return -1;
sprintf(buffer, "%c%c%c%c", 0x4E, 0x45, 0x53, 0x1A); sprintf(buffer, "%c%c%c%c", 0x4E, 0x45, 0x53, 0x1A);

View File

@@ -2,11 +2,12 @@
# TI-NES CMake # TI-NES CMake
# #
# Created by Manoel TRAPIER. # Created by Manoel TRAPIER.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2003-2016 986-Studio. All rights reserved.
# #
# $LastChangedDate$ # $LastChangedDate$
# $Author$ # $Author$
# $HeadURL$ # $HeadURL$
# $Revision$ # $Revision$
add_library(apu SndAlleg.c Sound.c) add_library(apu SndUnixT.c Sound.c)
#add_library(apu SndAlleg.c Sound.c)

View File

@@ -43,7 +43,7 @@ static int MasterSwitch = (1<<SND_CHANNELS)-1;
static int LoopFreq = 25; static int LoopFreq = 25;
static int NoiseGen = 1; static int NoiseGen = 1;
static int Suspended = 0; static int Suspended = 0;
static int SoundRun = 0;
static struct static struct
{ {
int Type; /* Channel type (SND_*) */ int Type; /* Channel type (SND_*) */
@@ -351,6 +351,7 @@ int InitSound(int Rate,int Verbose)
pthread_detach(ThreadID); pthread_detach(ThreadID);
/* Done */ /* Done */
SoundRun = 1;
if(Verbose) puts("OK"); if(Verbose) puts("OK");
return(SoundRate=Rate); return(SoundRate=Rate);
} }
@@ -360,10 +361,13 @@ int InitSound(int Rate,int Verbose)
/*************************************************************/ /*************************************************************/
void TrashSound(void) void TrashSound(void)
{ {
StopSound(); if (SoundRun == 1)
console_printf(Console_Default, "%s: Kill thread...\n", __func__); {
if(ThreadID) pthread_cancel(ThreadID); StopSound();
console_printf(Console_Default, "%s: Kill thread...\n", __func__);
if(ThreadID) pthread_cancel(ThreadID);
}
SoundRun = 0;
SoundRate = 0; SoundRate = 0;
ThreadID = 0; ThreadID = 0;
} }

View File

@@ -10,9 +10,7 @@
/** commercially. Please, notify me, if you make any **/ /** commercially. Please, notify me, if you make any **/
/** changes to this file. **/ /** changes to this file. **/
/*************************************************************/ /*************************************************************/
#ifdef UNIX //#include "Sound.h"
#include "Sound.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@@ -21,6 +19,8 @@
#include <pthread.h> #include <pthread.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <os_dependent.h>
#if 0
#ifdef SUN_AUDIO #ifdef SUN_AUDIO
#include <sys/audioio.h> #include <sys/audioio.h>
@@ -106,7 +106,7 @@ static struct
int Count; /* Phase counter */ int Count; /* Phase counter */
} CH[SND_CHANNELS]; } CH[SND_CHANNELS];
static void UnixSetWave(int Channel,signed char *Data,int Length,int Rate); static void UnixSetWave(int Channel, signed char *Data,int Length,int Freq);
static void UnixSetSound(int Channel,int NewType); static void UnixSetSound(int Channel,int NewType);
static void UnixDrum(int Type,int Force); static void UnixDrum(int Type,int Force);
static void UnixSetChannels(int Volume,int Switch); static void UnixSetChannels(int Volume,int Switch);
@@ -221,6 +221,9 @@ static void *DSPLoop(void *Arg)
unsigned char Buf[SND_BUFSIZE]; unsigned char Buf[SND_BUFSIZE];
register int J,I,K,L,M,N,L1,L2,A1,A2,V; register int J,I,K,L,M,N,L1,L2,A1,A2,V;
int FreqCount; int FreqCount;
int ret;
L = N = A2 = 0;
for(J=0;J<SND_CHANNELS;J++) for(J=0;J<SND_CHANNELS;J++)
{ {
@@ -421,7 +424,7 @@ static void *DSPLoop(void *Arg)
/* We'll block here until next DMA buffer becomes free. It happens /* We'll block here until next DMA buffer becomes free. It happens
** once per (1<<SND_BITS)/SoundRate seconds. ** once per (1<<SND_BITS)/SoundRate seconds.
*/ */
write(SoundFD,Buf,SND_BUFSIZE); ret = write(SoundFD,Buf,SND_BUFSIZE);
#endif #endif
} }
} }
@@ -531,13 +534,13 @@ void UnixSetSound(int Channel,int NewType)
/** waveform to be an instrument or set it to the waveform **/ /** waveform to be an instrument or set it to the waveform **/
/** own playback rate. **/ /** own playback rate. **/
/*************************************************************/ /*************************************************************/
void UnixSetWave(int Channel,signed char *Data,int Length,int Rate) void UnixSetWave(int Channel, signed char *Data, int Length, int Freq)
{ {
if((Channel<0)||(Channel>=SND_CHANNELS)||(Length<=0)) return; if((Channel<0)||(Channel>=SND_CHANNELS)||(Length<=0)) return;
CH[Channel].Type = SND_WAVE; CH[Channel].Type = SND_WAVE;
CH[Channel].Length = Length; CH[Channel].Length = Length;
CH[Channel].Rate = Rate; CH[Channel].Rate = Freq;
CH[Channel].Pos = 0; CH[Channel].Pos = 0;
CH[Channel].Count = 0; CH[Channel].Count = 0;
CH[Channel].Data = Data; CH[Channel].Data = Data;
@@ -550,5 +553,4 @@ void UnixDrum(int Type,int Force)
{ {
/* This function is currently empty */ /* This function is currently empty */
} }
#endif
#endif /* UNIX */

View File

@@ -36,7 +36,7 @@ struct SndDriverStruct SndDriver =
(void (*)(int,int))0, (void (*)(int,int))0,
(void (*)(int,int))0, (void (*)(int,int))0,
(void (*)(int,int,int))0, (void (*)(int,int,int))0,
(void (*)(int,const signed char *,int,int))0, (void (*)(int,signed char *,int,int))0,
(const signed char *(*)(int))0 (const signed char *(*)(int))0
}; };
@@ -167,7 +167,7 @@ void SetChannels(int Volume,int Switch)
/** waveform to be an instrument or set it to the waveform **/ /** waveform to be an instrument or set it to the waveform **/
/** own playback rate. **/ /** own playback rate. **/
/*************************************************************/ /*************************************************************/
void SetWave(int Channel,const signed char *Data,int Length,int Rate) void SetWave(int Channel,signed char *Data,int Length,int Rate)
{ {
if((Channel<0)||(Length<=0)) return; if((Channel<0)||(Length<=0)) return;

View File

@@ -9,4 +9,8 @@
# $HeadURL$ # $HeadURL$
# $Revision$ # $Revision$
if (COVERALLS)
set(COVERAGE_SRCS src/corecpu/corecpu.c ${COVERAGE_SRCS} PARENT_SCOPE)
endif()
add_library(corecpu corecpu.c) add_library(corecpu corecpu.c)

View File

@@ -12,9 +12,12 @@
* *
*/ */
/* TODO: Add Inst/MemAccess breakpoints */
/* Depending on the OS, one of these provide the malloc function */ /* Depending on the OS, one of these provide the malloc function */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <os_dependent.h> #include <os_dependent.h>
@@ -26,14 +29,68 @@
//#define TRACE_INSTRUCTIONS //#define TRACE_INSTRUCTIONS
#ifdef TRACE_INSTRUCTIONS #ifdef TRACE_INSTRUCTIONS
#define TRACEi(trace) do { console_printf(Console_Debug, "$%04X - ", cpu->reg_PC - 1); console_printf_d trace ; console_printf(Console_Debug, "\n"); } while(0) #define TRACEi(trace) do { console_printf(Console_Debug, ">> $%04X - ", cpu->reg_PC-1); console_printf_d trace ; console_printf(Console_Debug, "\n"); } while(0)
#define TRACEiE(trace) do { console_printf(Console_Debug, "$%04X - ", cpu->reg_PC - 1); console_printf_d trace ; console_printf(Console_Debug, "\n"); } while(0) #define TRACEiE(trace) do { console_printf(Console_Debug, ">> $%04X - ", cpu->reg_PC-1); console_printf_d trace ; console_printf(Console_Debug, "\n"); } while(0)
#else #else
#define TRACEi(trace) { } #define TRACEi(trace) { }
//#define TRACEiE(trace) { } //#define TRACEiE(trace) { }
#define TRACEiE(trace) do { console_printf(Console_Debug, "$%04X - ", cpu->reg_PC - 1); console_printf_d trace ; console_printf(Console_Debug, "\n"); } while(0) #define TRACEiE(trace) do { console_printf(Console_Debug, ">> $%04X - ", cpu->reg_PC-1); console_printf_d trace ; console_printf(Console_Debug, "\n"); } while(0)
#endif #endif
/*
* IP_ == "Instruction Parameter"
* nP: No parameters
* iM: Immediate
* iX: Indirect by X
* iY: Indirect by Y
* zP: Zero Page
* zX: Zero Page Indexec by X
* zY: Zero Page Indexec by Y
* iD: Indirect Double
* aB: Absolute
* aX: Absolute by X
* aY: Absolute by Y
* rE: Relative
*/
#define IP_nP "N"
#define IP_iM "I"
#define IP_iX "X"
#define IP_iY "Y"
#define IP_zP "0"
#define IP_zX "z"
#define IP_zY "Z"
#define IP_iD "D"
#define IP_aB "A"
#define IP_aX "x"
#define IP_aY "y"
#define IP_rE "R"
#define IP_nPc 'N'
#define IP_iMc 'I'
#define IP_iXc 'X'
#define IP_iYc 'Y'
#define IP_zPc '0'
#define IP_zXc 'z'
#define IP_zYc 'Z'
#define IP_iDc 'D'
#define IP_aBc 'A'
#define IP_aXc 'x'
#define IP_aYc 'y'
#define IP_rEc 'R'
#define IPf_nP ""
#define IPf_iM " $%02X"
#define IPf_iX " ($%02X,X)"
#define IPf_iY " ($%02X),Y"
#define IPf_zP " $%02X"
#define IPf_zX " $%02X,X"
#define IPf_zY " $%02X,Y"
#define IPf_iD " ($%02X%02X)"
#define IPf_aB " $%02X%02X"
#define IPf_aX " $%02X%02X,X"
#define IPf_aY " $%02X%02X,Y"
#define IPf_rE " $%02X%02X"
#define _INTERNAL_QUICK6502_CORECPU_ #define _INTERNAL_QUICK6502_CORECPU_
#include "corecpu.h" #include "corecpu.h"
@@ -49,15 +106,15 @@
#define MEMORY_READ_ZP() cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC++)) #define MEMORY_READ_ZP() cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC++))
#define MEMORY_READ_IX() cpu->memory_read( (cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) + cpu->reg_X ) & 0xFF) |\ #define MEMORY_READ_IX() cpu->memory_read( (cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) + cpu->reg_X ) & 0xFF) |\
(cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_X + 1) << 8) ) (cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) + cpu->reg_X + 1) << 8) ); cpu->reg_PC++
#define MEMORY_READ_IY() cpu->memory_read( ( cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) ) |\ #define MEMORY_READ_IY() cpu->memory_read( ( cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) ) |\
(cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC++) + 1) << 8) ) + cpu->reg_Y ) (cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) + 1) << 8) ) + cpu->reg_Y ); cpu->reg_PC++
#define MEMORY_READ_ZX() cpu->memory_page0_read( (cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_X) ) #define MEMORY_READ_ZX() cpu->memory_page0_read( (cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_X) )
#define MEMORY_READ_ZY() cpu->memory_page0_read( (cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_Y) ) #define MEMORY_READ_ZY() cpu->memory_page0_read( (cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_Y) )
#define MEMORY_READ_AB() cpu->memory_read( ((cpu->memory_opcode_read(cpu->reg_PC++) ) |\ #define MEMORY_READ_AB() cpu->memory_read( ((cpu->memory_opcode_read(cpu->reg_PC ) ) |\
(cpu->memory_opcode_read(cpu->reg_PC++) << 8) )) (cpu->memory_opcode_read(cpu->reg_PC+1) << 8) )); cpu->reg_PC += 2
#define MEMORY_READ_AX() cpu->memory_read( ((op1 ) |\ #define MEMORY_READ_AX() cpu->memory_read( ((op1 ) |\
(op2 << 8) ) + cpu->reg_X) (op2 << 8) ) + cpu->reg_X)
@@ -68,26 +125,26 @@
#define MEMORY_WRITE_ZP(val) cpu->memory_page0_write(cpu->memory_opcode_read(cpu->reg_PC++), val) #define MEMORY_WRITE_ZP(val) cpu->memory_page0_write(cpu->memory_opcode_read(cpu->reg_PC++), val)
#define MEMORY_WRITE_IX(val) cpu->memory_write( (cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) + cpu->reg_X ) & 0xFF) |\ #define MEMORY_WRITE_IX(val) cpu->memory_write( (cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) + cpu->reg_X ) & 0xFF) |\
(cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_X + 1) << 8) , val) (cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) + cpu->reg_X + 1) << 8) , val); cpu->reg_PC++
#define MEMORY_WRITE_IY(val) cpu->memory_write( ( cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) ) |\ #define MEMORY_WRITE_IY(val) cpu->memory_write( ( cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) ) |\
(cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC++) + 1) << 8) ) + cpu->reg_Y , val) (cpu->memory_page0_read(cpu->memory_opcode_read(cpu->reg_PC ) + 1) << 8) ) + cpu->reg_Y , val); cpu->reg_PC++
#define MEMORY_WRITE_ZX(val) cpu->memory_page0_write( (cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_X), val) #define MEMORY_WRITE_ZX(val) cpu->memory_page0_write( (cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_X), val)
#define MEMORY_WRITE_ZY(val) cpu->memory_page0_write( (cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_Y), val) #define MEMORY_WRITE_ZY(val) cpu->memory_page0_write( (cpu->memory_opcode_read(cpu->reg_PC++) + cpu->reg_Y), val)
#define MEMORY_WRITE_AB(val) cpu->memory_write( ((cpu->memory_opcode_read(cpu->reg_PC++) ) |\ #define MEMORY_WRITE_AB(val) cpu->memory_write( ((cpu->memory_opcode_read(cpu->reg_PC ) ) |\
(cpu->memory_opcode_read(cpu->reg_PC++) << 8) ), val) (cpu->memory_opcode_read(cpu->reg_PC+1) << 8) ), val); cpu->reg_PC += 2
#define MEMORY_WRITE_AX(val) cpu->memory_write( ((cpu->memory_opcode_read(cpu->reg_PC++) ) |\ #define MEMORY_WRITE_AX(val) cpu->memory_write( ((cpu->memory_opcode_read(cpu->reg_PC ) ) |\
(cpu->memory_opcode_read(cpu->reg_PC++) << 8) ) + cpu->reg_X, val) (cpu->memory_opcode_read(cpu->reg_PC+1) << 8) ) + cpu->reg_X, val); cpu->reg_PC += 2
#define MEMORY_WRITE_AY(val) cpu->memory_write( ((cpu->memory_opcode_read(cpu->reg_PC++) ) |\ #define MEMORY_WRITE_AY(val) cpu->memory_write( ((cpu->memory_opcode_read(cpu->reg_PC ) ) |\
(cpu->memory_opcode_read(cpu->reg_PC++) << 8) ) + cpu->reg_Y, val) (cpu->memory_opcode_read(cpu->reg_PC+1) << 8) ) + cpu->reg_Y, val); cpu->reg_PC += 2
#define PUSH_S(value) cpu->memory_stack_write(0x100 | (cpu->reg_S--), value) #define PUSH_S(value) cpu->memory_stack_write(0x100 | (cpu->reg_S--), value)
#define POP_S() (cpu->memory_stack_read (0x100 | (++cpu->reg_S) )) #define POP_S() (cpu->memory_stack_read (0x100 | (++cpu->reg_S) ))
#ifdef NO_DECIMAL #ifdef Q6502_NO_DECIMAL
#define ADC_OPERATION(read) do {\ #define ADC_OPERATION(read) do {\
unsigned short tmp = 0; unsigned char v = read; \ unsigned short tmp = 0; unsigned char v = read; \
@@ -110,7 +167,7 @@
} while(0) } while(0)
#else #else
#error Quick6502 doesn't actually support DECIMAL mode #error Quick6502 doesn t actually support DECIMAL mode
#endif #endif
@@ -346,7 +403,7 @@ void quick6502_int(quick6502_cpu *cpu, quick6502_signal signal)
PUSH_S((cpu->reg_PC >> 8) & 0xFF ); PUSH_S((cpu->reg_PC >> 8) & 0xFF );
PUSH_S((cpu->reg_PC ) & 0xFF ); PUSH_S((cpu->reg_PC ) & 0xFF );
PUSH_S( cpu->reg_P ); PUSH_S( cpu->reg_P );
cpu->reg_P = cpu->reg_P | Q6502_I_FLAG & ~Q6502_B_FLAG; cpu->reg_P = (cpu->reg_P | Q6502_I_FLAG) & ~Q6502_B_FLAG;
cpu->reg_PC = (cpu->memory_read(Q6502_NMI_LOW)) | (cpu->memory_read(Q6502_NMI_HIGH)<<8); cpu->reg_PC = (cpu->memory_read(Q6502_NMI_LOW)) | (cpu->memory_read(Q6502_NMI_HIGH)<<8);
@@ -363,10 +420,10 @@ void quick6502_int(quick6502_cpu *cpu, quick6502_signal signal)
void quick6502_dump(quick6502_cpu *cpu, FILE * fp) void quick6502_dump(quick6502_cpu *cpu, FILE * fp)
{ {
short i; short i;
char instr[20]; char instr[100];
/* Display registers */ /* Display registers */
fprintf(fp, fprintf(fp,
"Quick6502: PC:$%04X A:$%02X X:$%02X Y:$%02X S:$%02X P:$%02X P:[%c%c%c%c%c%c%c%c]\n", "## Quick6502: PC:$%04X A:$%02X X:$%02X Y:$%02X S:$%02X P:$%02X [%c%c%c%c%c%c%c%c]\n",
cpu->reg_PC, cpu->reg_A, cpu->reg_X, cpu->reg_Y, cpu->reg_S, cpu->reg_P, cpu->reg_PC, cpu->reg_A, cpu->reg_X, cpu->reg_Y, cpu->reg_S, cpu->reg_P,
cpu->reg_P&Q6502_N_FLAG ? 'N':'.', cpu->reg_P&Q6502_N_FLAG ? 'N':'.',
cpu->reg_P&Q6502_V_FLAG ? 'V':'.', cpu->reg_P&Q6502_V_FLAG ? 'V':'.',
@@ -379,28 +436,59 @@ void quick6502_dump(quick6502_cpu *cpu, FILE * fp)
); );
/* Display stack */ /* Display stack */
fprintf(fp, "Quick6502: Stack: [ "); fprintf(fp, "## Quick6502: Stack: [ ");
for (i = cpu->reg_S+1; i < 0x100; i++) for (i = cpu->reg_S+1; i < 0x100; i++)
{ {
fprintf(fp, "$%02X ", cpu->memory_opcode_read(0x100 | i)); fprintf(fp, "$%02X ", cpu->memory_read(0x100 | i));
} }
fprintf(fp, "] Run:%c Cycle:%ld\n", cpu->running?'Y':'N', cpu->cycle_done); fprintf(fp, "] Run:%c Cycle:%ld\n", cpu->running?'Y':'N', cpu->cycle_done);
quick6502_getinstruction(cpu, cpu->reg_PC, instr); fprintf(fp, "## Quick6502: InstrMem: [ ");
fprintf(fp, "Quick6502: Instruction at PC: %s\n", instr); for (i = 0; i < 0x5; i++)
{
fprintf(fp, "$%02X ", cpu->memory_opcode_read(cpu->reg_PC + i));
}
fprintf(fp, "]\n");
quick6502_getinstruction(cpu, (1==1), cpu->reg_PC, instr, NULL);
fprintf(fp, "## $%04X: %s\n", cpu->reg_PC, instr);
} }
/** Get current instruction name at specified address and put it into buffer */ typedef enum InstructionNameTag
void quick6502_getinstruction(quick6502_cpu *cpu, unsigned short addr, char *buffer)
{ {
buffer[0] = 0; n_ILG = 0, n_NOP,
} n_CLI, n_SEI, n_CLC, n_SEC, n_CLD, n_SED, n_CLV,
n_LDA, n_LDX, n_LDY, n_STA, n_STX, n_STY,
n_TXA, n_TAX, n_TAY, n_TYA, n_TSX, n_TXS,
n_PHA, n_PLA, n_PHP, n_PLP,
n_DEX, n_DEY, n_INX, n_INY, n_DEC, n_INC,
n_JSR, n_RTS, n_JMP, n_BRK, n_RTI,
n_BCC, n_BCS, n_BEQ, n_BNE, n_BHI, n_BPL, n_BVS, n_BVC, n_BMI,
n_EOR, n_AND, n_BIT, n_ORA, n_ADC, n_SBC,
n_ROL, n_ROR, n_ASL, n_LSR,
n_CMP, n_CPX, n_CPY,
} InstructionNameTag;
char *InstructionName[] =
{
"ILLEGAL", "NOP",
"CLI", "SEI", "CLC", "SEC", "CLD", "SED", "CLV",
"LDA", "LDX", "LDY", "STA", "STX", "STY",
"TXA", "TAX", "TAY", "TYA", "TSX", "TXS",
"PHA", "PLA", "PHP", "PLP",
"DEX", "DEY", "INX", "INY", "DEC", "INC",
"JSR", "RTS", "JMP", "BRK", "RTI",
"BCC", "BCS", "BEQ", "BNE", "BHI", "BPL", "BVS", "BVC", "BVS",
"EOR", "AND", "BIT", "ORA", "ADC", "SBC",
"ROL", "ROR", "ASL", "LSR",
"CMP", "CPX", "CPY",
};
/** /**
* Free the CPU * Free the CPU
* *
* This function will free the CPU only if it's not currently used, it will * This function will free the CPU only if it's not currently used, it will
* return !0 if everything goes well and 0 if the free is impossible * return 0 if everything goes well and !0 if the free is impossible
*/ */
int quick6502_free(quick6502_cpu *cpu) int quick6502_free(quick6502_cpu *cpu)
{ {
@@ -447,52 +535,52 @@ INSTRUCTION(ILLEG)
} }
/** 58 : CLI - CLear Interrupt **/ /** 58 : CLI - CLear Interrupt **/
INSTRUCTION(CLIiM) INSTRUCTION(CLInP)
{ {
TRACEi(("CLC")); TRACEi(("CLI"));
cpu->reg_P &= ~Q6502_I_FLAG; cpu->reg_P &= ~Q6502_I_FLAG;
} }
/** 78 : SEI - SEt Interrupt **/ /** 78 : SEI - SEt Interrupt **/
INSTRUCTION(SEIiM) INSTRUCTION(SEInP)
{ {
TRACEi(("SEI")); TRACEi(("SEI"));
cpu->reg_P |= Q6502_I_FLAG; cpu->reg_P |= Q6502_I_FLAG;
} }
/** 18 : CLC - CLear Carry **/ /** 18 : CLC - CLear Carry **/
INSTRUCTION(CLCiM) INSTRUCTION(CLCnP)
{ {
TRACEi(("CLC")); TRACEi(("CLC"));
cpu->reg_P &= ~Q6502_C_FLAG; cpu->reg_P &= ~Q6502_C_FLAG;
} }
/** 38 : SEC - SEt Carry **/ /** 38 : SEC - SEt Carry **/
INSTRUCTION(SECiM) INSTRUCTION(SECnP)
{ {
TRACEi(("SEC")); TRACEi(("SEC"));
cpu->reg_P |= Q6502_C_FLAG; cpu->reg_P |= Q6502_C_FLAG;
} }
/** D8 : CLD - CLear Decimal **/ /** D8 : CLD - CLear Decimal **/
INSTRUCTION(CLDiM) INSTRUCTION(CLDnP)
{ {
TRACEi(("CLD")); TRACEi(("CLD"));
cpu->reg_P &= ~Q6502_D_FLAG; cpu->reg_P &= ~Q6502_D_FLAG;
} }
/** F8 : SED - SEt Decimal **/ /** F8 : SED - SEt Decimal **/
INSTRUCTION(SEDiM) INSTRUCTION(SEDnP)
{ {
TRACEi(("SED")); TRACEi(("SED"));
cpu->reg_P |= Q6502_D_FLAG; cpu->reg_P |= Q6502_D_FLAG;
} }
/** B8 : CLV - CLear oVerflo **/ /** B8 : CLV - CLear oVerflo **/
INSTRUCTION(CLViM) INSTRUCTION(CLVnP)
{ {
TRACEi(("CLV")); TRACEi(("CLV"));
cpu->reg_P &= ~Q6502_V_FLAG; cpu->reg_P &= ~Q6502_V_FLAG;
} }
/** EA : NOP - NO oPeration **/ /** EA : NOP - NO oPeration **/
INSTRUCTION(NOPiM) INSTRUCTION(NOPnP)
{ {
TRACEi(("NOP")); TRACEi(("NOP"));
} }
@@ -752,7 +840,7 @@ INSTRUCTION(STYaB)
/**** Register functions ****/ /**** Register functions ****/
/** AA : TAX - Transfer A to X **/ /** AA : TAX - Transfer A to X **/
INSTRUCTION(TAXiM) INSTRUCTION(TAXnP)
{ {
TRACEi(("TAX")); TRACEi(("TAX"));
cpu->reg_X = cpu->reg_A; cpu->reg_X = cpu->reg_A;
@@ -760,7 +848,7 @@ INSTRUCTION(TAXiM)
} }
/** 8A : TXA - Transfer X to A **/ /** 8A : TXA - Transfer X to A **/
INSTRUCTION(TXAiM) INSTRUCTION(TXAnP)
{ {
TRACEi(("TXA")); TRACEi(("TXA"));
cpu->reg_A = cpu->reg_X; cpu->reg_A = cpu->reg_X;
@@ -768,7 +856,7 @@ INSTRUCTION(TXAiM)
} }
/** A8 : TAY - Transfer A to Y **/ /** A8 : TAY - Transfer A to Y **/
INSTRUCTION(TAYiM) INSTRUCTION(TAYnP)
{ {
TRACEi(("TAY")); TRACEi(("TAY"));
cpu->reg_Y = cpu->reg_A; cpu->reg_Y = cpu->reg_A;
@@ -776,7 +864,7 @@ INSTRUCTION(TAYiM)
} }
/** 98 : TYA - Transfer Y to A **/ /** 98 : TYA - Transfer Y to A **/
INSTRUCTION(TYAiM) INSTRUCTION(TYAnP)
{ {
TRACEi(("TYA")); TRACEi(("TYA"));
cpu->reg_A = cpu->reg_Y; cpu->reg_A = cpu->reg_Y;
@@ -784,7 +872,7 @@ INSTRUCTION(TYAiM)
} }
/* BA : TSX - Transfer S to X **/ /* BA : TSX - Transfer S to X **/
INSTRUCTION(TSXiM) INSTRUCTION(TSXnP)
{ {
TRACEi(("TSX")); TRACEi(("TSX"));
cpu->reg_X = cpu->reg_S; cpu->reg_X = cpu->reg_S;
@@ -792,7 +880,7 @@ INSTRUCTION(TSXiM)
} }
/** 9A : TXS - Transfer X to S **/ /** 9A : TXS - Transfer X to S **/
INSTRUCTION(TXSiM) INSTRUCTION(TXSnP)
{ {
TRACEi(("TXS")); TRACEi(("TXS"));
cpu->reg_S = cpu->reg_X; cpu->reg_S = cpu->reg_X;
@@ -801,7 +889,7 @@ INSTRUCTION(TXSiM)
/**** Simple register operation instructions ****/ /**** Simple register operation instructions ****/
/** CA : DEX - DEcrement X **/ /** CA : DEX - DEcrement X **/
INSTRUCTION(DEXiM) INSTRUCTION(DEXnP)
{ {
TRACEi(("DEX")); TRACEi(("DEX"));
cpu->reg_X --; cpu->reg_X --;
@@ -809,7 +897,7 @@ INSTRUCTION(DEXiM)
} }
/** 88 : DEY - DEcrement Y **/ /** 88 : DEY - DEcrement Y **/
INSTRUCTION(DEYiM) INSTRUCTION(DEYnP)
{ {
TRACEi(("DEY")); TRACEi(("DEY"));
cpu->reg_Y --; cpu->reg_Y --;
@@ -817,7 +905,7 @@ INSTRUCTION(DEYiM)
} }
/** E8 : INX - INcrement X **/ /** E8 : INX - INcrement X **/
INSTRUCTION(INXiM) INSTRUCTION(INXnP)
{ {
TRACEi(("INX")); TRACEi(("INX"));
cpu->reg_X ++; cpu->reg_X ++;
@@ -825,7 +913,7 @@ INSTRUCTION(INXiM)
} }
/** C8 : INY - INcrement Y **/ /** C8 : INY - INcrement Y **/
INSTRUCTION(INYiM) INSTRUCTION(INYnP)
{ {
TRACEi(("INY")); TRACEi(("INY"));
cpu->reg_Y ++; cpu->reg_Y ++;
@@ -835,14 +923,14 @@ INSTRUCTION(INYiM)
/**** Stack related instructions ****/ /**** Stack related instructions ****/
/** 48 : PHA - PusH A */ /** 48 : PHA - PusH A */
INSTRUCTION(PHAiM) INSTRUCTION(PHAnP)
{ {
TRACEi(("PHA")); TRACEi(("PHA"));
PUSH_S(cpu->reg_A); PUSH_S(cpu->reg_A);
} }
/** 68 : PLA - PuLl A */ /** 68 : PLA - PuLl A */
INSTRUCTION(PLAiM) INSTRUCTION(PLAnP)
{ {
TRACEi(("PLA")); TRACEi(("PLA"));
cpu->reg_A = POP_S(); cpu->reg_A = POP_S();
@@ -850,14 +938,14 @@ INSTRUCTION(PLAiM)
} }
/** 08 : PHP - PusH P */ /** 08 : PHP - PusH P */
INSTRUCTION(PHPiM) INSTRUCTION(PHPnP)
{ {
TRACEi(("PHP")); TRACEi(("PHP"));
PUSH_S((cpu->reg_P | Q6502_R_FLAG | Q6502_B_FLAG)); PUSH_S((cpu->reg_P | Q6502_R_FLAG | Q6502_B_FLAG));
} }
/** 28 : PLP - PuLl P */ /** 28 : PLP - PuLl P */
INSTRUCTION(PLPiM) INSTRUCTION(PLPnP)
{ {
TRACEi(("PLP")); TRACEi(("PLP"));
cpu->reg_P = POP_S() & ~(Q6502_R_FLAG | Q6502_B_FLAG); cpu->reg_P = POP_S() & ~(Q6502_R_FLAG | Q6502_B_FLAG);
@@ -880,10 +968,11 @@ INSTRUCTION(JSRaB)
} }
/** 60 : RTS - ReTurn from Subrutine */ /** 60 : RTS - ReTurn from Subrutine */
INSTRUCTION(RTSiM) INSTRUCTION(RTSnP)
{ {
TRACEi(("RTS")); TRACEi(("RTS"));
cpu->reg_PC = POP_S() | (POP_S() << 8); cpu->reg_PC = POP_S();
cpu->reg_PC |= (POP_S() << 8);
cpu->reg_PC ++; cpu->reg_PC ++;
} }
@@ -891,7 +980,7 @@ INSTRUCTION(RTSiM)
INSTRUCTION(JMPaB) INSTRUCTION(JMPaB)
{ {
TRACEi(("JMP $%02X%02X", cpu->memory_opcode_read(cpu->reg_PC+1), cpu->memory_opcode_read(cpu->reg_PC))); TRACEi(("JMP $%02X%02X", cpu->memory_opcode_read(cpu->reg_PC+1), cpu->memory_opcode_read(cpu->reg_PC)));
cpu->reg_PC = cpu->memory_opcode_read(cpu->reg_PC++) | (cpu->memory_opcode_read(cpu->reg_PC) << 8); cpu->reg_PC = cpu->memory_opcode_read(cpu->reg_PC) | (cpu->memory_opcode_read(cpu->reg_PC+1) << 8);
} }
/** 6C : JMP ($xxxx) - JuMP inconditionaly to ($xxxx) **/ /** 6C : JMP ($xxxx) - JuMP inconditionaly to ($xxxx) **/
@@ -904,7 +993,7 @@ INSTRUCTION(JMPiD)
} }
/** 00 : BRK - BReaK **/ /** 00 : BRK - BReaK **/
INSTRUCTION(BRKiM) INSTRUCTION(BRKnP)
{ {
TRACEi(("BRK")); TRACEi(("BRK"));
cpu->reg_PC++; cpu->reg_PC++;
@@ -917,11 +1006,12 @@ INSTRUCTION(BRKiM)
} }
/** 40 : RTI - ReTurn from Interruption **/ /** 40 : RTI - ReTurn from Interruption **/
INSTRUCTION(RTIiM) INSTRUCTION(RTInP)
{ {
TRACEi(("RTI")); TRACEi(("RTI"));
cpu->reg_P = POP_S(); cpu->reg_P = POP_S();
cpu->reg_PC = POP_S() | (POP_S() << 8); cpu->reg_PC = POP_S();
cpu->reg_PC |= (POP_S() << 8);
if (cpu->int_pending != 0) if (cpu->int_pending != 0)
{ {
@@ -935,7 +1025,7 @@ INSTRUCTION(BCCrE)
TRACEi(("BCC $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1)); TRACEi(("BCC $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1));
if (!(cpu->reg_P & Q6502_C_FLAG)) if (!(cpu->reg_P & Q6502_C_FLAG))
{ {
cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC++) + 1; cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1;
/* Need to set timing */ /* Need to set timing */
/* +1 is same page */ /* +1 is same page */
@@ -952,7 +1042,7 @@ INSTRUCTION(BCSrE)
TRACEi(("BCS $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1)); TRACEi(("BCS $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1));
if (cpu->reg_P & Q6502_C_FLAG) if (cpu->reg_P & Q6502_C_FLAG)
{ {
cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC ++) + 1; cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1;
/* Need to set timing */ /* Need to set timing */
/* +1 is same page */ /* +1 is same page */
@@ -969,7 +1059,7 @@ INSTRUCTION(BEQrE)
TRACEi(("BEQ $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1)); TRACEi(("BEQ $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1));
if (cpu->reg_P & Q6502_Z_FLAG) if (cpu->reg_P & Q6502_Z_FLAG)
{ {
cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC ++) + 1; cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1;
/* Need to set timing */ /* Need to set timing */
/* +1 is same page */ /* +1 is same page */
@@ -986,7 +1076,7 @@ INSTRUCTION(BMIrE)
TRACEi(("BMI $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1)); TRACEi(("BMI $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1));
if (cpu->reg_P & Q6502_N_FLAG) if (cpu->reg_P & Q6502_N_FLAG)
{ {
cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC ++) + 1; cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1;
/* Need to set timing */ /* Need to set timing */
/* +1 is same page */ /* +1 is same page */
@@ -1003,7 +1093,7 @@ INSTRUCTION(BNErE)
TRACEi(("BNE $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1)); TRACEi(("BNE $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1));
if (!(cpu->reg_P & Q6502_Z_FLAG)) if (!(cpu->reg_P & Q6502_Z_FLAG))
{ {
cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC ++) + 1; cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1;
/* Need to set timing */ /* Need to set timing */
/* +1 is same page */ /* +1 is same page */
@@ -1020,7 +1110,7 @@ INSTRUCTION(BPLrE)
TRACEi(("BPL $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1)); TRACEi(("BPL $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1));
if (!(cpu->reg_P & Q6502_N_FLAG)) if (!(cpu->reg_P & Q6502_N_FLAG))
{ {
cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC ++) + 1; cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1;
/* Need to set timing */ /* Need to set timing */
/* +1 is same page */ /* +1 is same page */
@@ -1037,7 +1127,7 @@ INSTRUCTION(BVCrE)
TRACEi(("BVC $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1)); TRACEi(("BVC $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1));
if (!(cpu->reg_P & Q6502_V_FLAG)) if (!(cpu->reg_P & Q6502_V_FLAG))
{ {
cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC ++) + 1; cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1;
/* Need to set timing */ /* Need to set timing */
/* +1 is same page */ /* +1 is same page */
@@ -1054,7 +1144,7 @@ INSTRUCTION(BVSrE)
TRACEi(("BVS $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1)); TRACEi(("BVS $%04X", cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1));
if (cpu->reg_P & Q6502_V_FLAG) if (cpu->reg_P & Q6502_V_FLAG)
{ {
cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC ++) + 1; cpu->reg_PC += (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1;
/* Need to set timing */ /* Need to set timing */
/* +1 is same page */ /* +1 is same page */
@@ -1515,28 +1605,28 @@ INSTRUCTION(BITaB)
} }
/** 2A : ROL A **/ /** 2A : ROL A **/
INSTRUCTION(ROLiM) INSTRUCTION(ROLnP)
{ {
TRACEi(("ROL A")); TRACEi(("ROL A"));
ROL_OPERATION(cpu->reg_A); ROL_OPERATION(cpu->reg_A);
} }
/** 6A : ROR A **/ /** 6A : ROR A **/
INSTRUCTION(RORiM) INSTRUCTION(RORnP)
{ {
TRACEi(("ROR A")); TRACEi(("ROR A"));
ROR_OPERATION(cpu->reg_A); ROR_OPERATION(cpu->reg_A);
} }
/** 0A : ASL A **/ /** 0A : ASL A **/
INSTRUCTION(ASLiM) INSTRUCTION(ASLnP)
{ {
TRACEi(("ASL A")); TRACEi(("ASL A"));
ASL_OPERATION(cpu->reg_A); ASL_OPERATION(cpu->reg_A);
} }
/** 4A : LSR A **/ /** 4A : LSR A **/
INSTRUCTION(LSRiM) INSTRUCTION(LSRnP)
{ {
TRACEi(("LSR A")); TRACEi(("LSR A"));
LSR_OPERATION(cpu->reg_A); LSR_OPERATION(cpu->reg_A);
@@ -1800,34 +1890,346 @@ INSTRUCTION(INCzX)
NZ_FLAG_UPDATE(val); NZ_FLAG_UPDATE(val);
} }
/* */ /* iM: Immediate
static InstructionFunction InstructionTable[256] = * iX: Indirect by X
* iY: Indirect by Y
* zP: Zero Page
* zX: Zero Page Indexec by X
* zY: Zero Page Indexec by Y
* iD: Indirect Double
* aB: Absolute
* aX: Absolute by X
* aY: Absolute by Y
*/
static InstructionFunction InstructionTable[256] =
{
/* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */
/* 00 */ I_BRKnP, I_ORAiX, I_ILLEG, I_ILLEG, I_ILLEG, I_ORAzP, I_ASLzP, I_ILLEG, I_PHPnP, I_ORAiM, I_ASLnP, I_ILLEG, I_ILLEG, I_ORAaB, I_ASLaB, I_ILLEG,
/* 10 */ I_BPLrE, I_ORAiY, I_ILLEG, I_ILLEG, I_ILLEG, I_ORAzX, I_ASLzX, I_ILLEG, I_CLCnP, I_ORAaY, I_ILLEG, I_ILLEG, I_ILLEG, I_ORAaX, I_ASLaX, I_ILLEG,
/* 20 */ I_JSRaB, I_ANDiX, I_ILLEG, I_ILLEG, I_BITzP, I_ANDzP, I_ROLzP, I_ILLEG, I_PLPnP, I_ANDiM, I_ROLnP, I_ILLEG, I_BITaB, I_ANDaB, I_ROLaB, I_ILLEG,
/* 30 */ I_BMIrE, I_ANDiY, I_ILLEG, I_ILLEG, I_ILLEG, I_ANDzX, I_ROLzX, I_ILLEG, I_SECnP, I_ANDaY, I_ILLEG, I_ILLEG, I_ILLEG, I_ANDaX, I_ROLaX, I_ILLEG,
/* 40 */ I_RTInP, I_EORiX, I_ILLEG, I_ILLEG, I_ILLEG, I_EORzP, I_LSRzP, I_ILLEG, I_PHAnP, I_EORiM, I_LSRnP, I_ILLEG, I_JMPaB, I_EORaB, I_LSRaB, I_ILLEG,
/* 50 */ I_BVCrE, I_EORiY, I_ILLEG, I_ILLEG, I_ILLEG, I_EORzX, I_LSRzX, I_ILLEG, I_CLInP, I_EORaY, I_ILLEG, I_ILLEG, I_ILLEG, I_EORaX, I_LSRaX, I_ILLEG,
/* 60 */ I_RTSnP, I_ADCiX, I_ILLEG, I_ILLEG, I_ILLEG, I_ADCzP, I_RORzP, I_ILLEG, I_PLAnP, I_ADCiM, I_RORnP, I_ILLEG, I_JMPiD, I_ADCaB, I_RORaB, I_ILLEG,
/* 70 */ I_BVSrE, I_ADCiY, I_ILLEG, I_ILLEG, I_ILLEG, I_ADCzX, I_RORzX, I_ILLEG, I_SEInP, I_ADCaY, I_ILLEG, I_ILLEG, I_ILLEG, I_ADCaX, I_RORaX, I_ILLEG,
/* 80 */ I_ILLEG, I_STAiX, I_ILLEG, I_ILLEG, I_STYzP, I_STAzP, I_STXzP, I_ILLEG, I_DEYnP, I_ILLEG, I_TXAnP, I_ILLEG, I_STYaB, I_STAaB, I_STXaB, I_ILLEG,
/* 90 */ I_BCCrE, I_STAiY, I_ILLEG, I_ILLEG, I_STYzX, I_STAzX, I_STXzY, I_ILLEG, I_TYAnP, I_STAaY, I_TXSnP, I_ILLEG, I_ILLEG, I_STAaX, I_ILLEG, I_ILLEG,
/* A0 */ I_LDYiM, I_LDAiX, I_LDXiM, I_ILLEG, I_LDYzP, I_LDAzP, I_LDXzP, I_ILLEG, I_TAYnP, I_LDAiM, I_TAXnP, I_ILLEG, I_LDYaB, I_LDAaB, I_LDXaB, I_ILLEG,
/* B0 */ I_BCSrE, I_LDAiY, I_ILLEG, I_ILLEG, I_LDYzX, I_LDAzX, I_LDXzY, I_ILLEG, I_CLVnP, I_LDAaY, I_TSXnP, I_ILLEG, I_LDYaX, I_LDAaX, I_LDXaY, I_ILLEG,
/* C0 */ I_CPYiM, I_CMPiX, I_ILLEG, I_ILLEG, I_CPYzP, I_CMPzP, I_DECzP, I_ILLEG, I_INYnP, I_CMPiM, I_DEXnP, I_ILLEG, I_CPYaB, I_CMPaB, I_DECaB, I_ILLEG,
/* D0 */ I_BNErE, I_CMPiY, I_ILLEG, I_ILLEG, I_ILLEG, I_CMPzX, I_DECzX, I_ILLEG, I_CLDnP, I_CMPaY, I_ILLEG, I_ILLEG, I_ILLEG, I_CMPaX, I_DECaX, I_ILLEG,
/* E0 */ I_CPXiM, I_SBCiX, I_ILLEG, I_ILLEG, I_CPXzP, I_SBCzP, I_INCzP, I_ILLEG, I_INXnP, I_SBCiM, I_NOPnP, I_ILLEG, I_CPXaB, I_SBCaB, I_INCaB, I_ILLEG,
/* F0 */ I_BEQrE, I_SBCiY, I_ILLEG, I_ILLEG, I_ILLEG, I_SBCzX, I_INCzX, I_ILLEG, I_SEDnP, I_SBCaY, I_ILLEG, I_ILLEG, I_ILLEG, I_SBCaX, I_INCaX, I_ILLEG
/* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */
};
#ifdef MINE
typedef enum InstructionType
{ {
/* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */ t_IMM = 0, t_IDX, t_IDY, t_ABS,
/* 00 */ I_BRKiM, I_ORAiX, I_ILLEG, I_ILLEG, I_ILLEG, I_ORAzP, I_ASLzP, I_ILLEG, I_PHPiM, I_ORAiM, I_ASLiM, I_ILLEG, I_ILLEG, I_ORAaB, I_ASLaB, I_ILLEG, t_REL, t_ZEP, t_ZPX, t_ZPY,
/* 10 */ I_BPLrE, I_ORAiY, I_ILLEG, I_ILLEG, I_ILLEG, I_ORAzX, I_ASLzX, I_ILLEG, I_CLCiM, I_ORAaY, I_ILLEG, I_ILLEG, I_ILLEG, I_ORAaX, I_ASLaX, I_ILLEG, t_ABX, t_ABY, t_IND, t_NOP,
/* 20 */ I_JSRaB, I_ANDiX, I_ILLEG, I_ILLEG, I_BITzP, I_ANDzP, I_ROLzP, I_ILLEG, I_PLPiM, I_ANDiM, I_ROLiM, I_ILLEG, I_BITaB, I_ANDaB, I_ROLaB, I_ILLEG, } InstructionType;
/* 30 */ I_BMIrE, I_ANDiY, I_ILLEG, I_ILLEG, I_ILLEG, I_ANDzX, I_ROLzX, I_ILLEG, I_SECiM, I_ANDaY, I_ILLEG, I_ILLEG, I_ILLEG, I_ANDaX, I_ROLaX, I_ILLEG,
/* 40 */ I_RTIiM, I_EORiX, I_ILLEG, I_ILLEG, I_ILLEG, I_EORzP, I_LSRzP, I_ILLEG, I_PHAiM, I_EORiM, I_LSRiM, I_ILLEG, I_JMPaB, I_EORaB, I_LSRaB, I_ILLEG, static InstructionType InstructionTypeTable[256] =
/* 50 */ I_BVCrE, I_EORiY, I_ILLEG, I_ILLEG, I_ILLEG, I_EORzX, I_LSRzX, I_ILLEG, I_CLIiM, I_EORaY, I_ILLEG, I_ILLEG, I_ILLEG, I_EORaX, I_LSRaX, I_ILLEG, {
/* 60 */ I_RTSiM, I_ADCiX, I_ILLEG, I_ILLEG, I_ILLEG, I_ADCzP, I_RORzP, I_ILLEG, I_PLAiM, I_ADCiM, I_RORiM, I_ILLEG, I_JMPiD, I_ADCaB, I_RORaB, I_ILLEG, /* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */
/* 70 */ I_BVSrE, I_ADCiY, I_ILLEG, I_ILLEG, I_ILLEG, I_ADCzX, I_RORzX, I_ILLEG, I_SEIiM, I_ADCaY, I_ILLEG, I_ILLEG, I_ILLEG, I_ADCaX, I_RORaX, I_ILLEG, /* 00 */ t_NOP, t_IDX, t_IMM, t_IMM, t_IMM, t_ZEP, t_ZEP, t_IMM, t_NOP, t_IMM, t_NOP, t_IMM, t_IMM, t_ABS, t_ABS, t_IMM,
/* 80 */ I_ILLEG, I_STAiX, I_ILLEG, I_ILLEG, I_STYzP, I_STAzP, I_STXzP, I_ILLEG, I_DEYiM, I_ILLEG, I_TXAiM, I_ILLEG, I_STYaB, I_STAaB, I_STXaB, I_ILLEG, /* 10 */ t_REL, t_IDY, t_IMM, t_IMM, t_IMM, t_ZPX, t_ZPX, t_IMM, t_NOP, t_ABY, t_IMM, t_IMM, t_IMM, t_ABX, t_ABX, t_IMM,
/* 90 */ I_BCCrE, I_STAiY, I_ILLEG, I_ILLEG, I_STYzX, I_STAzX, I_STXzY, I_ILLEG, I_TYAiM, I_STAaY, I_TXSiM, I_ILLEG, I_ILLEG, I_STAaX, I_ILLEG, I_ILLEG, /* 20 */ t_ABS, t_IDX, t_IMM, t_IMM, t_ZEP, t_ZEP, t_ZEP, t_IMM, t_NOP, t_IMM, t_NOP, t_IMM, t_ABS, t_ABS, t_ABS, t_IMM,
/* A0 */ I_LDYiM, I_LDAiX, I_LDXiM, I_ILLEG, I_LDYzP, I_LDAzP, I_LDXzP, I_ILLEG, I_TAYiM, I_LDAiM, I_TAXiM, I_ILLEG, I_LDYaB, I_LDAaB, I_LDXaB, I_ILLEG, /* 30 */ t_REL, t_IDY, t_IMM, t_IMM, t_IMM, t_ZPX, t_ZPX, t_IMM, t_NOP, t_ABY, t_IMM, t_IMM, t_IMM, t_ABX, t_ABX, t_IMM,
/* B0 */ I_BCSrE, I_LDAiY, I_ILLEG, I_ILLEG, I_LDYzX, I_LDAzX, I_LDXzY, I_ILLEG, I_CLViM, I_LDAaY, I_TSXiM, I_ILLEG, I_LDYaX, I_LDAaX, I_LDXaY, I_ILLEG, /* 40 */ t_NOP, t_IDX, t_IMM, t_IMM, t_IMM, t_ZEP, t_ZEP, t_IMM, t_NOP, t_IMM, t_NOP, t_IMM, t_ABS, t_ABS, t_ABS, t_IMM,
/* C0 */ I_CPYiM, I_CMPiX, I_ILLEG, I_ILLEG, I_CPYzP, I_CMPzP, I_DECzP, I_ILLEG, I_INYiM, I_CMPiM, I_DEXiM, I_ILLEG, I_CPYaB, I_CMPaB, I_DECaB, I_ILLEG, /* 50 */ t_REL, t_IDY, t_IMM, t_IMM, t_IMM, t_ZPX, t_ZPX, t_IMM, t_NOP, t_ABY, t_IMM, t_IMM, t_IMM, t_ABX, t_ABX, t_IMM,
/* D0 */ I_BNErE, I_CMPiY, I_ILLEG, I_ILLEG, I_ILLEG, I_CMPzX, I_DECzX, I_ILLEG, I_CLDiM, I_CMPaY, I_ILLEG, I_ILLEG, I_ILLEG, I_CMPaX, I_DECaX, I_ILLEG, /* 60 */ t_NOP, t_IDX, t_IMM, t_IMM, t_IMM, t_ZEP, t_ZEP, t_IMM, t_NOP, t_IMM, t_NOP, t_IMM, t_IND, t_ABS, t_ABS, t_IMM,
/* E0 */ I_CPXiM, I_SBCiX, I_ILLEG, I_ILLEG, I_CPXzP, I_SBCzP, I_INCzP, I_ILLEG, I_INXiM, I_SBCiM, I_NOPiM, I_ILLEG, I_CPXaB, I_SBCaB, I_INCaB, I_ILLEG, /* 70 */ t_REL, t_IDY, t_IMM, t_IMM, t_IMM, t_ZPX, t_ZPX, t_IMM, t_NOP, t_ABY, t_IMM, t_IMM, t_IMM, t_ABX, t_ABX, t_IMM,
/* F0 */ I_BEQrE, I_SBCiY, I_ILLEG, I_ILLEG, I_ILLEG, I_SBCzX, I_INCzX, I_ILLEG, I_SEDiM, I_SBCaY, I_ILLEG, I_ILLEG, I_ILLEG, I_SBCaX, I_INCaX, I_ILLEG /* 80 */ t_IMM, t_IDX, t_IMM, t_IMM, t_ZEP, t_ZEP, t_ZEP, t_IMM, t_NOP, t_IMM, t_NOP, t_IMM, t_ABS, t_ABS, t_ABS, t_IMM,
/* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */ /* 90 */ t_REL, t_IDY, t_IMM, t_IMM, t_ZPX, t_ZPX, t_ZPY, t_IMM, t_NOP, t_ABY, t_NOP, t_IMM, t_IMM, t_ABX, t_IMM, t_IMM,
/* A0 */ t_IMM, t_IDX, t_IMM, t_IMM, t_ZEP, t_ZEP, t_ZEP, t_IMM, t_NOP, t_IMM, t_NOP, t_IMM, t_ABS, t_ABS, t_ABS, t_IMM,
/* B0 */ t_REL, t_IDY, t_IMM, t_IMM, t_ZPX, t_ZPX, t_ZPY, t_IMM, t_NOP, t_ABY, t_NOP, t_IMM, t_ABX, t_ABX, t_ABY, t_IMM,
/* C0 */ t_IMM, t_IDX, t_IMM, t_IMM, t_ZEP, t_ZEP, t_ZEP, t_IMM, t_NOP, t_IMM, t_NOP, t_IMM, t_ABS, t_ABS, t_ABS, t_IMM,
/* D0 */ t_REL, t_IDY, t_IMM, t_IMM, t_IMM, t_ZPX, t_ZPX, t_IMM, t_NOP, t_ABY, t_IMM, t_IMM, t_IMM, t_ABX, t_ABX, t_IMM,
/* E0 */ t_IMM, t_IDX, t_IMM, t_IMM, t_ZEP, t_ZEP, t_ZEP, t_IMM, t_NOP, t_IMM, t_IMM, t_IMM, t_ABS, t_ABS, t_ABS, t_IMM,
/* F0 */ t_REL, t_IDY, t_IMM, t_IMM, t_IMM, t_ZPX, t_ZPX, t_IMM, t_NOP, t_ABY, t_IMM, t_IMM, t_IMM, t_ABX, t_ABX, t_IMM
/* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */
}; };
static InstructionNameTag InstructionNameTable[256] =
{
/* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */
/* 00 */ n_BRK, n_ORA, n_ILG, n_ILG, n_ILG, n_ORA, n_ASL, n_ILG, n_PHP, n_ORA, n_ASL, n_ILG, n_ILG, n_ORA, n_ASL, n_ILG,
/* 10 */ n_BPL, n_ORA, n_ILG, n_ILG, n_ILG, n_ORA, n_ASL, n_ILG, n_CLC, n_ORA, n_ILG, n_ILG, n_ILG, n_ORA, n_ASL, n_ILG,
/* 20 */ n_JSR, n_AND, n_ILG, n_ILG, n_BIT, n_AND, n_ROL, n_ILG, n_PLP, n_AND, n_ROL, n_ILG, n_BIT, n_AND, n_ROL, n_ILG,
/* 30 */ n_BMI, n_AND, n_ILG, n_ILG, n_ILG, n_AND, n_ROL, n_ILG, n_SEC, n_AND, n_ILG, n_ILG, n_ILG, n_AND, n_ROL, n_ILG,
/* 40 */ n_RTI, n_EOR, n_ILG, n_ILG, n_ILG, n_EOR, n_LSR, n_ILG, n_PHA, n_EOR, n_LSR, n_ILG, n_JMP, n_EOR, n_LSR, n_ILG,
/* 50 */ n_BVC, n_EOR, n_ILG, n_ILG, n_ILG, n_EOR, n_LSR, n_ILG, n_CLI, n_EOR, n_ILG, n_ILG, n_ILG, n_EOR, n_LSR, n_ILG,
/* 60 */ n_RTS, n_ADC, n_ILG, n_ILG, n_ILG, n_ADC, n_ROR, n_ILG, n_PLA, n_ADC, n_ROR, n_ILG, n_JMP, n_ADC, n_ROR, n_ILG,
/* 70 */ n_BVS, n_ADC, n_ILG, n_ILG, n_ILG, n_ADC, n_ROR, n_ILG, n_SEI, n_ADC, n_ILG, n_ILG, n_ILG, n_ADC, n_ROR, n_ILG,
/* 80 */ n_ILG, n_STA, n_ILG, n_ILG, n_STY, n_STA, n_STX, n_ILG, n_DEY, n_ILG, n_TXA, n_ILG, n_STY, n_STA, n_STX, n_ILG,
/* 90 */ n_BCC, n_STA, n_ILG, n_ILG, n_STY, n_STA, n_STX, n_ILG, n_TYA, n_STA, n_TXS, n_ILG, n_ILG, n_STA, n_ILG, n_ILG,
/* A0 */ n_LDY, n_LDA, n_LDX, n_ILG, n_LDY, n_LDA, n_LDX, n_ILG, n_TAY, n_LDA, n_TAX, n_ILG, n_LDY, n_LDA, n_LDX, n_ILG,
/* B0 */ n_BCS, n_LDA, n_ILG, n_ILG, n_LDY, n_LDA, n_LDX, n_ILG, n_CLV, n_LDA, n_TSX, n_ILG, n_LDY, n_LDA, n_LDX, n_ILG,
/* C0 */ n_CPY, n_CMP, n_ILG, n_ILG, n_CPY, n_CMP, n_DEC, n_ILG, n_INY, n_CMP, n_DEX, n_ILG, n_CPY, n_CMP, n_DEC, n_ILG,
/* D0 */ n_BNE, n_CMP, n_ILG, n_ILG, n_ILG, n_CMP, n_DEC, n_ILG, n_CLD, n_CMP, n_ILG, n_ILG, n_ILG, n_CMP, n_DEC, n_ILG,
/* E0 */ n_CPX, n_SBC, n_ILG, n_ILG, n_CPX, n_SBC, n_INC, n_ILG, n_INX, n_SBC, n_NOP, n_ILG, n_CPX, n_SBC, n_INC, n_ILG,
/* F0 */ n_BEQ, n_SBC, n_ILG, n_ILG, n_ILG, n_SBC, n_INC, n_ILG, n_SED, n_SBC, n_ILG, n_ILG, n_ILG, n_SBC, n_INC, n_ILG,
/* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */
};
/** Get current instruction name at specified address and put it into buffer */
int quick6502_getinstruction(quick6502_cpu *cpu, char interpret,
unsigned short addr, char *buffer, int *strlength)
{
int len = 0, curlen;
int readbyte = 1;
char *str = buffer;
uint8_t opcode = cpu->memory_opcode_read(addr);
uint8_t value_u8;
uint16_t value_u16;
curlen = sprintf(str, "%s", InstructionName[InstructionNameTable[opcode]]);
str += curlen; len += curlen;
switch(InstructionTypeTable[opcode])
{
default: /* Nothing to do */
case t_NOP:
break;
case t_IMM:
curlen = sprintf(str, " #$%02X", cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
/* Nothing to interpret.. Really */
readbyte += 2;
break;
case t_IDX:
curlen = sprintf(str, " ($%02X, X)", cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
if (interpret)
{
value_u8 = cpu->memory_opcode_read( addr + 1 );
value_u16 = value_u8 + cpu->reg_X;
curlen = sprintf(str, " ; ($%02X + $%02X) -> ($%02X) -> $%02X%02X",
value_u8, cpu->reg_X,
value_u16 & 0xFF,
cpu->memory_page0_read(value_u16),
cpu->memory_page0_read(value_u16 + 1));
str += curlen; len += curlen;
}
readbyte += 1;
break;
case t_IDY:
curlen = sprintf(str, " ($%02X), Y", cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
if (interpret)
{
value_u8 = cpu->memory_opcode_read( addr + 1 );
value_u16 = (cpu->memory_page0_read(value_u8 + 1) << 8) |
(cpu->memory_page0_read(value_u8) );
curlen = sprintf(str, " ; ($%02X) + $%02X -> $%04X + $%02X -> $%04X",
value_u8, cpu->reg_Y,
value_u16, cpu->reg_Y,
value_u16 + cpu->reg_Y
);
str += curlen; len += curlen;
}
readbyte += 1;
break;
case t_ABS:
curlen = sprintf(str, " $%02X%02X", cpu->memory_opcode_read(addr + 2),
cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
/* Nothing to interpret.. Really */
readbyte += 2;
break;
case t_REL:
value_u16 = 2 + addr + (signed char) cpu->memory_opcode_read(addr + 1);
curlen = sprintf(str, " $%04X", value_u16);
str += curlen; len += curlen;
/* Nothing to interpret.. Really */
readbyte += 1;
break;
case t_ZEP:
curlen = sprintf(str, " $%02X", cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
/* Nothing to interpret.. Really */
readbyte += 1;
break;
case t_ZPX:
curlen = sprintf(str, " $%02X, X", cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
if (interpret)
{
curlen = sprintf(str, " ; $%02X + $%02x -> $%02X",
cpu->memory_opcode_read(addr + 1), cpu->reg_X,
(cpu->memory_opcode_read(addr + 1) + cpu->reg_X) & 0xFF);
str += curlen; len += curlen;
}
readbyte += 1;
break;
case t_ZPY:
curlen = sprintf(str, " $%02X, Y", cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
if (interpret)
{
curlen = sprintf(str, " ; $%02X + $%02x -> $%02X",
cpu->memory_opcode_read(addr + 1), cpu->reg_Y,
(cpu->memory_opcode_read(addr + 1) + cpu->reg_Y) & 0xFF);
str += curlen; len += curlen;
}
readbyte += 1;
break;
case t_ABX:
curlen = sprintf(str, " $%02X%02X, X", cpu->memory_opcode_read(addr + 2),
cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
if (interpret)
{
value_u16 = (cpu->memory_opcode_read(addr + 2) << 8) |
cpu->memory_opcode_read(addr + 1);
curlen = sprintf(str, " ; $%04X + $%02X -> $%04X", value_u16,
cpu->reg_X, value_u16 + cpu->reg_X);
str += curlen; len += curlen;
}
readbyte += 2;
break;
case t_ABY:
curlen = sprintf(str, " $%02X%02X, Y", cpu->memory_opcode_read(addr + 2),
cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
if (interpret)
{
value_u16 = (cpu->memory_opcode_read(addr + 2) << 8) |
cpu->memory_opcode_read(addr + 1);
curlen = sprintf(str, " ; $%04X + $%02X -> $%04X", value_u16,
cpu->reg_Y, value_u16 + cpu->reg_Y);
str += curlen; len += curlen;
}
readbyte += 2;
break;
case t_IND:
curlen = sprintf(str, " ($%02X%02X)", cpu->memory_opcode_read(addr + 2),
cpu->memory_opcode_read(addr + 1));
str += curlen; len += curlen;
if (interpret)
{
value_u16 = (cpu->memory_opcode_read(addr + 2) << 8) |
cpu->memory_opcode_read(addr + 1);
value_u16 = cpu->memory_read(value_u16) |
(cpu->memory_read( ( value_u16 & 0xFF00 ) |
( ( value_u16 + 1 ) & 0x00FF ) ) << 8 );
curlen = sprintf(str, " ; ($%02X%02X) -> $%04X",
cpu->memory_opcode_read(addr + 2),
cpu->memory_opcode_read(addr + 1),
cpu->memory_opcode_read(addr));
str += curlen; len += curlen;
}
readbyte += 2;
break;
}
if (strlength != NULL)
*strlength = len;
return readbyte;
}
#else
static char InstructionParameters[256][10] =
{
/* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */
/* 00 */ IP_iM "BRK", IP_iX "ORA", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_zP "ORA", IP_zP "ASL", IP_iM "ILG", IP_iM "PHP", IP_iM "ORA", IP_iM "ASL", IP_iM "ILG", IP_iM "ILG", IP_aB "ORA", IP_aB "ASL", IP_iM "ILG",
/* 10 */ IP_rE "BPL", IP_iY "ORA", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_zX "ORA", IP_zX "ASL", IP_iM "ILG", IP_iM "CLC", IP_aY "ORA", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_aX "ORA", IP_aX "ASL", IP_iM "ILG",
/* 20 */ IP_aB "JSR", IP_iX "AND", IP_iM "ILG", IP_iM "ILG", IP_zP "BIT", IP_zP "AND", IP_zP "ROL", IP_iM "ILG", IP_iM "PLP", IP_iM "AND", IP_iM "ROL", IP_iM "ILG", IP_aB "BIT", IP_aB "AND", IP_aB "ROL", IP_iM "ILG",
/* 30 */ IP_rE "BMI", IP_iY "AND", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_zX "AND", IP_zX "ROL", IP_iM "ILG", IP_iM "SEC", IP_aY "AND", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_aX "AND", IP_aX "ROL", IP_iM "ILG",
/* 40 */ IP_iM "RTI", IP_iX "EOR", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_zP "EOR", IP_zP "LSR", IP_iM "ILG", IP_iM "PHA", IP_iM "EOR", IP_iM "LSR", IP_iM "ILG", IP_aB "JMP", IP_aB "EOR", IP_aB "LSR", IP_iM "ILG",
/* 50 */ IP_rE "BVC", IP_iY "EOR", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_zX "EOR", IP_zX "LSR", IP_iM "ILG", IP_iM "CLI", IP_aY "EOR", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_aX "EOR", IP_aX "LSR", IP_iM "ILG",
/* 60 */ IP_iM "RTS", IP_iX "ADC", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_zP "ADC", IP_zP "ROR", IP_iM "ILG", IP_iM "PLA", IP_iM "ADC", IP_iM "ROR", IP_iM "ILG", IP_iD "JMP", IP_aB "ADC", IP_aB "ROR", IP_iM "ILG",
/* 70 */ IP_rE "BVS", IP_iY "ADC", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_zX "ADC", IP_zX "ROR", IP_iM "ILG", IP_iM "SEI", IP_aY "ADC", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_aX "ADC", IP_aX "ROR", IP_iM "ILG",
/* 80 */ IP_iM "ILG", IP_iX "STA", IP_iM "ILG", IP_iM "ILG", IP_zP "STY", IP_zP "STA", IP_zP "STX", IP_iM "ILG", IP_iM "DEY", IP_iM "ILG", IP_iM "TXA", IP_iM "ILG", IP_aB "STY", IP_aB "STA", IP_aB "STX", IP_iM "ILG",
/* 90 */ IP_rE "BCC", IP_iY "STA", IP_iM "ILG", IP_iM "ILG", IP_zX "STY", IP_zX "STA", IP_zY "STX", IP_iM "ILG", IP_iM "TYA", IP_aY "STA", IP_iM "TXS", IP_iM "ILG", IP_iM "ILG", IP_aX "STA", IP_iM "ILG", IP_iM "ILG",
/* A0 */ IP_iM "LDY", IP_iX "LDA", IP_iM "LDX", IP_iM "ILG", IP_zP "LDY", IP_zP "LDA", IP_zP "LDX", IP_iM "ILG", IP_iM "TAY", IP_iM "LDA", IP_iM "TAX", IP_iM "ILG", IP_aB "LDY", IP_aB "LDA", IP_aB "LDX", IP_iM "ILG",
/* B0 */ IP_rE "BCS", IP_iY "LDA", IP_iM "ILG", IP_iM "ILG", IP_zX "LDY", IP_zX "LDA", IP_zY "LDX", IP_iM "ILG", IP_iM "CLV", IP_aY "LDA", IP_iM "TSX", IP_iM "ILG", IP_aX "LDY", IP_aX "LDA", IP_aY "LDX", IP_iM "ILG",
/* C0 */ IP_iM "CPY", IP_iX "CMP", IP_iM "ILG", IP_iM "ILG", IP_zP "CPY", IP_zP "CMP", IP_zP "DEC", IP_iM "ILG", IP_iM "INY", IP_iM "CMP", IP_iM "DEX", IP_iM "ILG", IP_aB "CPY", IP_aB "CMP", IP_aB "DEC", IP_iM "ILG",
/* D0 */ IP_rE "BNE", IP_iY "CMP", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_zX "CMP", IP_zX "DEC", IP_iM "ILG", IP_iM "CLD", IP_aY "CMP", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_aX "CMP", IP_aX "DEC", IP_iM "ILG",
/* E0 */ IP_iM "CPX", IP_iX "SBC", IP_iM "ILG", IP_iM "ILG", IP_zP "CPX", IP_zP "SBC", IP_zP "INC", IP_iM "ILG", IP_iM "INX", IP_iM "SBC", IP_iM "NOP", IP_iM "ILG", IP_aB "CPX", IP_aB "SBC", IP_aB "INC", IP_iM "ILG",
/* F0 */ IP_rE "BEQ", IP_iY "SBC", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_zX "SBC", IP_zX "INC", IP_iM "ILG", IP_iM "SED", IP_aY "SBC", IP_iM "ILG", IP_iM "ILG", IP_iM "ILG", IP_aX "SBC", IP_aX "INC", IP_iM "ILG"
/* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */
};
/** Get current instruction name at specified address and put it into buffer */
int quick6502_getinstruction(quick6502_cpu *cpu, char interpret,
unsigned short addr, char *buffer, int *strlength)
{
unsigned char instr = cpu->memory_opcode_read(cpu->reg_PC);
unsigned char *instrText = InstructionParameters[instr];
buffer += strlen(strcpy(buffer, instrText[1]));
switch(instrText[0])
{
case IP_nPc: default: break;
case IP_iMc: buffer += strlen(sprintf(buffer, IPf_iM, cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_iXc: buffer += strlen(sprintf(buffer, IPf_iX, cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_iYc: buffer += strlen(sprintf(buffer, IPf_iY, cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_zPc: buffer += strlen(sprintf(buffer, IPf_zP, cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_zXc: buffer += strlen(sprintf(buffer, IPf_zX, cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_zYc: buffer += strlen(sprintf(buffer, IPf_zY, cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_iDc: buffer += strlen(sprintf(buffer, IPf_iD, cpu->memory_opcode_read(cpu->reg_PC + 2), cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_aBc: buffer += strlen(sprintf(buffer, IPf_aB, cpu->memory_opcode_read(cpu->reg_PC + 2), cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_aXc: buffer += strlen(sprintf(buffer, IPf_aX, cpu->memory_opcode_read(cpu->reg_PC + 2), cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_aYc: buffer += strlen(sprintf(buffer, IPf_aY, cpu->memory_opcode_read(cpu->reg_PC + 2), cpu->memory_opcode_read(cpu->reg_PC + 1))); break;
case IP_rEc: buffer += strlen(sprintf(buffer, IPf_rE, cpu->reg_PC + (signed char) cpu->memory_opcode_read(cpu->reg_PC) + 1)); break;
}
*buffer = 0;
}
#endif
static inline int quick6502_exec_one(quick6502_cpu *cpu) static inline int quick6502_exec_one(quick6502_cpu *cpu)
{ {
register byte opcode = cpu->memory_opcode_read(cpu->reg_PC++); register byte opcode = cpu->memory_opcode_read(cpu->reg_PC);
//char instr[100];
//quick6502_dump(cpu, stdout);
cpu->reg_PC++;
TRACEi(("Quick6502: PC:$%04X A:$%02X X:$%02X Y:$%02X S:$%02X P:$%02X P:[%c%c%c%c%c%c%c%c]", TRACEi(("Quick6502: PC:$%04X A:$%02X X:$%02X Y:$%02X S:$%02X P:$%02X P:[%c%c%c%c%c%c%c%c]",
cpu->reg_PC, cpu->reg_A, cpu->reg_X, cpu->reg_Y, cpu->reg_S, cpu->reg_P, cpu->reg_PC, cpu->reg_A, cpu->reg_X, cpu->reg_Y, cpu->reg_S, cpu->reg_P,
cpu->reg_P&Q6502_N_FLAG ? 'N':'.', cpu->reg_P&Q6502_N_FLAG ? 'N':'.',
@@ -1838,8 +2240,11 @@ static inline int quick6502_exec_one(quick6502_cpu *cpu)
cpu->reg_P&Q6502_I_FLAG ? 'I':'.', cpu->reg_P&Q6502_I_FLAG ? 'I':'.',
cpu->reg_P&Q6502_Z_FLAG ? 'Z':'.', cpu->reg_P&Q6502_Z_FLAG ? 'Z':'.',
cpu->reg_P&Q6502_C_FLAG ? 'C':'.')); cpu->reg_P&Q6502_C_FLAG ? 'C':'.'));
InstructionTable[opcode](cpu); InstructionTable[opcode](cpu);
//printf("--------------------------------------------------------------\n");
/*quick6502_getinstruction(cpu, (1==1), cpu->reg_PC, instr, NULL);
printf("%04X: %s\n", cpu->reg_PC, instr);*/
cpu->cycle_done += CycleTable[opcode]; cpu->cycle_done += CycleTable[opcode];
if (cpu->page_crossed) { cpu->cycle_done++; cpu->page_crossed = 0; } if (cpu->page_crossed) { cpu->cycle_done++; cpu->page_crossed = 0; }
if (cpu->int_pending != 0) if (cpu->int_pending != 0)

View File

@@ -3,7 +3,7 @@
* NESCart.h * NESCart.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -14,6 +14,7 @@
#ifndef NESCARTS_H #ifndef NESCARTS_H
#define NESCARTS_H #define NESCARTS_H
#include <stdint.h>
#include <types.h> #include <types.h>
#define iNES_MIRROR 0x01 #define iNES_MIRROR 0x01
@@ -23,14 +24,14 @@
typedef struct NesCart_ typedef struct NesCart_
{ {
unsigned long PROMSize, /* Size of PROM */ uint32_t PROMSize, /* Size of PROM */
VROMSize; /* Size of VROM */ VROMSize; /* Size of VROM */
char MapperID; /* Mapper Type */ char MapperID; /* Mapper Type */
byte Flags; uint8_t Flags;
char *FileName; char *FileName;
byte *File; /* Pointer on the file in memory */ uint8_t *File; /* Pointer on the file in memory */
byte *PROMBanks; /* Pointer on the first PROM */ uint8_t *PROMBanks; /* Pointer on the first PROM */
byte *VROMBanks; /* Pointer on the first VROM */ uint8_t *VROMBanks; /* Pointer on the first VROM */
} NesCart; } NesCart;
void DumpCartProperties(); void DumpCartProperties();

View File

@@ -93,7 +93,7 @@ void SetChannels(int Volume,int Switch);
/** waveform to be an instrument or set it to the waveform **/ /** waveform to be an instrument or set it to the waveform **/
/** own playback rate. **/ /** own playback rate. **/
/*************************************************************/ /*************************************************************/
void SetWave(int Channel,const signed char *Data,int Length,int Rate); void SetWave(int Channel,signed char *Data,int Length,int Rate);
/** GetWave() ************************************************/ /** GetWave() ************************************************/
/** Get current read position for the buffer set with the **/ /** Get current read position for the buffer set with the **/
@@ -225,7 +225,7 @@ struct SndDriverStruct
void (*Drum)(int Type,int Force); void (*Drum)(int Type,int Force);
void (*SetChannels)(int Volume,int Switch); void (*SetChannels)(int Volume,int Switch);
void (*Sound)(int Channel,int NewFreq,int NewVolume); void (*Sound)(int Channel,int NewFreq,int NewVolume);
void (*SetWave)(int Channel,const signed char *Data,int Length,int Freq); void (*SetWave)(int Channel,signed char *Data,int Length,int Freq);
const signed char *(*GetWave)(int Channel); const signed char *(*GetWave)(int Channel);
}; };
extern struct SndDriverStruct SndDriver; extern struct SndDriverStruct SndDriver;

48
src/include/color.h Normal file
View File

@@ -0,0 +1,48 @@
/**
* ANSI Color definition - The Quick6502 Project
* include/color.h
*
* Created by Manoel Trapier on 25/06/10
* Copyright (c) 2003-2016 986-Studio. All rights reserved.
*
* $LastChangedDate:$
* $Author:$
* $HeadURL:$
* $Revision:$
*
*/
#ifndef COLOR_H
#define COLOR_H
#define ALLOW_COLORS
#ifdef ALLOW_COLORS
#define __C(c) "\x1B[" c "m"
#else
#define __C(c) ""
#endif
#define ANSI_COLOR __C
#define FBLACK ANSI_COLOR("30")
#define FRED ANSI_COLOR("31")
#define FGREEN ANSI_COLOR("32")
#define FYELLOW ANSI_COLOR("33")
#define FBLUE ANSI_COLOR("34")
#define FMAGENTA ANSI_COLOR("35")
#define FCYAN ANSI_COLOR("36")
#define FWHITE ANSI_COLOR("37")
#define BBLACK ANSI_COLOR("40")
#define BRED ANSI_COLOR("41")
#define BGREEN ANSI_COLOR("42")
#define BYELLOW ANSI_COLOR("43")
#define BBLUE ANSI_COLOR("44")
#define BMAGENTA ANSI_COLOR("45")
#define BCYAN ANSI_COLOR("46")
#define BWHITE ANSI_COLOR("47")
#define CNORMAL ANSI_COLOR("0")
#endif /* COLOR_H */

View File

@@ -3,7 +3,7 @@
* corecpu.h * corecpu.h
* *
* Created by Manoel Trapier on 24/02/08 * Created by Manoel Trapier on 24/02/08
* Copyright 2008 986 Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -18,22 +18,23 @@
/* M6502 configuration /* M6502 configuration
* *
* Supported DEFINEs : * Supported DEFINEs :
* NO_DECIMAL Quick6502 will not support BDC arithemtic (used for NES) * Q6502_NO_DECIMAL Quick6502 will not support BDC arithemtic (used for NES)
* CMOS_6502 Quick6502 will act as a CMOS 6502 (Not actually used) * Q6502_CMOS Quick6502 will act as a CMOS 6502 (Not actually used)
* Q6502_DEBUGGER Quick6502 will be build with debugguer support. Add some KB to the binary
* and may slowdown a bit the emulation.
* *
*/ */
#ifdef CMOS_6502 #ifdef Q6502_CMOS
//#warning Quick6502 CMOS support is actually desactivated, desactivate it //#warning Quick6502 CMOS support is actually desactivated, desactivate it
#undef CMOS_6502 #undef Q6502_CMOS
#endif #endif
#ifndef NO_DECIMAL #ifndef Q6502_NO_DECIMAL
//#warning Quick6502 have actually no BCD support, fallback to no NO_DECIMAL //#warning Quick6502 have actually no BCD support, fallback to no NO_DECIMAL
#define NO_DECIMAL #define Q6502_NO_DECIMAL
#endif #endif
#include "types.h" #include "types.h"
typedef byte (*quick6502_MemoryReadFunction)(unsigned short addr); typedef byte (*quick6502_MemoryReadFunction)(unsigned short addr);
@@ -63,6 +64,9 @@ typedef struct quick6502_cpu_
/* Other config options */ /* Other config options */
byte running; /* This field is used to prevent cpu free if this cpu is running */ byte running; /* This field is used to prevent cpu free if this cpu is running */
byte page_crossed; byte page_crossed;
/* TODO add support for Inst/MemAccess breakpoints */
} quick6502_cpu; } quick6502_cpu;
typedef struct quick6502_cpuconfig_ typedef struct quick6502_cpuconfig_
@@ -150,8 +154,10 @@ void quick6502_int(quick6502_cpu *cpu, quick6502_signal signal);
void quick6502_dump(quick6502_cpu *cpu, FILE * fp); void quick6502_dump(quick6502_cpu *cpu, FILE * fp);
/** Get current instruction name at specified address and put it into buffer */ /** Get current instruction name at specified address and put it into buffer */
void quick6502_getinstruction(quick6502_cpu *cpu, unsigned short addr, char *buffer); #define MINE
int quick6502_getinstruction(quick6502_cpu *cpu, char interpret,
unsigned short addr, char *buffer, int *strlength);
/** /**
* Free the CPU * Free the CPU
* *

42
src/include/log.h Normal file
View File

@@ -0,0 +1,42 @@
/**
* Log Facility - The Quick6502 Project
* include/log.h
*
* Created by Manoel Trapier on 19/05/10
* Copyright (c) 2003-2016 986-Studio. All rights reserved.
*
* $LastChangedDate:$
* $Author:$
* $HeadURL:$
* $Revision:$
*
*/
#ifndef _LOG_H
#define _LOG_H
enum
{
LOG_ALWAYS = -1,
LOG_PANIC = 0,
LOG_ERROR,
LOG_WARNING,
LOG_NORMAL,
LOG_VERBOSE,
LOG_DEBUG,
};
#define TIME_STAMP_LOG
#define MAX_DEBUG_LEVEL LOG_PANIC
#define log(_level, _user, _fmt, ...) if ((_level <= MAX_DEBUG_LEVEL) || (_level <= LOG_PANIC)) do { log_real(_level, _user, _fmt, ##__VA_ARGS__); } while(0)
void log_real(int level, char *user, char *fmt, ...);
#define LOG(_level, _str, ...) if ((_level <= MAX_DEBUG_LEVEL) || (_level <= LOG_PANIC)) do { puts(_str); } while(0)
#define LOGCODE(_level, _user, _code) log(_level, _user, ""); \
if ((_level <= MAX_DEBUG_LEVEL) || (_level <= LOG_PANIC)) \
do { _code; printf("\n"); } while(0)
#endif /* _LOG_H */

View File

@@ -63,6 +63,6 @@ void InitMemory();
byte ReadMemory(byte page, byte addr); byte ReadMemory(byte page, byte addr);
void WriteMemory(byte page, byte addr, byte value); void WriteMemory(byte page, byte addr, byte value);
void DumpMemoryState(); void DumpMemoryState(FILE *fp);
#endif #endif

View File

@@ -3,7 +3,7 @@
* os_dependent.h * os_dependent.h
* *
* Created by Manoel TRAPIER on 08/05/08. * Created by Manoel TRAPIER on 08/05/08.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -15,11 +15,21 @@
#ifndef OS_DEPENDENT_H #ifndef OS_DEPENDENT_H
#define OS_DEPENDENT_H #define OS_DEPENDENT_H
#include <stdint.h>
/* File related functions */ /* File related functions */
/* Graphics related functions */ /* Graphics related functions */
int graphics_init(); int graphics_init();
int graphics_drawpixel(long x, long y, long color); int graphics_drawpixel(long x, long y, long color);
int graphics_blit(long x, long y, long w, long h); int graphics_blit(long x, long y, long w, long h);
int graphics_drawline(long x, long y, long x1, long y1, long color);
typedef struct Palette_t
{
uint8_t r,g,b,a;
} Palette;
int getKeyStatus(int key);
/* Sound related functions */ /* Sound related functions */
@@ -37,7 +47,6 @@ typedef enum ConsoleLevel_t
Console_Debug, Console_Debug,
} ConsoleLevel; } ConsoleLevel;
int console_init(ConsoleLevel DefaultLevel); int console_init(ConsoleLevel DefaultLevel);
int console_printf(const ConsoleLevel level, const char *format, ...); int console_printf(const ConsoleLevel level, const char *format, ...);
int console_printf_d(const char *format, ...); int console_printf_d(const char *format, ...);

View File

@@ -3,7 +3,7 @@
* paddle.h * paddle.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -6,7 +6,7 @@
* $Revision$ * $Revision$
*/ */
PALETTE basicPalette = { Palette basicPalette[] = {
{ 0x1E, 0x1E, 0x1E, 0x07 }, { 0x1E, 0x1E, 0x1E, 0x07 },
{ 0x03, 0x09, 0x28, 0xB7 }, { 0x03, 0x09, 0x28, 0xB7 },
{ 0x0A, 0x04, 0x2B, 0x0D }, { 0x0A, 0x04, 0x2B, 0x0D },

View File

@@ -5,7 +5,7 @@
* Define and emulate the PPU (Picture Processing Unit) of the real NES * Define and emulate the PPU (Picture Processing Unit) of the real NES
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -21,10 +21,10 @@
typedef struct PPU_Sprite_ typedef struct PPU_Sprite_
{ {
byte y; uint8_t y;
byte tileid; uint8_t tileid;
byte flags; uint8_t flags;
byte x; uint8_t x;
} PPU_Sprite; } PPU_Sprite;
/* /*
@@ -32,13 +32,13 @@ PPU must be initialized after memory initialisation..
*/ */
int ppu_init(); int ppu_init();
int ppu_hblank(int scanline); int ppu_hblank(uint16_t scanline);
byte ppu_readReg(byte id); uint8_t ppu_readReg(uint8_t id);
void ppu_writeReg(byte id, byte val); void ppu_writeReg(uint8_t id, uint8_t val);
void ppu_fillSprRamDMA(byte value); void ppu_fillSprRamDMA(uint8_t value);
#define PPU_MIRROR_HORIZTAL 0 #define PPU_MIRROR_HORIZTAL 0
#define PPU_MIRROR_VERTICAL 1 #define PPU_MIRROR_VERTICAL 1
@@ -52,15 +52,15 @@ void ppu_fillSprRamDMA(byte value);
#define PPU_SCMODE_NORMAL 1 #define PPU_SCMODE_NORMAL 1
#define PPU_SCMODE_FOURSC 2 #define PPU_SCMODE_FOURSC 2
void ppu_setMirroring(byte direction); void ppu_setMirroring(uint8_t direction);
void ppu_setSingleScreen(byte screen); void ppu_setSingleScreen(uint8_t screen);
void ppu_setScreenMode(byte mode); void ppu_setScreenMode(uint8_t mode);
PPU_Sprite ppu_getSprite(unsigned short i); PPU_Sprite ppu_getSprite(uint16_t i);
unsigned char ppu_memoryRead(byte page, byte addr); unsigned char ppu_memoryRead(uint8_t page, uint8_t addr);
void ppu_memoryWrite(byte page, byte addr, byte value); void ppu_memoryWrite(uint8_t page, uint8_t addr, uint8_t value);
void ppu_debugSprites(); void ppu_debugSprites();
void ppu_debugColor(); void ppu_debugColor();

View File

@@ -3,7 +3,7 @@
* types.h - Taken from the Quick6502 project * types.h - Taken from the Quick6502 project
* *
* Created by Manoel Trapier on 18/09/06. * Created by Manoel Trapier on 18/09/06.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -15,12 +15,14 @@
#ifndef TYPES_H #ifndef TYPES_H
#define TYPES_H #define TYPES_H
#include <stdint.h>
#ifndef BYTE_TYPE_DEFINED #ifndef BYTE_TYPE_DEFINED
#define BYTE_TYPE_DEFINED #define BYTE_TYPE_DEFINED
typedef unsigned char byte; typedef uint8_t byte;
#endif #endif
typedef unsigned char bool; typedef uint8_t bool;
#define true (0) #define true (0)
#define false (!true) #define false (!true)

125
src/log.c Normal file
View File

@@ -0,0 +1,125 @@
/**
* Log Facility - The Quick6502 Project
* log.c
*
* Created by Manoel Trapier on 19/05/10
* Copyright 2010 986 Corp. All rights reserved.
*
* $LastChangedDate:$
* $Author:$
* $HeadURL:$
* $Revision:$
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <color.h>
#include <string.h>
#include <stdarg.h>
#include <log.h>
#include <sys/time.h>
#include <time.h>
#ifdef TIME_STAMP_LOG
void time_stamp_line(void)
{
/* Time "0" will be thefirst log line */
static char firstRun = 1;
static struct timeval firstTime;
struct timeval curTime;
int cMin, cSec;
long long cMSec;
/* Get datetime */
gettimeofday(&curTime, NULL);
if (firstRun == 1)
{
firstRun = 0;
firstTime.tv_sec = curTime.tv_sec;
firstTime.tv_usec = curTime.tv_usec;
}
cMSec = ((curTime.tv_sec - firstTime.tv_sec)* 1000) + (curTime.tv_usec - firstTime.tv_usec)/1000;
cSec = (cMSec/1000);
cMSec %= 1000;
cMin = cSec / 60;
cSec %= 60;
/* Put cursor at start of line */
printf("%c[s", 0x1B);
printf("%c[7000D", 0x1B);
printf("%c[1C", 0x1B);
printf(FWHITE"[" FYELLOW "%03d" FRED "." FBLUE "%02d" FRED "." FGREEN "%03lld" FWHITE "]" CNORMAL, cMin, cSec, cMSec);
printf("%c[u", 0x1B);
}
#endif /* TIME_STAMP_LOG */
void log_real(int level, char *user, char *fmt, ...)
{
int i;
va_list va;
/* The LOG_PANIC must always be displayed */
if ((level <= MAX_DEBUG_LEVEL) || (level <= LOG_PANIC))
{
switch(level)
{
case LOG_PANIC: printf(BRED FWHITE); break;
case LOG_ERROR: printf(FRED); break;
case LOG_WARNING: printf(FYELLOW); break;
default:
case LOG_NORMAL: printf(FGREEN); break;
case LOG_VERBOSE: printf(FCYAN); break;
case LOG_DEBUG: printf(BBLUE FWHITE); break;
}
#ifdef TIME_STAMP_LOG
printf(" ");
#endif
if (user != NULL)
{
i = strlen(user);
if (i < 12)
{
i = 12 - i;
for (; i >= 0; i--)
putchar(' ');
}
printf("%s", user);
}
else
{
switch(level)
{
case LOG_PANIC: printf(" PANIC"); break;
case LOG_ERROR: printf(" Error"); break;
case LOG_WARNING: printf(" Warning"); break;
default:
case LOG_NORMAL: printf(" Info"); break;
case LOG_VERBOSE: printf(" Verbose"); break;
case LOG_DEBUG: printf(" Debug"); break;
}
}
printf(CNORMAL ": ");
#ifdef TIME_STAMP_LOG
time_stamp_line();
#endif /* TIME_STAMP_LOG */
va_start(va, fmt);
vprintf(fmt, va);
va_end(va);
if (fmt[0] != 0)
{
printf("\n");
}
}
}

View File

@@ -3,7 +3,7 @@
* main.c * main.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -20,21 +20,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>
/* Allegro includes */ #include <GLFW/glfw3.h>
#ifdef __APPLE__
#define USE_CONSOLE
#include <Allegro/allegro.h>
#else
#define USE_CONSOLE
#include <allegro.h>
#endif
#else #else
@@ -61,23 +55,11 @@
#include <Sound.h> #include <Sound.h>
#endif #endif
#include <palette.h>
/* PAL support is broken, so force NTSC mode */
#if ISPAL || ISNTSC
#undef ISPAL
#undef ISNTSC
#endif
#define ISNTSC 1
#if ISPAL && !ISNTSC #if ISPAL && !ISNTSC
int VBLANK_TIME = 70; int VBLANK_TIME = 70;
int HBLANK_TIME = 140; int HBLANK_TIME = 103;
double APU_BASEFREQ = 1.7734474; double APU_BASEFREQ = 1.7734474;
#elif !ISPAL && ISNTSC #elif !ISPAL && ISNTSC
int VBLANK_TIME = 20; int VBLANK_TIME = 20;
int HBLANK_TIME = 113; int HBLANK_TIME = 113;
double APU_BASEFREQ = 1.7897725; double APU_BASEFREQ = 1.7897725;
@@ -87,15 +69,20 @@ double APU_BASEFREQ = 1.7897725;
# error Cannot use ISPAL with ISNTSC together ! # error Cannot use ISPAL with ISNTSC together !
#endif #endif
//#define MEMORY_TEST
/* TI-NESulator Version */ /* TI-NESulator Version */
#define V_MAJOR 0 #define V_MAJOR 0
#define V_MINOR 40 #define V_MINOR 71
#ifdef USE_SOUND
#undef USE_SOUND
#endif
/* SVN specific values */ /* SVN specific values */
#define VS_ID "$Id$"
#define VS_REVISION "$Revision$" #define VS_REVISION "$Revision$"
#define VS_LASTCHANGEDDATE "$LastChangedDate$" #define VS_LASTCHANGEDDATE "$LastChangedDate$"
#define VS_HEADURL "$HeadURL$"
#define VS_AUTHOR "$Author$" #define VS_AUTHOR "$Author$"
/* /*
@@ -111,10 +98,6 @@ NesCart *Cart;
byte *FDSRom; byte *FDSRom;
byte *FDSRam; byte *FDSRam;
/* Allegro main screen */
BITMAP *Buffer;
/* Command line options */ /* Command line options */
byte START_DEBUG = 0; byte START_DEBUG = 0;
byte START_WITH_FDS = 0; byte START_WITH_FDS = 0;
@@ -137,9 +120,8 @@ struct timeval timeEnd;
volatile unsigned long FPS, IPS; volatile unsigned long FPS, IPS;
PALETTE pal;
short IRQScanHit = -1; short IRQScanHit = -1;
short SZHit = -1;
/* palette */ /* palette */
unsigned long ColorPalette[ 8 * 63 ]; unsigned long ColorPalette[ 8 * 63 ];
@@ -163,20 +145,12 @@ void CloseHook(void)
WantClosing = 1; WantClosing = 1;
} }
void ips_fps_counter(void)
{
FPS = frame;
IPS = ccount;
frame = 0;
ccount = 0;
}
END_OF_FUNCTION(ips_fps_counter);
void SaveSaveRam(char *name) void SaveSaveRam(char *name)
{ {
FILE *fp; FILE *fp;
int i; int i;
char fname[512]; char fname[512];
strcpy(fname, name); strcpy(fname, name);
strcat(fname, ".svt"); strcat(fname, ".svt");
if ((fp = fopen(fname, "wb"))) if ((fp = fopen(fname, "wb")))
@@ -212,10 +186,9 @@ void LoadSaveRam(char *name)
} }
void LoadPalette(char *filename, PALETTE pal) void LoadPalette(char *filename, Palette *pal)
{ {
FILE *fp; FILE *fp;
unsigned char r, v, b, i; unsigned char r, v, b, i;
console_printf(Console_Default, "%s: try to load pallette file '%s'", __func__, filename); console_printf(Console_Default, "%s: try to load pallette file '%s'", __func__, filename);
if ((fp = fopen(filename, "rb")) != NULL) if ((fp = fopen(filename, "rb")) != NULL)
@@ -255,7 +228,7 @@ void LoadPalette(char *filename, PALETTE pal)
ColorPalette[i + (6 * 63)] = SET_RGB(r - 10, v + 05, b + 05); ColorPalette[i + (6 * 63)] = SET_RGB(r - 10, v + 05, b + 05);
/* Red + Green + Blue emphase */ /* Red + Green + Blue emphase */
ColorPalette[i + (7 * 63)] = SET_RGB(r + 00, v + 00, b + 00);*/ ColorPalette[i + (7 * 63)] = SET_RGB(r + 00, v + 00, b + 00);
#else /* Else Use 8Bits */ #else /* Else Use 8Bits */
pal[i].r = r; pal[i].r = r;
pal[i].g = v; pal[i].g = v;
@@ -284,16 +257,20 @@ void LoadPalette(char *filename, PALETTE pal)
} }
} }
void *signalhandler(int sig) #ifdef RUN_COVERAGE
void alarmHandler(int sig)
{
signal(SIGALRM, SIG_IGN);
WantClosing = 1;
}
#endif
void signalhandler(int sig)
{ {
#if 0
static int state=0; static int state=0;
byte F;
int J, I;
static char FA[8] = "NVRBDIZC";
char S[128];
char name[512]; char name[512];
static FILE *fp = NULL; static FILE *fp = NULL;
sprintf(name, "crashdump-%d.txt", (int)time(NULL)); sprintf(name, "crashdump-%d.txt", (int)time(NULL));
if (state != 0) if (state != 0)
@@ -332,27 +309,17 @@ void *signalhandler(int sig)
case SIGTERM: fprintf(fp,"Termination request"); break; case SIGTERM: fprintf(fp,"Termination request"); break;
} }
fprintf(fp,"\nAn error occured during the excution.\n Crash report information :\n"); fprintf(fp,"\nAn error occured during the excution.\n Crash report information :\n");
#ifdef DEBUG
DAsm(S, R->PC.W); //quick6502_dump(cpu, fp);
#endif
fprintf(fp, "CPU: A:%02X P:%02X X:%02X Y:%02X S:%04X PC:%04X Flags:[", //showlastop(fp);
R->A, R->P, R->X, R->Y, R->S + 0x0100, R->PC.W);
for (J = 0, F = R->P; J < 8; J++, F <<= 1)
fprintf(fp, "%c", F & 0x80 ? FA[J] : '.');
fprintf(fp, "]\nCPU: ");
fprintf(fp, "AT PC: [%02X - %s] AT SP: [%02X %02X %02X]\nLast execution :\n",
Rd6502(R->PC.W), S,
Rd6502(0x0100 + (byte) (R->S + 1)),
Rd6502(0x0100 + (byte) (R->S + 2)),
Rd6502(0x0100 + (byte) (R->S + 3)));
showlastop(fp);
// fprintf(fp, "PPU: CR1: 0x%02X (NT:%d AI:%d SP:%d BP:%d SS:%d NMI:%d)\n",ppu.ControlRegister1.b, ppu.ControlRegister1.s.NameTblAddr, ppu.ControlRegister1.s.AddrIncrmt, ppu.ControlRegister1.s.SptPattern, ppu.ControlRegister1.s.BgPattern, ppu.ControlRegister1.s.SpriteSize, ppu.ControlRegister1.s.VBlank_NMI); // fprintf(fp, "PPU: CR1: 0x%02X (NT:%d AI:%d SP:%d BP:%d SS:%d NMI:%d)\n",ppu.ControlRegister1.b, ppu.ControlRegister1.s.NameTblAddr, ppu.ControlRegister1.s.AddrIncrmt, ppu.ControlRegister1.s.SptPattern, ppu.ControlRegister1.s.BgPattern, ppu.ControlRegister1.s.SpriteSize, ppu.ControlRegister1.s.VBlank_NMI);
// fprintf(fp, "PPU: CR2: 0x%02X (FBC/CI:%d SV:%d BV:%d SC:%d BC:%d DT:%d)\n",ppu.ControlRegister2.b,ppu.ControlRegister2.s.Colour,ppu.ControlRegister2.s.SpriteVisibility,ppu.ControlRegister2.s.BgVisibility,ppu.ControlRegister2.s.SpriteClipping,ppu.ControlRegister2.s.BgClipping,ppu.ControlRegister2.s.DisplayType); // fprintf(fp, "PPU: CR2: 0x%02X (FBC/CI:%d SV:%d BV:%d SC:%d BC:%d DT:%d)\n",ppu.ControlRegister2.b,ppu.ControlRegister2.s.Colour,ppu.ControlRegister2.s.SpriteVisibility,ppu.ControlRegister2.s.BgVisibility,ppu.ControlRegister2.s.SpriteClipping,ppu.ControlRegister2.s.BgClipping,ppu.ControlRegister2.s.DisplayType);
// fprintf(fp, "PPU: SR: 0x%02X (VB:%d S0:%d SSC:%d VWF:%d)\n", ppu.StatusRegister.b,ppu.StatusRegister.s.VBlankOccur,ppu.StatusRegister.s.Sprite0Occur,ppu.StatusRegister.s.SprtCount,ppu.StatusRegister.s.VRAMProtect); // fprintf(fp, "PPU: SR: 0x%02X (VB:%d S0:%d SSC:%d VWF:%d)\n", ppu.StatusRegister.b,ppu.StatusRegister.s.VBlankOccur,ppu.StatusRegister.s.Sprite0Occur,ppu.StatusRegister.s.SprtCount,ppu.StatusRegister.s.VRAMProtect);
// fprintf(fp, "PPU: M:%d ST:%d VRAMPtr:0x%04X T:0x%04X\n",ppu.MirrorDir,ppu.ScreenType,ppu.VRAMAddrReg2.W,ppu.TmpVRamPtr); // fprintf(fp, "PPU: M:%d ST:%d VRAMPtr:0x%04X T:0x%04X\n",ppu.MirrorDir,ppu.ScreenType,ppu.VRAMAddrReg2.W,ppu.TmpVRamPtr);
//MapperDump(fp); //MapperDump(fp);
#if 0
for(I = 0; I < 0xFFFF; I += 0x10) for(I = 0; I < 0xFFFF; I += 0x10)
fprintf(fp, "%04X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X | %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", fprintf(fp, "%04X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X | %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
I, I,
@@ -377,12 +344,12 @@ void *signalhandler(int sig)
isprint(Rd6502(I+0x0D))?Rd6502(I+0x0D):'_', isprint(Rd6502(I+0x0D))?Rd6502(I+0x0D):'_',
isprint(Rd6502(I+0x0E))?Rd6502(I+0x0E):'_', isprint(Rd6502(I+0x0E))?Rd6502(I+0x0E):'_',
isprint(Rd6502(I+0x0F))?Rd6502(I+0x0F):'_'); isprint(Rd6502(I+0x0F))?Rd6502(I+0x0F):'_');
#endif
DumpMemoryState(fp); DumpMemoryState(fp);
console_printf(Console_Error, "\nPlease join this informations when submiting crash report\n"); console_printf(Console_Error, "\nPlease join this informations when submiting crash report\n");
if (fp != stderr) fclose(fp); if (fp != stderr) fclose(fp);
#endif
exit(-42); exit(-42);
} }
@@ -390,6 +357,7 @@ byte Page40[256];
void WrHook4000Multiplexer(byte addr, byte value) void WrHook4000Multiplexer(byte addr, byte value)
{ {
#ifdef USE_SOUND
static byte SQ1V = 0; static byte SQ1V = 0;
static byte SQ2V = 0; static byte SQ2V = 0;
static byte NOIV = 0; static byte NOIV = 0;
@@ -410,6 +378,7 @@ void WrHook4000Multiplexer(byte addr, byte value)
static byte Sq2_reg3 = 0; static byte Sq2_reg3 = 0;
double SQ = 0.0; double SQ = 0.0;
#endif
switch(addr) switch(addr)
{ {
@@ -623,8 +592,6 @@ byte RdHook4000Multiplexer(byte addr)
case 0x15: case 0x15:
ret = 0x1F; ret = 0x1F;
break;
default: default:
ret = 0x42; ret = 0x42;
} }
@@ -645,7 +612,6 @@ void printUsage(int argc, char *argv[])
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i; int i;
unsigned char j, k;
unsigned char *MemoryPage; unsigned char *MemoryPage;
quick6502_cpuconfig CpuConfig; quick6502_cpuconfig CpuConfig;
@@ -665,31 +631,30 @@ int main(int argc, char *argv[])
2kB Internal RAM, mirrored 4 times 2kB Internal RAM, mirrored 4 times
--------------------------------------- $0000 --------------------------------------- $0000
*/ */
console_init(Console_Default); console_init(Console_Debug);
/* Print the banner */ /* Print the banner */
console_printf(Console_Default, "--------------------------------------------------------------------------------\n" console_printf(Console_Default, "--------------------------------------------------------------------------------\n"
"Welcome to TI-NESulator v%d.%d - by Godzil\n" "Welcome to TI-NESulator v%d.%d - by Godzil\n"
"Copyright 2003-2008 TRAPIER Manoel (godzil@godzil.net)\n" "Copyright 2003-2016 TRAPIER Manoel (godzil@godzil.net)\n"
"%s\n%s\n%s\n"
"--------------------------------------------------------------------------------\n\n", "--------------------------------------------------------------------------------\n\n",
V_MAJOR, V_MAJOR, V_MINOR);
V_MINOR,
VS_REVISION,
VS_LASTCHANGEDDATE,
VS_AUTHOR);
console_printf(Console_Default, "Install signal handlers...\t["); console_printf(Console_Default, "Install signal handlers...\t[");
// signal(SIGABRT,signalhandler); signal(SIGABRT, signalhandler);
console_printf(Console_Default, "A"); console_printf(Console_Default, "A");
// signal(SIGILL,signalhandler); signal(SIGILL, signalhandler);
console_printf(Console_Default, "I"); console_printf(Console_Default, "I");
/*signal(SIGINT,signalhandler);*/ /*signal(SIGINT, signalhandler);*/
console_printf(Console_Default, "."); console_printf(Console_Default, ".");
// signal(SIGSEGV,signalhandler); signal(SIGSEGV, signalhandler);
console_printf(Console_Default, "S"); console_printf(Console_Default, "S");
// signal(SIGTERM,signalhandler); signal(SIGTERM, signalhandler);
console_printf(Console_Default, "T]\n"); console_printf(Console_Default, "T]\n");
#ifdef RUN_COVERAGE
signal(SIGALRM, alarmHandler);
#endif
/* */ /* */
console_printf(Console_Default, "Initialize memory...\t\t"); console_printf(Console_Default, "Initialize memory...\t\t");
InitMemory(); InitMemory();
@@ -812,6 +777,7 @@ int main(int argc, char *argv[])
#define Value(s) (((s%0xFF) + (rand()%0xFF-128) )%0xFF) #define Value(s) (((s%0xFF) + (rand()%0xFF-128) )%0xFF)
#ifdef MEMORY_TEST
console_printf(Console_Default, "Testing memory validity...\n"); console_printf(Console_Default, "Testing memory validity...\n");
map_sram(); map_sram();
@@ -841,12 +807,13 @@ int main(int argc, char *argv[])
if ((k=MemoryOpCodeRead(i)) != j) if ((k=MemoryOpCodeRead(i)) != j)
console_printf(Console_Error, "Error opcode @ 0x%X [w:%d,r:%d]\n", i, j, k); console_printf(Console_Error, "Error opcode @ 0x%X [w:%d,r:%d]\n", i, j, k);
} }
#endif
/* SRAM (0x6000 : 0x2000 bytes ) */ /* SRAM (0x6000 : 0x2000 bytes ) */
MemoryPage = (unsigned char *)malloc (0x2000); MemoryPage = (unsigned char *)malloc (0x2000);
set_page_ptr_8k(0x60, MemoryPage); set_page_ptr_8k(0x60, MemoryPage);
#ifdef MEMORY_TEST
for(i = 0x6000; i < 0x8000; i ++) for(i = 0x6000; i < 0x8000; i ++)
{ {
if (MemoryPage[i-0x6000] != (k = MemoryRead(i))) if (MemoryPage[i-0x6000] != (k = MemoryRead(i)))
@@ -875,6 +842,7 @@ int main(int argc, char *argv[])
} }
console_printf(Console_Default, "[ OK ]\n"); console_printf(Console_Default, "[ OK ]\n");
#endif
Cart = malloc( sizeof (NesCart)); Cart = malloc( sizeof (NesCart));
if (Cart == NULL) if (Cart == NULL)
@@ -887,8 +855,13 @@ int main(int argc, char *argv[])
{ {
int fd; int fd;
console_printf(Console_Default, "Loading FDS ROM...\t\t"); console_printf(Console_Default, "Loading FDS ROM...\t\t");
//fd = open("../data/disksys.rom", O_RDONLY); fd = open("../data/disksys.rom", O_RDONLY);
fd = open("TI-NESulator.app/Contents/Resources/disksys.rom", O_RDONLY); //fd = open("TI-NESulator.app/Contents/Resources/disksys.rom", O_RDONLY);
if (fd < 0)
{
console_printf(Console_Error, "Can't find FDS ROM...\n");
exit(-1);
}
FDSRom = mmap(NULL, 8*1024, PROT_READ, MAP_PRIVATE, fd, 0); FDSRom = mmap(NULL, 8*1024, PROT_READ, MAP_PRIVATE, fd, 0);
console_printf(Console_Default, "%p [ OK ]\n", FDSRom); console_printf(Console_Default, "%p [ OK ]\n", FDSRom);
@@ -935,22 +908,6 @@ int main(int argc, char *argv[])
InitPaddle(&P1); InitPaddle(&P1);
console_printf(Console_Default, "Initializing Allegro...\t\t");
allegro_init();
install_timer();
install_keyboard();
console_printf(Console_Default, "[ OK ]\n");
console_printf(Console_Default, "Set graphic mode...\t\t");
set_color_depth(8);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 512 + 256, 480, 512 + 256, 480);
Buffer = create_bitmap(512 + 256, 480);
clear_to_color(Buffer, 0x0D);
//set_close_button_callback(CloseHook);
//set_window_title("TI-NESulator");
console_printf(Console_Default, "[ OK ]\n");
console_printf(Console_Default, "Init PPU...\n"); console_printf(Console_Default, "Init PPU...\n");
if (ppu_init() != 0) if (ppu_init() != 0)
@@ -959,7 +916,7 @@ int main(int argc, char *argv[])
exit(-1); exit(-1);
} }
DumpMemoryState(); DumpMemoryState(stdout);
if (Cart->Flags & iNES_4SCREEN) if (Cart->Flags & iNES_4SCREEN)
{ {
@@ -976,15 +933,7 @@ int main(int argc, char *argv[])
return -1; return -1;
console_printf(Console_Default, "[ OK ]\n"); console_printf(Console_Default, "[ OK ]\n");
if (PALETTE_FILENAME == NULL) // set_palette(basicPalette);
{
set_palette(basicPalette);
}
else
{
LoadPalette(PALETTE_FILENAME, pal);
set_palette(pal);
}
#ifdef USE_SOUND #ifdef USE_SOUND
InitSound(44400,!0); InitSound(44400,!0);
@@ -996,7 +945,7 @@ int main(int argc, char *argv[])
#endif #endif
// Actually no real debugguer... // Actually no real debugguer...
//console_printf(Console_Default, "Press ESC to pause emulation and jump to debugguer\n"); //console_printf(Console_Default, "Press ESC to pause emulation and jump to debugguer\n");
install_int(ips_fps_counter, 1000);
ScanLine = 0; ScanLine = 0;
/* Initialize the CPU */ /* Initialize the CPU */
@@ -1020,6 +969,10 @@ int main(int argc, char *argv[])
gettimeofday(&timeStart, NULL); gettimeofday(&timeStart, NULL);
#ifdef RUN_COVERAGE
alarm(1 * 60); /* Run for 1 minutes */
#endif
while(!WantClosing) while(!WantClosing)
{ {
ccount += quick6502_run(MainCPU, HBLANK_TIME); ccount += quick6502_run(MainCPU, HBLANK_TIME);
@@ -1033,7 +986,6 @@ int main(int argc, char *argv[])
} }
return 0; return 0;
} }
//END_OF_MAIN()
/* Access directly to Memory pages *HACKISH* */ /* Access directly to Memory pages *HACKISH* */
extern byte *memory_pages[0xFF]; extern byte *memory_pages[0xFF];
@@ -1085,13 +1037,13 @@ void MemoryPageZeroWrite (unsigned short Addr, byte Value)
void Loop6502(quick6502_cpu *R) void Loop6502(quick6502_cpu *R)
{ {
byte ret; byte ret;
short skey; // short skey;
long WaitTime; long WaitTime;
static long delta=0; static long delta=0;
ret = 0; ret = 0;
if ( mapper_irqloop (ScanLine) ) if ( (mapper_irqloop) && ( mapper_irqloop (ScanLine) ) )
{ {
ret = Q6502_IRQ_SIGNAL; ret = Q6502_IRQ_SIGNAL;
IRQScanHit = ScanLine; IRQScanHit = ScanLine;
@@ -1108,12 +1060,11 @@ void Loop6502(quick6502_cpu *R)
ret = Q6502_NMI_SIGNAL; ret = Q6502_NMI_SIGNAL;
} }
if (ScanLine == 239)
frame++;
if (ScanLine == (239 + VBLANK_TIME)) if (ScanLine == (239 + VBLANK_TIME))
{ /* End of VBlank Time */ { /* End of VBlank Time */
frame++;
SZHit = -1;
IRQScanHit = -1;
/* Sync at 60FPS */ /* Sync at 60FPS */
/* Get current time in microseconds */ /* Get current time in microseconds */
gettimeofday(&timeEnd, NULL); gettimeofday(&timeEnd, NULL);
@@ -1129,9 +1080,9 @@ void Loop6502(quick6502_cpu *R)
#endif #endif
/* If we press Page Up, we want to accelerate "time" */ /* If we press Page Up, we want to accelerate "time" */
if (!key[KEY_PGUP]) if (!getKeyStatus('Y'))
if ((WaitTime >= 0) && (WaitTime < 100000)) if ((WaitTime >= 0) && (WaitTime < 100000))
usleep(WaitTime); usleep(WaitTime);
/* Now get the time after sleep */ /* Now get the time after sleep */
gettimeofday(&timeStart, NULL); gettimeofday(&timeStart, NULL);
@@ -1154,15 +1105,13 @@ void Loop6502(quick6502_cpu *R)
else else
ScanLine++; ScanLine++;
//console_printf(Console_Default, "SL:%d HBT:%d VbT:%d\n", ScanLine, HBLANK_TIME, VBLANK_TIME); //console_printf(Console_Default, "SL:%d HBT:%d VbT:%d\n", ScanLine, HBLANK_TIME, VBLANK_TIME);
if (keypressed())
{
skey = (readkey() & 0xFF);
// TODO: NO DEBUGER
/* if (skey == 27)
R->Trace = 1;*/
// TODO: NO DEBUGER
if (getKeyStatus(GLFW_KEY_ESCAPE))
exit(0);
#if 0
if (skey == '9') if (skey == '9')
{ {
VBLANK_TIME += 2; VBLANK_TIME += 2;
@@ -1186,17 +1135,16 @@ void Loop6502(quick6502_cpu *R)
HBLANK_TIME -= 1; HBLANK_TIME -= 1;
console_printf(Console_Default, "HBLT: %d\n", HBLANK_TIME); console_printf(Console_Default, "HBLT: %d\n", HBLANK_TIME);
} }
#endif
if ((skey == 'r') || (skey == 'R')) if (getKeyStatus('r') || getKeyStatus('R'))
{ {
/* Force the PPU to stop NMIs */ /* Force the PPU to stop NMIs */
MemoryWrite(0x2000, 0x00); MemoryWrite(0x2000, 0x00);
quick6502_reset(R); quick6502_reset(R);
} }
plugin_keypress(skey); // plugin_keypress(skey);
}
if (ret != 0) if (ret != 0)
quick6502_int(R, ret); quick6502_int(R, ret);

View File

@@ -2,7 +2,7 @@
# TI-NES CMake # TI-NES CMake
# #
# Created by Manoel TRAPIER. # Created by Manoel TRAPIER.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2003-2016 986-Studio. All rights reserved.
# #
# $LastChangedDate$ # $LastChangedDate$
# $Author$ # $Author$
@@ -10,4 +10,9 @@
# $Revision$ # $Revision$
file(GLOB mappers_list mappers/*.c) file(GLOB mappers_list mappers/*.c)
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} ) add_library(mappermanager utils.c manager.c ${mappers_list} )

View File

@@ -3,7 +3,7 @@
* manager.c * manager.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -50,13 +50,14 @@ void mapper_list ()
int mapper_init (NesCart *cart) int mapper_init (NesCart *cart)
{ {
Mapper *ptr = &(Mappers[0]); Mapper *ptr = &(Mappers[0]);
console_printf (Console_Default, "Search for a compatible mapper ID #%X:\n", cart->MapperID); console_printf (Console_Default, "Search for a compatible mapper ID #%d:\n", cart->MapperID);
while (ptr->name != NULL) while (ptr->name != NULL)
{ {
if (ptr->id == cart->MapperID) if (ptr->id == cart->MapperID)
{ {
console_printf (Console_Default, "Found mapper ID #%X - '%s'\n", ptr->id, ptr->name); console_printf (Console_Default, "Found mapper ID #%d - '%s'\n", ptr->id, ptr->name);
ptr->init (cart); if (ptr->init)
ptr->init (cart);
mapper_irqloop = ptr->irq; mapper_irqloop = ptr->irq;
mapper_dump = ptr->dump; mapper_dump = ptr->dump;
@@ -65,5 +66,6 @@ int mapper_init (NesCart *cart)
} }
ptr++; ptr++;
} }
console_printf (Console_Default, "No compatible mapper found!\n");
return -1; return -1;
} }

View File

@@ -3,7 +3,7 @@
* aorom.c * aorom.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -55,7 +55,7 @@ void aorom_MapperWriteHook(register byte Addr, register byte Value)
aorom_load_bank = BankNb; aorom_load_bank = BankNb;
//console_printf(Console_Default, "aorom: Asking bank %d (giving %d & %d) - mirror is %d\n",BankNb,BankNb,(Value<<1)+1,Value&0x0F); //console_printf(Console_Default, "aorom: Asking bank %d - NT is 0x%04X\n",BankNb,(Value&0x10)?0x2400:0x2000);
set_prom_bank_32k(0x8000,BankNb); set_prom_bank_32k(0x8000,BankNb);
} }

View File

@@ -3,7 +3,7 @@
* aorom.h * aorom.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* cnrom.c * cnrom.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* cnrom.h * cnrom.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* iremh3001.c * iremh3001.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -116,7 +116,7 @@ void iremh3001_MapperDump(FILE *fp)
iremh3001_vrom_slot[4], iremh3001_vrom_slot[4],
iremh3001_vrom_slot[5], iremh3001_vrom_slot[5],
iremh3001_vrom_slot[6], iremh3001_vrom_slot[6],
iremh3001_prom_slot[7]); iremh3001_vrom_slot[7]);
} }

View File

@@ -3,7 +3,7 @@
* iremh3001.h * iremh3001.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* mmc1.h * mmc1.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -12,17 +12,17 @@
* *
*/ */
#include "norom.h" #include "mmc1.h"
unsigned char MMC1_reg0; uint8_t MMC1_reg0;
unsigned char MMC1_reg1; uint8_t MMC1_reg1;
unsigned char MMC1_reg2; uint8_t MMC1_reg2;
unsigned char MMC1_reg3; uint8_t MMC1_reg3;
unsigned char mmc1_CurrentBank; uint8_t mmc1_CurrentBank;
#define MMC1_R0_MIRROR 0x01 #define MMC1_R0_MIRROR 0x01
#define MMC1_R0_ONESCREEN 0x02 #define MMC1_R0_ONESCREEN 0x02
@@ -135,7 +135,7 @@ Reg 0
void mmc1_ApplyReg0Mod() void mmc1_ApplyReg0Mod()
{ {
static unsigned char OldSwitchArea = MMC1_R0_PRGAREA; static uint8_t OldSwitchArea = MMC1_R0_PRGAREA;
@@ -182,9 +182,9 @@ void mmc1_ApplyReg0Mod()
} }
int VROMBankNb; uint32_t VROMBankNb;
unsigned char Bit = 0; uint8_t Bit = 0;
unsigned char BitBuf = 0; uint8_t BitBuf = 0;
void mmc1_MapperWriteReg0(register byte Addr, register byte Value) void mmc1_MapperWriteReg0(register byte Addr, register byte Value)
{ {
@@ -321,7 +321,7 @@ void mmc1_MapperWriteReg3(register byte Addr, register byte Value)
MMC1_reg3 = BitBuf; MMC1_reg3 = BitBuf;
if (MMC1_reg3<<14 > Cart->PROMSize) if ( ((uint32_t)MMC1_reg3 << 14) > Cart->PROMSize)
return; return;
if ( (MMC1_reg0 & MMC1_R0_PRGSIZE) != 0 ) if ( (MMC1_reg0 & MMC1_R0_PRGSIZE) != 0 )

View File

@@ -3,7 +3,7 @@
* mmc1.h * mmc1.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* mmc3.h * mmc3.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* mmc3.h * mmc3.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* mmc4.h * mmc4.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2007-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -27,6 +27,7 @@ byte mmc4_RegF;
#define LOG(s) { } #define LOG(s) { }
#endif #endif
/* MAPPER WARNING: This mapper need to attach to the PPU memory... Need more work on this parts.. */
void mmc4_MapperWriteRegA(register byte Addr, register byte Value) void mmc4_MapperWriteRegA(register byte Addr, register byte Value)
{ {
@@ -86,7 +87,7 @@ int mmc4_InitMapper(NesCart * cart)
{ {
int i; int i;
set_prom_bank_16k(0x8000,0); set_prom_bank_16k(0x8000, 0);
set_prom_bank_16k(0xC000, GETLAST16KBANK(cart)); set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
if (cart->VROMSize > 0) if (cart->VROMSize > 0)

View File

@@ -3,7 +3,7 @@
* mmc4.h * mmc4.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2007-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* norom.c * norom.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* norom.c * norom.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* unrom.h * unrom.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* unrom.h * unrom.h
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -0,0 +1,68 @@
/*
* UNROM Mapper - The TI-NESulator Project
* unrom.h
*
* Created by Manoel TRAPIER.
* Copyright (c) 2003-2016 986-Studio. All rights reserved.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*
*/
#include <ppu/ppu.h>
#include "unrom512.h"
static byte mirroring_set;
static byte loaded_vbank;
static byte loaded_pbank;
static void unrom512_applyValues()
{
/*if (mirroring_set)
{
ppu_setMirroring(PPU);
}
else
{
ppu_setMirroring(PPU_MIRROR_VERTICAL);
}*/
//set_vrom_bank_8k(0x0000, loaded_vbank);
set_prom_bank_16k(0x8000, loaded_pbank);
}
static void unrom512_MapperWriteHook(byte Addr, byte Value)
{
mirroring_set = (Value >> 7) & 0x01;
loaded_vbank = (Value >> 5) & 0x03;
loaded_pbank = (Value ) & 0x1F;
unrom512_applyValues();
}
int unrom512_InitMapper(NesCart * cart)
{
int i;
loaded_vbank = 0;
loaded_pbank = 0;
set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
unrom512_applyValues();
/* Register the write hook */
for (i = 0x80; i < 0x100; i++)
{
set_page_wr_hook(i, unrom512_MapperWriteHook);
set_page_writeable(i, true);
}
return 0;
}
void unrom512_MapperDump(FILE *fp)
{
fprintf(fp,"unrom512: vbank:%d pbank:%d\n", loaded_vbank, loaded_pbank);
}

View File

@@ -0,0 +1,19 @@
/*
* UNROM Mapper - The TI-NESulator Project
* unrom.h
*
* Created by Manoel TRAPIER.
* Copyright (c) 2003-2016 986-Studio. All rights reserved.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*
*/
#define __TINES_MAPPERS__
#include <mappers/manager.h>
int unrom512_InitMapper(NesCart * cart);
void unrom512_MapperDump(FILE *fp);

View File

@@ -3,7 +3,7 @@
* mappers_list.h * mappers_list.h
* *
* Created by Manoel TRAPIER on 25/10/07. * Created by Manoel TRAPIER on 25/10/07.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -18,6 +18,8 @@
#include "mappers/unrom.h" #include "mappers/unrom.h"
#include "mappers/cnrom.h" #include "mappers/cnrom.h"
#include "mappers/unrom512.h"
#include "mappers/iremh3001.h" #include "mappers/iremh3001.h"
#include "mappers/mmc1.h" #include "mappers/mmc1.h"
@@ -32,10 +34,14 @@ Mapper Mappers[] = {
{ 1 , "MMC1", mmc1_InitMapper, norom_MapperIRQ, mmc1_MapperDump }, { 1 , "MMC1", mmc1_InitMapper, norom_MapperIRQ, mmc1_MapperDump },
{ 4 , "MMC3", mmc3_InitMapper, mmc3_MapperIRQ, mmc3_MapperDump }, { 4 , "MMC3", mmc3_InitMapper, mmc3_MapperIRQ, mmc3_MapperDump },
{ 10, "MMC4", mmc3_InitMapper, norom_MapperIRQ, mmc4_MapperDump }, { 10, "MMC4", mmc4_InitMapper, norom_MapperIRQ, mmc4_MapperDump },
{ 30, "UNROM512", unrom512_InitMapper, norom_MapperIRQ, unrom512_MapperDump },
{ 65, "Irem H3001", iremh3001_InitMapper, iremh3001_MapperIRQ, iremh3001_MapperDump }, { 65, "Irem H3001", iremh3001_InitMapper, iremh3001_MapperIRQ, iremh3001_MapperDump },
{ 100, "Floppy Disk System", NULL, norom_MapperIRQ, norom_MapperDump },
/* EOL tag */ /* EOL tag */
{ 0, NULL, NULL, NULL, NULL } { 0, NULL, NULL, NULL, NULL }
}; };

View File

@@ -3,7 +3,7 @@
* mappers.c * mappers.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -2,11 +2,15 @@
# TI-NES CMake # TI-NES CMake
# #
# Created by Manoel TRAPIER. # Created by Manoel TRAPIER.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2003-2016 986-Studio. All rights reserved.
# #
# $LastChangedDate$ # $LastChangedDate$
# $Author$ # $Author$
# $HeadURL$ # $HeadURL$
# $Revision$ # $Revision$
if (COVERALLS)
set(COVERAGE_SRCS src/memorymanager/memory.c ${COVERAGE_SRCS} PARENT_SCOPE)
endif()
add_library(memorymanager memory.c) add_library(memorymanager memory.c)

View File

@@ -3,7 +3,7 @@
* memory.c - Taken from the Quick6502 project * memory.c - Taken from the Quick6502 project
* *
* Created by Manoel Trapier on 18/09/06. * Created by Manoel Trapier on 18/09/06.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -2,11 +2,18 @@
# TI-NES CMake # TI-NES CMake
# #
# Created by Manoel TRAPIER. # Created by Manoel TRAPIER.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2003-2016 986-Studio. All rights reserved.
# #
# $LastChangedDate$ # $LastChangedDate$
# $Author$ # $Author$
# $HeadURL$ # $HeadURL$
# $Revision$ # $Revision$
add_library(oslib loadfile.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} ${OPENGL_gl_LIBRARY})

438
src/os/unix/graphics.c Normal file
View File

@@ -0,0 +1,438 @@
/*
* 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <os_dependent.h>
#define GLFW_INCLUDE_GLEXT
#include <GLFW/glfw3.h>
#include <palette.h>
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;
};
static int window_num = 0;
void GLWindowInitEx(GLWindow *g, int w, int h)
{
g->WIDTH = w;
g->HEIGHT = h;
g->videoTexture = window_num++;
}
void GLWindowInit(GLWindow *g)
{
GLWindowInitEx(g, 100, 100);
}
void ShowScreen(GLWindow *g, int w, int h)
{
glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
// glTexSubImage2D is faster when not using a texture range
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);
glVertex2f(-1.0f,1.0f);
glTexCoord2f(0.0f, h);
glVertex2f(-1.0f, -1.0f);
glTexCoord2f(w, h);
glVertex2f(1.0f, -1.0f);
glTexCoord2f(w, 0.0f);
glVertex2f(1.0f, 1.0f);
glEnd();
glFlush();
}
void setupGL(GLWindow *g, int w, int h)
{
g->videoMemory = (unsigned char*)malloc(w*h*sizeof(unsigned int));
memset(g->videoMemory, 0,w*h*sizeof(unsigned int));
//Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glClearColor(1.0f, 0.f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
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, 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, 0, GL_RGBA, w,
h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory);
glDisable(GL_DEPTH_TEST);
}
void restoreGL(GLWindow *g, int w, int h)
{
//Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glClearColor(1.0f, 0.f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE);
glDisable(GL_DEPTH_TEST);
}
void kbHandler(GLFWwindow* window, int key, int scan, int action, int mod )
{
struct KeyArray *keyArray;
keyArray = (struct KeyArray*) glfwGetWindowUserPointer(window);
keyArray[key].lastState=keyArray[key].curState;
if (action==GLFW_RELEASE)
{
keyArray[key].curState=GLFW_RELEASE;
}
else
{
keyArray[key].curState=GLFW_PRESS;
}
keyArray[key].debounced |= (keyArray[key].lastState==GLFW_RELEASE)&&(keyArray[key].curState==GLFW_PRESS);
keyArray[key].window = window;
}
void sizeHandler(GLFWwindow* window,int xs,int ys)
{
glfwMakeContextCurrent(window);
glViewport(0, 0, xs, ys);
}
static void error_callback(int error, const char* description)
{
puts(description);
}
void initDisplay(GLWindow *g)
{
int h = g->HEIGHT;
int w = g->WIDTH;
/// Initialize GLFW
glfwInit();
glfwSetErrorCallback(error_callback);
// Open screen OpenGL window
if( !(g->windows=glfwCreateWindow( g->WIDTH, g->HEIGHT, "Main", NULL, NULL)) )
{
glfwTerminate();
fprintf(stderr, "Window creation error...\n");
abort();
}
glfwMakeContextCurrent(g->windows);
setupGL(g, g->WIDTH, g->HEIGHT);
glfwSwapInterval(0); // Disable VSYNC
glfwGetWindowSize(g->windows, &w, &h);
glfwSetWindowUserPointer(g->windows, g->keyArray);
glfwSetKeyCallback(g->windows, kbHandler);
glfwSetWindowSizeCallback(g->windows, sizeHandler);
}
void drawPixel(GLWindow *gw, int x, int y, uint32_t colour)
{
uint8_t r,g,b,a;
uint32_t offset = (y*gw->WIDTH*4)+4*x;
if ((x < 0) || (x > gw->WIDTH) || (y < 0) || (y > gw->HEIGHT))
return;
b = colour & 0xFF;
g = (colour >> 8) & 0xFF;
r = (colour >> 16) & 0xFF;
a = (colour >> 24) & 0xFF;
gw->videoMemory[offset + 0] = a;
gw->videoMemory[offset + 1] = r;
gw->videoMemory[offset + 2] = g;
gw->videoMemory[offset + 3] = b;
}
void drawLine(GLWindow *g, int x0, int y0, int x1, int y1, uint32_t colour)
{
int d, dx, dy, aincr, bincr, xincr, yincr, x, y;
if (abs(x1 - x0) < abs(y1 - y0))
{
/* parcours par l'axe vertical */
if (y0 > y1)
{
drawLine(g, x1, y1, x0, y0, colour);
goto exit;
}
xincr = x1 > x0 ? 1 : -1;
dy = y1 - y0;
dx = abs(x1 - x0);
d = 2 * dx - dy;
aincr = 2 * (dx - dy);
bincr = 2 * dx;
x = x0;
y = y0;
drawPixel(g, x, y, colour);
for (y = y0+1; y <= y1; y++)
{
if (d >= 0)
{
x += xincr;
d += aincr;
}
else
{
d += bincr;
}
drawPixel(g, x, y, colour);
}
}
else
{
/* parcours par l'axe horizontal */
if (x0 > x1)
{
drawLine(g, x1, y1, x0, y0, colour);
goto exit;
}
yincr = y1 > y0 ? 1 : -1;
dx = x1 - x0;
dy = abs(y1 - y0);
d = 2 * dy - dx;
aincr = 2 * (dy - dx);
bincr = 2 * dy;
x = x0;
y = y0;
drawPixel(g, x, y, colour);
for (x = x0+1; x <= x1; ++x)
{
if (d >= 0)
{
y += yincr;
d += aincr;
}
else
{
d += bincr;
}
drawPixel(g, x, y, colour);
}
}
exit:
return;
}
void drawCircle(GLWindow *g, int xc, int yc, int radius, uint32_t colour)
{
int f = 1 - radius;
int ddF_x = 0;
int ddF_y = -2 * radius;
int x = 0;
int y = radius;
int pX, pY;
pX = xc; pY = yc + radius;
drawPixel(g, pX, pY, colour);
pY -= (2*radius);
drawPixel(g, pX, pY, colour);
pY += radius; pX += radius;
drawPixel(g, pX, pY, colour);
pX -= (2*radius);
drawPixel(g, pX, pY, colour);
while(x < y)
{
if(f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x + 1;
pX = xc+x ; pY = yc+y;
drawPixel(g, pX, pY, colour);
pX = xc-x ; pY = yc+y;
drawPixel(g, pX, pY, colour);
pX = xc+x ; pY = yc-y;
drawPixel(g, pX, pY, colour);
pX = xc-x ; pY = yc-y;
drawPixel(g, pX, pY, colour);
pX = xc+y ; pY = yc+x;
drawPixel(g, pX, pY, colour);
pX = xc-y ; pY = yc+x;
drawPixel(g, pX, pY, colour);
pX = xc+y ; pY = yc-x;
drawPixel(g, pX, pY, colour);
pX = xc-y ; pY = yc-x;
drawPixel(g, pX, pY, colour);
}
return;
}
void drawRect(GLWindow *g, int x0, int y0, int w, int h, uint32_t colour)
{
drawLine(g, x0 , y0 , x0 + w, y0 , colour);
drawLine(g, x0 + w, y0 , x0 + w, y0 + h, colour);
drawLine(g, x0 + w, y0 + h, x0 , y0 + h, colour);
drawLine(g, x0 , y0 + h, x0 , y0 , colour);
}
void drawFillrect(GLWindow *g, int x0, int y0, int w, int h, uint32_t colour)
{
int i;
for(i = 0; i < h; i++)
drawLine(g, x0, y0+i, x0+w, y0+i, colour);
}
void clearScreen(GLWindow *g)
{
memset(g->videoMemory, 0, sizeof(uint8_t) * g->WIDTH * g->HEIGHT * 4);
}
void updateScreen(GLWindow *g)
{
/*Update windows code */
glfwMakeContextCurrent(g->windows);
ShowScreen(g, g->WIDTH, g->HEIGHT);
glfwSwapBuffers(g->windows);
glfwPollEvents();
}
void updateScreenAndWait(GLWindow *g)
{
while (glfwGetKey(g->windows,GLFW_KEY_ESCAPE) != GLFW_PRESS)
{
updateScreen(g);
glfwPollEvents();
}
while(glfwGetKey(g->windows,GLFW_KEY_ESCAPE) != GLFW_RELEASE)
{
glfwPollEvents();
}
}
GLWindow mainWindow;
int graphics_init()
{
GLWindowInitEx(&mainWindow, 256, 240);
initDisplay(&mainWindow);
clearScreen(&mainWindow);
updateScreen(&mainWindow);
return 0;
}
static unsigned long getColour(long color)
{
Palette *pal = &basicPalette[color];
uint8_t r, g, b, a;
r = pal->r;
b = pal->b;
g = pal->g;
a = 255;//pal->a;
return (b << 24) | (g << 16) | (r << 8) | a;
}
int graphics_drawpixel(long x, long y, long color)
{
drawPixel(&mainWindow, x, y, getColour(color));
return 0;
}
int graphics_drawline(long x, long y, long x1, long y1, long color)
{
drawLine(&mainWindow, x, y, x1, y1, getColour(color));
return 0;
}
int graphics_blit(long x, long y, long w, long h)
{
updateScreen(&mainWindow);
return 0;
}
int getKeyStatus(int key)
{
return mainWindow.keyArray[key].curState;
}

View File

@@ -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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <os_dependent.h>
#include <GLFW/glfw3.h>
//#include <OpenGL/glext.h>
#include <palette.h>
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;
}

60
src/os/unix/io.c Normal file
View File

@@ -0,0 +1,60 @@
/*
* IO Manager - The TI-NESulator Project
* os/macos/graphics.c
*
* Created by Manoël Trapier on 04/01/09.
* Copyright (c) 2003-2016 986-Studio. All rights reserved.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*
*/
#include <stdio.h>
#include <stdarg.h>
#include <os_dependent.h>
char LevelChar[] = { 'E', 'W', 'A', 'N', 'V', 'D'};
ConsoleLevel console_ActualLevel = Console_Default;
/* Actually nothing to do */
int console_init(ConsoleLevel DefaultLevel)
{
console_ActualLevel = DefaultLevel;
return 0;
}
/* Actually a simple printf with levels */
int console_vprintf(const ConsoleLevel level, const char *format, va_list ap)
{
if (console_ActualLevel >= level)
vprintf(format, ap);
return 0;
}
int console_printf(const ConsoleLevel level, const char *format, ...)
{
va_list ap;
va_start(ap, format);
console_vprintf(level, format, ap);
va_end(ap);
return 0;
}
int console_printf_d(const char *format, ...)
{
va_list ap;
va_start(ap, format);
console_vprintf (Console_Debug, format, ap);
return 0;
}

View File

@@ -1,3 +1,6 @@
/*
* Copyright (c) 2003-2016 986-Studio. All rights reserved.
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -27,5 +30,10 @@ void *LoadFilePtr(char * filename)
close(fd); close(fd);
if ( RetPtr == MAP_FAILED )
{
RetPtr = NULL;
}
return RetPtr; return RetPtr;
} }

0
src/os/unix/sound.c Normal file
View File

View File

@@ -2,11 +2,13 @@
# TI-NES CMake # TI-NES CMake
# #
# Created by Manoel TRAPIER. # Created by Manoel TRAPIER.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2003-2016 986-Studio. All rights reserved.
# #
# $LastChangedDate$ # $LastChangedDate$
# $Author$ # $Author$
# $HeadURL$ # $HeadURL$
# $Revision$ # $Revision$
add_library(oslib loadfile.c) add_library(oslib loadfile.c graphics.c sound.c io.c)
target_link_libraries(oslib glfw ${OPENGL_glu_LIBRARY})

436
src/os/win32/graphics.c Normal file
View File

@@ -0,0 +1,436 @@
/*
* 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <os_dependent.h>
#include <GLFW/glfw3.h>
#include <OpenGL/glext.h>
#include <palette.h>
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
static int window_num = 0;
void GLWindowInitEx(GLWindow *g, int w, int h)
{
g->WIDTH = w;
g->HEIGHT = h;
g->videoTexture = window_num++;
}
void GLWindowInit(GLWindow *g)
{
GLWindowInitEx(g, 100, 100);
}
void ShowScreen(GLWindow *g, int w, int h)
{
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 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);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-1.0f,1.0f);
glTexCoord2f(0.0f, h);
glVertex2f(-1.0f, -1.0f);
glTexCoord2f(w, h);
glVertex2f(1.0f, -1.0f);
glTexCoord2f(w, 0.0f);
glVertex2f(1.0f, 1.0f);
glEnd();
glFlush();
}
void setupGL(GLWindow *g, int w, int h)
{
g->videoMemory = (unsigned char*)malloc(w*h*sizeof(unsigned int));
memset(g->videoMemory, 0,w*h*sizeof(unsigned int));
//Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glClearColor(1.0f, 0.f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_EXT);
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 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);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, w,
h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory);
glDisable(GL_DEPTH_TEST);
}
void restoreGL(GLWindow *g, int w, int h)
{
//Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glClearColor(1.0f, 0.f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_EXT);
glDisable(GL_DEPTH_TEST);
}
void kbHandler(GLFWwindow* window, int key, int scan, int action, int mod )
{
struct KeyArray *keyArray;
keyArray = (struct KeyArray*) glfwGetWindowUserPointer(window);
keyArray[key].lastState=keyArray[key].curState;
if (action==GLFW_RELEASE)
{
keyArray[key].curState=GLFW_RELEASE;
}
else
{
keyArray[key].curState=GLFW_PRESS;
}
keyArray[key].debounced |= (keyArray[key].lastState==GLFW_RELEASE)&&(keyArray[key].curState==GLFW_PRESS);
keyArray[key].window = window;
}
void sizeHandler(GLFWwindow* window,int xs,int ys)
{
glfwMakeContextCurrent(window);
glViewport(0, 0, xs, ys);
}
void initDisplay(GLWindow *g)
{
int h = g->HEIGHT;
int w = g->WIDTH;
/// Initialize GLFW
glfwInit();
// Open screen OpenGL window
if( !(g->windows=glfwCreateWindow( g->WIDTH, g->HEIGHT, "Main", NULL, NULL)) )
{
glfwTerminate();
fprintf(stderr, "Window creation error...\n");
return;
}
glfwMakeContextCurrent(g->windows);
setupGL(g, g->WIDTH, g->HEIGHT);
glfwSwapInterval(0); // Disable VSYNC
glfwGetWindowSize(g->windows, &w, &h);
glfwSetWindowUserPointer(g->windows, g->keyArray);
glfwSetKeyCallback(g->windows, kbHandler);
glfwSetWindowSizeCallback(g->windows, sizeHandler);
}
void drawPixel(GLWindow *gw, int x, int y, uint32_t colour)
{
uint8_t r,g,b,a;
uint32_t offset = (y*gw->WIDTH*4)+4*x;
if ((x < 0) || (x > gw->WIDTH) || (y < 0) || (y > gw->HEIGHT))
return;
b = colour & 0xFF;
g = (colour >> 8) & 0xFF;
r = (colour >> 16) & 0xFF;
a = (colour >> 24) & 0xFF;
gw->videoMemory[offset + 0] = a;
gw->videoMemory[offset + 1] = r;
gw->videoMemory[offset + 2] = g;
gw->videoMemory[offset + 3] = b;
}
void drawLine(GLWindow *g, int x0, int y0, int x1, int y1, uint32_t colour)
{
int d, dx, dy, aincr, bincr, xincr, yincr, x, y;
if (abs(x1 - x0) < abs(y1 - y0))
{
/* parcours par l'axe vertical */
if (y0 > y1)
{
drawLine(g, x1, y1, x0, y0, colour);
goto exit;
}
xincr = x1 > x0 ? 1 : -1;
dy = y1 - y0;
dx = abs(x1 - x0);
d = 2 * dx - dy;
aincr = 2 * (dx - dy);
bincr = 2 * dx;
x = x0;
y = y0;
drawPixel(g, x, y, colour);
for (y = y0+1; y <= y1; y++)
{
if (d >= 0)
{
x += xincr;
d += aincr;
}
else
{
d += bincr;
}
drawPixel(g, x, y, colour);
}
}
else
{
/* parcours par l'axe horizontal */
if (x0 > x1)
{
drawLine(g, x1, y1, x0, y0, colour);
goto exit;
}
yincr = y1 > y0 ? 1 : -1;
dx = x1 - x0;
dy = abs(y1 - y0);
d = 2 * dy - dx;
aincr = 2 * (dy - dx);
bincr = 2 * dy;
x = x0;
y = y0;
drawPixel(g, x, y, colour);
for (x = x0+1; x <= x1; ++x)
{
if (d >= 0)
{
y += yincr;
d += aincr;
}
else
{
d += bincr;
}
drawPixel(g, x, y, colour);
}
}
exit:
return;
}
void drawCircle(GLWindow *g, int xc, int yc, int radius, uint32_t colour)
{
int f = 1 - radius;
int ddF_x = 0;
int ddF_y = -2 * radius;
int x = 0;
int y = radius;
int pX, pY;
pX = xc; pY = yc + radius;
drawPixel(g, pX, pY, colour);
pY -= (2*radius);
drawPixel(g, pX, pY, colour);
pY += radius; pX += radius;
drawPixel(g, pX, pY, colour);
pX -= (2*radius);
drawPixel(g, pX, pY, colour);
while(x < y)
{
if(f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x + 1;
pX = xc+x ; pY = yc+y;
drawPixel(g, pX, pY, colour);
pX = xc-x ; pY = yc+y;
drawPixel(g, pX, pY, colour);
pX = xc+x ; pY = yc-y;
drawPixel(g, pX, pY, colour);
pX = xc-x ; pY = yc-y;
drawPixel(g, pX, pY, colour);
pX = xc+y ; pY = yc+x;
drawPixel(g, pX, pY, colour);
pX = xc-y ; pY = yc+x;
drawPixel(g, pX, pY, colour);
pX = xc+y ; pY = yc-x;
drawPixel(g, pX, pY, colour);
pX = xc-y ; pY = yc-x;
drawPixel(g, pX, pY, colour);
}
return;
}
void drawRect(GLWindow *g, int x0, int y0, int w, int h, uint32_t colour)
{
drawLine(g, x0 , y0 , x0 + w, y0 , colour);
drawLine(g, x0 + w, y0 , x0 + w, y0 + h, colour);
drawLine(g, x0 + w, y0 + h, x0 , y0 + h, colour);
drawLine(g, x0 , y0 + h, x0 , y0 , colour);
}
void drawFillrect(GLWindow *g, int x0, int y0, int w, int h, uint32_t colour)
{
int i;
for(i = 0; i < h; i++)
drawLine(g, x0, y0+i, x0+w, y0+i, colour);
}
void clearScreen(GLWindow *g)
{
memset(g->videoMemory, 0, sizeof(uint8_t) * g->WIDTH * g->HEIGHT * 4);
}
void updateScreen(GLWindow *g)
{
/*Update windows code */
glfwMakeContextCurrent(g->windows);
ShowScreen(g, g->WIDTH, g->HEIGHT);
glfwSwapBuffers(g->windows);
glfwPollEvents();
}
void updateScreenAndWait(GLWindow *g)
{
while (glfwGetKey(g->windows,GLFW_KEY_ESCAPE) != GLFW_PRESS)
{
updateScreen(g);
glfwPollEvents();
}
while(glfwGetKey(g->windows,GLFW_KEY_ESCAPE) != GLFW_RELEASE)
{
glfwPollEvents();
}
}
GLWindow mainWindow;
int graphics_init()
{
GLWindowInitEx(&mainWindow, 256, 240);
initDisplay(&mainWindow);
clearScreen(&mainWindow);
updateScreen(&mainWindow);
return 0;
}
static unsigned long getColour(long color)
{
Palette *pal = &basicPalette[color];
uint8_t r, g, b, a;
r = pal->r;
b = pal->b;
g = pal->g;
a = 255;//pal->a;
return (b << 24) | (g << 16) | (r << 8) | a;
}
int graphics_drawpixel(long x, long y, long color)
{
drawPixel(&mainWindow, x, y, getColour(color));
return 0;
}
int graphics_drawline(long x, long y, long x1, long y1, long color)
{
drawLine(&mainWindow, x, y, x1, y1, getColour(color));
return 0;
}
int graphics_blit(long x, long y, long w, long h)
{
updateScreen(&mainWindow);
return 0;
}
int getKeyStatus(int key)
{
return mainWindow.keyArray[key].curState;
}

61
src/os/win32/io.c Normal file
View File

@@ -0,0 +1,61 @@
/*
* IO Manager - The TI-NESulator Project
* os/macos/graphics.c
*
* Created by Manoël Trapier on 04/01/09.
* Copyright (c) 2003-2016 986-Studio. All rights reserved.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*
*/
#include <stdio.h>
#include <stdarg.h>
#include <os_dependent.h>
char LevelChar[] = { 'E', 'W', 'A', 'N', 'V', 'D'};
ConsoleLevel console_ActualLevel = Console_Default;
/* Actually nothing to do */
int console_init(ConsoleLevel DefaultLevel)
{
console_ActualLevel = DefaultLevel;
return 0;
}
/* Actually a simple printf with levels */
int console_vprintf(const ConsoleLevel level, const char *format, va_list ap)
{
if (console_ActualLevel >= level)
vprintf(format, ap);
return 0;
}
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);
va_end(ap);
return 0;
}
int console_printf_d(const char *format, ...)
{
va_list ap;
va_start(ap, format);
console_vprintf (Console_Debug, format, ap);
return 0;
}

34
src/os/win32/loadfile.c Normal file
View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2003-2016 986-Studio. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
/* Map a file in memory */
void *LoadFilePtr(char * filename)
{
int fd;
void *RetPtr = NULL;
struct stat FileStat;
fd = open(filename, O_RDONLY);
fstat(fd, &FileStat);
RetPtr = mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd);
return RetPtr;
}

0
src/os/win32/sound.c Normal file
View File

View File

@@ -3,7 +3,7 @@
* paddle.c * paddle.c
* *
* Created by Manoel TRAPIER. * Created by Manoel TRAPIER.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -12,117 +12,83 @@
* *
*/ */
/* Allegro includes */ #include <os_dependent.h>
#ifdef __APPLE__
#define USE_CONSOLE
#include <Allegro/allegro.h>
#else
#define USE_CONSOLE
#include <allegro.h>
#endif
#include "paddle.h" #include "paddle.h"
void InitPaddle(Paddle * pdl) void InitPaddle(Paddle *pdl)
{ {
pdl->Bit = 1; pdl->Bit = 1;
pdl->LastWrite = 0; pdl->LastWrite = 0;
} }
void WritePaddle(Paddle *pdl, unsigned char val) void WritePaddle(Paddle *pdl, unsigned char val)
{ {
if ((pdl->LastWrite == 1) && (val == 0)) if ( ( pdl->LastWrite == 1 ) && ( val == 0 ) )
InitPaddle(pdl); InitPaddle(pdl);
pdl->LastWrite = val; pdl->LastWrite = val;
} }
unsigned char ReadPaddle(Paddle * pdl)
unsigned char ReadPaddle(Paddle *pdl)
{ {
switch (pdl->Bit++) switch(pdl->Bit++)
{ {
case 1: case 1:
if (key[KEY_Z]) if ( getKeyStatus('O') )
return 0x41;
break;
return 0x41; case 2:
if ( getKeyStatus('P') )
return 0x41;
break;
break; case 3:
if ( getKeyStatus('I') )
return 0x41;
break;
case 2: case 4:
if ( getKeyStatus('U') )
return 0x41;
break;
if (key[KEY_X]) case 5:
if ( getKeyStatus('W') )
return 0x41;
break;
return 0x41; case 6:
if ( getKeyStatus('S') )
return 0x41;
break;
break; case 7:
if ( getKeyStatus('A') )
return 0x41;
break;
case 3: case 8:
if ( getKeyStatus('D') )
return 0x41;
break;
if (key[KEY_P]) case 20:
return 0x40;
break;
return 0x41; case 24:
pdl->Bit = 1;
return 0x40;
break; default:
return 0x40;
break;
case 4: }
if (key[KEY_ENTER])
return 0x41;
break;
case 5:
if (key[KEY_UP])
return 0x41;
break;
case 6:
if (key[KEY_DOWN])
return 0x41;
break;
case 7:
if (key[KEY_LEFT])
return 0x41;
break;
case 8:
if (key[KEY_RIGHT])
return 0x41;
break;
case 20:
return 0x40;
break;
case 24:
pdl->Bit = 1;
return 0x40;
default:
return 0x40;
break;
}
return 0x40; return 0x40;
} }

View File

@@ -2,7 +2,7 @@
# TI-NES CMake # TI-NES CMake
# #
# Created by Manoel TRAPIER. # Created by Manoel TRAPIER.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2003-2016 986-Studio. All rights reserved.
# #
# $LastChangedDate$ # $LastChangedDate$
# $Author$ # $Author$
@@ -10,4 +10,9 @@
# $Revision$ # $Revision$
file(GLOB plugins_list plugins/*.c) file(GLOB plugins_list plugins/*.c)
if (COVERALLS)
set(COVERAGE_SRCS src/pluginsmanager/manager.c ${COVERAGE_SRCS} PARENT_SCOPE)
endif()
add_library(pluginsmanager manager.c ${plugins_list}) add_library(pluginsmanager manager.c ${plugins_list})

View File

@@ -3,7 +3,7 @@
* plugins.c * plugins.c
* *
* Created by Manoel TRAPIER on 02/04/07. * Created by Manoel TRAPIER on 02/04/07.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* gamegenie.c: Hack your games with unlimited lives of add new powers! * gamegenie.c: Hack your games with unlimited lives of add new powers!
* *
* Created by Manoel Trapier. * Created by Manoel Trapier.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -24,6 +24,7 @@
#include <memory/manager.h> #include <memory/manager.h>
#include <types.h> #include <types.h>
#if 0
/* Allegro includes */ /* Allegro includes */
#ifdef __APPLE__ #ifdef __APPLE__
#define USE_CONSOLE #define USE_CONSOLE
@@ -824,3 +825,4 @@ int gg_Deinit()
{ {
return 0; return 0;
} }
#endif

View File

@@ -3,7 +3,7 @@
* gamegenie.h * gamegenie.h
* *
* Created by Manoel Trapier. * Created by Manoel Trapier.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$

View File

@@ -3,7 +3,7 @@
* plugins_list.h * plugins_list.h
* *
* Created by Manoel Trapier. * Created by Manoel Trapier.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$
@@ -17,7 +17,7 @@
#include "plugins/gamegenie.h" #include "plugins/gamegenie.h"
Plugin Plugins[] = { Plugin Plugins[] = {
{ "Game Genie", gg_Init, gg_Deinit }, // { "Game Genie", gg_Init, gg_Deinit },
/* EOL tag */ /* EOL tag */
{ NULL, NULL, NULL } { NULL, NULL, NULL }

View File

@@ -10,4 +10,10 @@
# $Revision$ # $Revision$
file(GLOB ppu_debug_list debug/*.c) file(GLOB ppu_debug_list debug/*.c)
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}) add_library(ppu ppu.c ppu.memory.c ${ppu_debug_list})

View File

@@ -15,6 +15,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#if 0
/* Allegro includes */ /* Allegro includes */
#ifdef __APPLE__ #ifdef __APPLE__
#define USE_CONSOLE #define USE_CONSOLE
@@ -355,8 +356,8 @@ void ppu_dumpPalette(int x, int y)
{ {
int i; int i;
textout(Buffer, font, "Bg Palette", x , y, 5); textout_ex(Buffer, font, "Bg Palette", x , y, 5, 0);
textout(Buffer, font, "Sprt Palette", x + 90, y, 5); textout_ex(Buffer, font, "Sprt Palette", x + 90, y, 5, 0);
rect(Buffer, x+0, y+20, x+4 * 20 + 2, y + 4 * 20 + 22, 0); rect(Buffer, x+0, y+20, x+4 * 20 + 2, y + 4 * 20 + 22, 0);
rect(Buffer, x+90, y+20, x+90 + 4 * 20 + 2, y + 4 * 20 + 22, 0); rect(Buffer, x+90, y+20, x+90 + 4 * 20 + 2, y + 4 * 20 + 22, 0);
@@ -367,3 +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)); 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

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
* ppu.memory.c - Inspired from the memory manager of the Quick6502 Project. * ppu.memory.c - Inspired from the memory manager of the Quick6502 Project.
* *
* Created by Manoel Trapier on 12/04/07. * Created by Manoel Trapier on 12/04/07.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2003-2016 986-Studio. All rights reserved.
* *
* $LastChangedDate$ * $LastChangedDate$
* $Author$ * $Author$