Compare commits

..

41 Commits

Author SHA1 Message Date
Godzil
37589c72ef Do not enable -Werror by default. GCC is a pain constantly changing warnings 2021-04-18 15:17:13 +01:00
Godzil
8e62b1c934 Update travis config. Should no longer fail now 2021-04-18 15:07:55 +01:00
Godzil
4280979f87 Fix warnings/errors spotted by travis 2020-01-17 18:13:06 +00:00
Godzil
2ec7a9c21e Working on plugin to make them work again! 2020-01-14 18:59:22 +00:00
Godzil
221417c0ee Temporary palette fix 2019-12-06 12:34:20 +00:00
Godzil
1d6afc5473 Fix a 17 year old bug: paddle were not properly handled, funny I never got issues before Twin Dragons with that!
Though Twin Dragon way of writing to 4016 is nasty! ;P
2019-12-06 12:34:11 +00:00
Godzil
d37ad746b1 Temporary fix for the coverall/dummy run. 2019-12-05 16:56:31 +00:00
Manoël Trapier
c7c0f708d8
Update README.md 2019-12-05 16:45:12 +00:00
Godzil
8fcf756566 Update headers
- Update copyrights dates
- Remove the useless "All right reserved"
- Change incorrect name(s)
2019-12-05 16:42:11 +00:00
Godzil
cd00346978 Remove useless files. 2019-12-05 16:35:56 +00:00
Godzil
9fb3a09f05 Remove all the complicated (even if working) stuff to use vsync instead to sync NTSC at 60Hz! 2019-12-05 16:17:09 +00:00
Godzil
b44faef4ac Update .gitignore 2019-12-05 16:15:11 +00:00
Godzil
55a82312c4 RB Update 2019-12-05 16:14:10 +00:00
Godzil
46683a86f6 Update win32 files
(they are not working version, but at least they are not complaining either)
2018-02-03 12:07:20 +00:00
Godzil
cdda587579 [Cosmetics]
- Update some headers that was incorrect
- Reformat the code in all files to match the same code style
- Removal of unwanted/unneeded files
2018-02-02 17:43:15 +00:00
Godzil
ad195d6c20 Use more modern types for fixed size variables. 2018-02-01 19:04:46 +00:00
Godzil
a3d67a4de3 Remove unneeded debug print 2018-02-01 18:45:10 +00:00
Godzil
1e13490c36 Add proper support for UNROM512 32K CHR-RAM 2018-02-01 18:20:16 +00:00
Godzil
c1d8e858aa More python update 2018-02-01 16:47:17 +00:00
Godzil
ac50dea14b Disabling sonarcloud. 2018-02-01 15:59:11 +00:00
Godzil
97fa1cc4d1 Last test before disabling. 2018-02-01 15:56:11 +00:00
Godzil
621cac64e3 Maybe token setting is invalid? 2018-02-01 15:43:02 +00:00
Godzil
ef1ff8deb9 Makes the Python script more pythonic (3) 2018-02-01 15:32:26 +00:00
Godzil
8f51c4712c Try to run sonarqube/sonarcloud in travis... 2018-02-01 15:07:25 +00:00
Godzil
223b0080c8 Now make OSX failure treated as failure.
Also add troll burner as part of coverage test.
2018-02-01 12:41:00 +00:00
Godzil
1d20c0ab11 Change how coverage is done to be more deterministic than just running for a given time. 2018-02-01 12:21:18 +00:00
Godzil
fd980059f1 Remove all sound related code from main.c 2018-01-31 18:49:49 +00:00
Godzil
b178988fbe Remove all useless old SVN tag 2018-01-31 18:49:28 +00:00
Godzil
4a1af785c9 On other error spotted by codacy. 2018-01-31 18:45:48 +00:00
Godzil
f6d0c8d93a Remove old buggy sound code, and start a fresh new APU module. (empty for now) 2018-01-31 18:45:22 +00:00
Godzil
e837f43f86 Silence some codacy errors. 2018-01-31 18:32:22 +00:00
Godzil
7e1afab7e3 Remove old backup of PPU code. 2018-01-31 18:05:54 +00:00
Manoël Trapier
28dbaa8d08
Update README.md 2018-01-31 17:51:00 +00:00
Godzil
4bab10621f Correct some potential errors. 2018-01-31 17:46:02 +00:00
Godzil
cc291907c2 Rename project from TI-NESulator to peTI-NESulator
And update all headers accordingly
2018-01-31 15:13:45 +00:00
Godzil
c3e9d57379 Make OSX build work again (Stupid GL_* things...) 2018-01-31 10:35:59 +00:00
Godzil
cfe0099595 Adding PortAudio for audio backend.
Well that just the beginning!
2018-01-30 19:05:50 +00:00
Godzil
e96f36b6de Remove Marat Fayzullin 6502 emulation code 2018-01-30 17:29:26 +00:00
Godzil
12663ba99a Correct some invalid prototypes. 2018-01-30 17:27:22 +00:00
Godzil
9673b4694b Bump header copyright to -2018 2018-01-30 16:41:14 +00:00
Godzil
cd3d4bfc47 Get version from git tags 2018-01-30 16:40:35 +00:00
110 changed files with 5776 additions and 16151 deletions

5
.gitignore vendored
View File

@ -1,5 +1,10 @@
#Temp files #Temp files
/build* /build*
cmake-*/
sonar/
.idea/
.scannerwork/
venv/
*~ *~
*.swp *.swp

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[submodule "external/coveralls-cmake"] [submodule "external/coveralls-cmake"]
path = external/coveralls-cmake path = external/coveralls-cmake
url = https://github.com/JoakimSoderberg/coveralls-cmake.git url = https://github.com/JoakimSoderberg/coveralls-cmake.git
[submodule "external/portaudio"]
path = external/portaudio
url = https://git.assembla.com/portaudio.git

View File

@ -1,10 +1,4 @@
language: c language: c
os:
- linux
- osx
matrix:
allow_failures:
- os: osx
addons: addons:
apt: apt:
@ -14,27 +8,75 @@ addons:
- xorg-dev - xorg-dev
- libglu1-mesa-dev - libglu1-mesa-dev
compiler:
- clang
- gcc
script: script:
- mkdir build - mkdir build
- cd build - cd build
- cmake -DUSE_ALLEGRO=OFF -DUSE_PROFILING=OFF -DCOVERALLS=OFF -DCMAKE_BUILD_TYPE=Release .. - cmake -DUSE_ALLEGRO=OFF -DUSE_PROFILING=OFF -DCOVERALLS=OFF -DCMAKE_BUILD_TYPE=Release ..
- cmake --build . - 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: before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install glew; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install glew; fi
install: true jobs:
include:
- os: linux
dist: bionic
arch: amd64
compiler: gcc
after_success: - os: linux
- bash <(curl -s https://codecov.io/bash) dist: bionic
arch: amd64
compiler: clang
- os: linux
dist: focal
arch: amd64
compiler: gcc
- os: linux
dist: focal
arch: amd64
compiler: clang
- os: osx
compiler: clang
osx_image: xcode12.2
- os: linux
dist: focal
arch: arm64
compiler: gcc
- os: osx
compiler: clang
osx_image: xcode10.3
- os: osx
compiler: clang
osx_image: xcode11.6
- os: osx
compiler: clang
osx_image: xcode12
- stage: "Coverage"
os: linux
dist: bionic
arch: amd64
compiler: gcc
script:
- mkdir coverage
- cd coverage
- cmake -DUSE_ALLEGRO=OFF -DUSE_PROFILING=OFF -DCOVERALLS=ON -DCMAKE_BUILD_TYPE=Debug ..
- cmake --build .
- cmake --build . --target coveralls
after_success:
- bash <(curl -s https://codecov.io/bash)
allow_failures:
- os: linux
arch: arm64
- os: osx

View File

@ -1,18 +1,17 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoel TRAPIER.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
cmake_minimum_required (VERSION 2.8) cmake_minimum_required (VERSION 2.8)
project (TINES) project (peTI-NESulator)
# External cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/cmake ${CMAKE_MODULE_PATH})
# Include GLFW
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
@ -21,8 +20,29 @@ find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR}) include_directories(${OPENGL_INCLUDE_DIR})
# Include PortAudio
set(PA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(PA_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(PA_ENABLE_DEBUG_OUTPUT OFF CACHE BOOL "" FORCE)
add_subdirectory("external/portaudio")
if (COVERALLS) if (COVERALLS)
enable_testing() enable_testing()
endif (COVERALLS) endif (COVERALLS)
# Generate version from Git Tag
include(GetGitRevisionDescription)
git_describe(VERSION --tags --dirty=-dirty)
#parse the version information into pieces.
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_MICRO "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
message("-- Building version ${VERSION}")
add_compile_options(-DV_MAJOR=${VERSION_MAJOR})
add_compile_options(-DV_MINOR=${VERSION_MINOR})
add_compile_options(-DV_MICRO=${VERSION_MICRO})
add_compile_options(-DV_TEXT="${VERSION_SHA1}")
add_subdirectory (src) add_subdirectory (src)

11
LICENSE Normal file
View File

@ -0,0 +1,11 @@
Copyright (c) 2002-2019 986-Studio / Manoel <godzil> Trapier
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,21 +1,15 @@
TI-NESulator peTI-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) [![Coverage Status](https://coveralls.io/repos/github/Godzil/peTI-NESulator/badge.svg?branch=master)](https://coveralls.io/github/Godzil/peTI-NESulator?branch=master) [![codecov](https://codecov.io/gh/Godzil/peTI-NESulator/branch/master/graph/badge.svg)](https://codecov.io/gh/Godzil/peTI-NESulator) [![travis](https://travis-ci.org/Godzil/peTI-NESulator.svg?branch=master)](https://travis-ci.org/Godzil/peTI-NESulator) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a0671ed2065249f0825c91a57e883dbe)](https://www.codacy.com/app/Godzil/peTI-NESulator?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Godzil/peTI-NESulator&amp;utm_campaign=Badge_Grade)
This is a cleaned version of the TI-NESulator repository (all non free data has been removed) This is a cleaned version of the peTI-NESulator repository (all non free data has been removed)
Some part of the original subversion has been lost because of harddrive crash so the 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 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 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. 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 This software is released under a three clauses BSD.
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.
If you plan to use that project in your projects, I would be glad if you could just send me a message, I love to know where my work is used!

View File

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

View File

@ -1,67 +1,67 @@
<------------------------------------------------------------------------------> <------------------------------------------------------------------------------>
TI-NESulator peTI-NESulator
Version 0.30.2 beta Version 0.30.2 beta
Par Manoel TRAPIER aka Godzil Par Manoel TRAPIER aka Godzil
godzil at godzil point net petines at godzil point net
1 -> #include <disclamer.h> 1 -> #include <disclamer.h>
L'utilisation de se logiciel se fait a vos risque et pŽrils. Il s'agit d'une L'utilisation de se logiciel se fait a vos risque et p<EFBFBD>rils. Il s'agit d'une
pars d'une version non terminŽe, et en cours de dŽvellopement, et la diffusion pars d'une version non termin<EFBFBD>e, et en cours de d<>vellopement, et la diffusion
n'a ŽtŽ faite que pour permettre le teste, et la dŽmonstration de se que sera le n'a <EFBFBD>t<EFBFBD> faite que pour permettre le teste, et la d<>monstration de se que sera le
logiciel final. logiciel final.
Je ne peut donc <20>tre tenu pour responsable en cas de probl<62>me liŽ ˆ Je ne peut donc <20>tre tenu pour responsable en cas de probl<62>me li<EFBFBD> <20>
l'utilisation ou posession de se logiciel. l'utilisation ou posession de se logiciel.
Vous <20>tes libre de l'utiliser ˆ partir du moment au se logiciel n'a pas ŽtŽ Vous <20>tes libre de l'utiliser <EFBFBD> partir du moment au se logiciel n'a pas <20>t<EFBFBD>
modifiŽ que sa soit de mani<6E>re binaire, ou par dŽsassemblage. Si vous trouver modifi<EFBFBD> que sa soit de mani<6E>re binaire, ou par d<>sassemblage. Si vous trouver
une version modifiŽ ou fourni avec des fichiers illŽgaux, veuillez me le faire une version modifi<EFBFBD> ou fourni avec des fichiers ill<6C>gaux, veuillez me le faire
savoir. Vous trouverez comment me contacter dans la suite de se fichier. savoir. Vous trouverez comment me contacter dans la suite de se fichier.
Vous <20>tes libre aussi de le distribuer tant que les fichiers contenus dans le Vous <20>tes libre aussi de le distribuer tant que les fichiers contenus dans le
paquetage original sont laissŽ intouchŽ. paquetage original sont laiss<EFBFBD> intouch<63>.
Information lŽgales : Information l<EFBFBD>gales :
NES, Famicon, Nintendo Entertainment System, Nintendo sont des marques dŽposŽ de NES, Famicon, Nintendo Entertainment System, Nintendo sont des marques d<EFBFBD>pos<EFBFBD> de
Nintendo France, Nintendo of america et Nintendo Company, Ltd. Nintendo France, Nintendo of america et Nintendo Company, Ltd.
Tout les titres et marques apparaisant dans se fichier texte sont la propriŽtŽ Tout les titres et marques apparaisant dans se fichier texte sont la propri<EFBFBD>t<EFBFBD>
de leurs auteurs respectifs. de leurs auteurs respectifs.
N'oubliez pas aussi que la posession de ROM (Fichier binaire reprŽsentant le N'oubliez pas aussi que la posession de ROM (Fichier binaire repr<EFBFBD>sentant le
contenue d'une cartouche) sans en posseder l'originale (la cartouche) est contenue d'une cartouche) sans en posseder l'originale (la cartouche) est
absolument illŽgale, que vous la gardiez 24 heures ou seulement 30 secondes absolument ill<EFBFBD>gale, que vous la gardiez 24 heures ou seulement 30 secondes
2 -> Qu'est-ce que TI-NESulator ? 2 -> Qu'est-ce que peTI-NESulator ?
TI-NESulator est un Žmulateur de la console Nintendo Entertainment System peTI-NESulator est un <20>mulateur de la console Nintendo Entertainment System
(connunŽment appelŽ NES) fabriquŽ par Nintendo au milieu des annŽe 80. (connun<EFBFBD>ment appel<65> NES) fabriqu<71> par Nintendo au milieu des ann<6E>e 80.
L'originalitŽ de cet emulateur est que sa plateforme de fonctionnement principal L'originalit<EFBFBD> de cet emulateur est que sa plateforme de fonctionnement principal
est les calculatrices TI-89 et TI-92+ de chez Texas Instrument. Ses est les calculatrices TI-89 et TI-92+ de chez Texas Instrument. Ses
calculatrices on la particularitŽ de posseder un microprocesseur 68000 de chez calculatrices on la particularit<EFBFBD> de posseder un microprocesseur 68000 de chez
motorola, qui est pour se genre de plateforme relativement puissant et motorola, qui est pour se genre de plateforme relativement puissant et
programmer un emulateur, meme de NES, sur ses machine est un vŽritable dŽfit programmer un emulateur, meme de NES, sur ses machine est un v<EFBFBD>ritable d<>fit
tant au niveau matŽriel que mŽmoire, la NES et les TI-68k sont completements tant au niveau mat<EFBFBD>riel que m<>moire, la NES et les TI-68k sont completements
diffŽrents. diff<EFBFBD>rents.
La NES utilise une version lŽgŽrement personalisŽ du microprocesseur 6502 La NES utilise une version l<EFBFBD>g<EFBFBD>rement personalis<69> du microprocesseur 6502
fonctionnant ˆ environ 1.7Mhz. fonctionnant <EFBFBD> environ 1.7Mhz.
Vous avez actuellement une version spŽciale (comprendre pas faite pour Vous avez actuellement une version sp<EFBFBD>ciale (comprendre pas faite pour
calculatrices TI.) Cette version ne me sert qu'a mettre en oeuvre de nouvelles calculatrices TI.) Cette version ne me sert qu'a mettre en oeuvre de nouvelles
choses dans la version TI de l'Žmulateur (notemment a cause d'un gros manque choses dans la version TI de l'<EFBFBD>mulateur (notemment a cause d'un gros manque
de debuggueur C dans le monde TI.) de debuggueur C dans le monde TI.)
Cette version est et sera toujours plus avancŽ que la version TI dans le sens ou Cette version est et sera toujours plus avanc<EFBFBD> que la version TI dans le sens ou
elle me sert a expŽrimenter les nouveaux hardware ŽmulŽ et a finaliser le elle me sert a exp<EFBFBD>rimenter les nouveaux hardware <20>mul<75> et a finaliser le
hardware deja emuler. Une fois fonctionnant d'un maniere convenable sur le hardware deja emuler. Une fois fonctionnant d'un maniere convenable sur le
portage Windows, les mises a jours sont faites dans la version TI. Mais la portage Windows, les mises a jours sont faites dans la version TI. Mais la
version Windows au final contiendra plus de fonctionnalitŽ que la version TI version Windows au final contiendra plus de fonctionnalit<EFBFBD> que la version TI
(support des palletes, de la couleur, voir meme le son etc...) (support des palletes, de la couleur, voir meme le son etc...)
3 -> Utilisation de TI-NESulator 3 -> Utilisation de peTI-NESulator
[A faire.] [A faire.]
@ -85,7 +85,7 @@ SELECT P
-------------------------- --------------------------
Autres touches : Autres touches :
R identique ˆ l'apuis du bouton Reset de la console R identique <EFBFBD> l'apuis du bouton Reset de la console
1-2 A un effet, mais vous risque de pas le voir ;) 1-2 A un effet, mais vous risque de pas le voir ;)
@ -96,91 +96,91 @@ R identique
-------------------------- --------------------------
Il faut noter aussi qu'afficher ces tables ralentisent considŽrablement la Il faut noter aussi qu'afficher ces tables ralentisent consid<EFBFBD>rablement la
vitesse de l'Žmulateur vitesse de l'<EFBFBD>mulateur
4 -> CompatibilitŽ 4 -> Compatibilit<EFBFBD>
TI-NESulator version Win32 est normalement compatible avec tous les Windows peTI-NESulator version Win32 est normalement compatible avec tous les Windows
(95, 98,Me, NT 4, 2000, XP) (95, 98,Me, NT 4, 2000, XP)
TI-NESulator version .X (MacOS X) est normalement compatible toutes version peTI-NESulator version .X (MacOS X) est normalement compatible toutes version
de OS X (.1.x .2.x .3.x) de OS X (.1.x .2.x .3.x)
L'Žmulateur Žmule actuellement avec les mappers : L'<EFBFBD>mulateur <20>mule actuellement avec les mappers :
- 0 aucun mapper (Super Mario Bros 1, Donkey Kong, ...) - 0 aucun mapper (Super Mario Bros 1, Donkey Kong, ...)
- 1 MMC1 (a 99%, Megaman 2, Zelda1 & 2, Final Fantasy 1, ...) - 1 MMC1 (a 99%, Megaman 2, Zelda1 & 2, Final Fantasy 1, ...)
- 2 UNROM (MegaMan, Final fantasy 2, ...) - 2 UNROM (MegaMan, Final fantasy 2, ...)
- 3 CNROM - 3 CNROM
- 4 MMC3 (Super mario Bross 2 & 3, MegaMan 3 ˆ 6, ...) - 4 MMC3 (Super mario Bross 2 & 3, MegaMan 3 <EFBFBD> 6, ...)
- 7 AOROM (Battletoad, ...) - 7 AOROM (Battletoad, ...)
Les mappers marquŽ comme *NOUVEAU* sont ceux qui on ŽtŽ ajoutŽ dans la derniere Les mappers marqu<EFBFBD> comme *NOUVEAU* sont ceux qui on <20>t<EFBFBD> ajout<75> dans la derniere
version disponible. Merci de faire un rapport dŽtaillŽ si vous rencontrer des version disponible. Merci de faire un rapport d<EFBFBD>taill<EFBFBD> si vous rencontrer des
probl<EFBFBD>mes avec. probl<EFBFBD>mes avec.
5 -> Question RŽponses 5 -> Question R<EFBFBD>ponses
Q: Pourquoi le jeu xxx ne fonctionne pas ? Q: Pourquoi le jeu xxx ne fonctionne pas ?
R: TI-NESulator est actuellement en cours de dŽvellopement. Beaucoup de jeux ne R: peTI-NESulator est actuellement en cours de d<>vellopement. Beaucoup de jeux ne
sont pas supportŽ. sont pas support<EFBFBD>.
Q: Vous dites que certain de jeux ne sont pas supportŽ, mais si j'essaye xxx, il Q: Vous dites que certain de jeux ne sont pas support<EFBFBD>, mais si j'essaye xxx, il
marche ! Pourquoi ? marche ! Pourquoi ?
R: Ceci est du a une des particularitŽ du Hardware de la NES/Famicon. Le R: Ceci est du a une des particularit<EFBFBD> du Hardware de la NES/Famicon. Le
hardware de base de la console est assŽ limitŽ, et la mŽmoire est aussi tres hardware de base de la console est ass<EFBFBD> limit<69>, et la m<>moire est aussi tres
limitŽ. pour palier ˆ ses limitations, certains jeux utilise ce qu'on appele des limit<EFBFBD>. pour palier <20> ses limitations, certains jeux utilise ce qu'on appele des
Mappers, qui permettent notemment d'avoir des jeux plus gros, et qui sont Mappers, qui permettent notemment d'avoir des jeux plus gros, et qui sont
implŽmentŽ dans la cartouche du jeu. Malheureusement supporter tout ses mappers impl<EFBFBD>ment<EFBFBD> dans la cartouche du jeu. Malheureusement supporter tout ses mappers
font grossir l'emulateur, et certain on un fonctionnement qui est font grossir l'emulateur, et certain on un fonctionnement qui est
malheureusement encore inconnu. N'oubliez pas non plus que TI-NESulator est malheureusement encore inconnu. N'oubliez pas non plus que peTI-NESulator est
encore en dŽvellopement. Certain mapper connu ne sont pas encore implŽmentŽ. encore en d<EFBFBD>vellopement. Certain mapper connu ne sont pas encore impl<70>ment<6E>.
Q: Oui puis-je trouver le jeux xxxx ? Q: Oui puis-je trouver le jeux xxxx ?
R: DŽsolŽ, je ne donne aucun lien menant, ni aucune ROM de jeux commerciaux. R: D<EFBFBD>sol<EFBFBD>, je ne donne aucun lien menant, ni aucune ROM de jeux commerciaux.
N'oubliez pas que les personnes vous disant que vous avez le droit de ne garder N'oubliez pas que les personnes vous disant que vous avez le droit de ne garder
que 24h une ROM, vous raconte absolument n'importe quoi. Il est absolument que 24h une ROM, vous raconte absolument n'importe quoi. Il est absolument
*ILLEGAL* de posseder la ROM d'un jeu que vous ne possedez pas officiellement. *ILLEGAL* de posseder la ROM d'un jeu que vous ne possedez pas officiellement.
Q: XXX donne l'air de fonctionner, pourtant il ne reagis pas au touches Q: XXX donne l'air de fonctionner, pourtant il ne reagis pas au touches
R: Cet emulateur n'est pas parfait. Certain jeux/demo demandent un R: Cet emulateur n'est pas parfait. Certain jeux/demo demandent un
fonctionnement tres proche de celui de la console originale, ce que TI-NESulator fonctionnement tres proche de celui de la console originale, ce que peTI-NESulator
est encore loin d'arriver a faire. est encore loin d'arriver a faire.
Q: J'ai des probl<62>mes graphiques avec XXXX Q: J'ai des probl<62>mes graphiques avec XXXX
R: Cf rŽponse-ci dessus R: Cf r<EFBFBD>ponse-ci dessus
Q: C'est lent :( Q: C'est lent :(
R: DŽsolŽ. Le code est toujours en cours de devellopement. Si vous trouvez trop R: D<EFBFBD>sol<EFBFBD>. Le code est toujours en cours de devellopement. Si vous trouvez trop
lent, attendez la prochaine version une surprise vous y attendra peut-etre ! lent, attendez la prochaine version une surprise vous y attendra peut-etre !
7 -> En cas de probl<62>me 7 -> En cas de probl<62>me
a) Un jeu indiquŽ compatible ne fonctionne pas (ie "Mapper non supportŽ") a) Un jeu indiqu<EFBFBD> compatible ne fonctionne pas (ie "Mapper non support<72>")
Alors plusieurs possibilitŽ, soit vous avez une autre version du jeu officielle Alors plusieurs possibilit<EFBFBD>, soit vous avez une autre version du jeu officielle
ou non, cela peut changer par exemple le mapper utilisŽ par le jeux, soit vous ou non, cela peut changer par exemple le mapper utilis<EFBFBD> par le jeux, soit vous
avez recuperer un "bad dump", c'est a dire plus simplement une rom foireuse. avez recuperer un "bad dump", c'est a dire plus simplement une rom foireuse.
Dans ces deux cas essayez d'en recuperer une autre version. Dans ces deux cas essayez d'en recuperer une autre version.
b) TI-NESulator ˆ plantŽ !! b) peTI-NESulator <20> plant<6E> !!
Si cela arrive regulierement pour le meme jeu et au meme endroit faites moi un Si cela arrive regulierement pour le meme jeu et au meme endroit faites moi un
crash report avec les information que TI-NESulator vous met dans la console crash report avec les information que peTI-NESulator vous met dans la console
(pour pouvoir la copier tranquillement il faut lancer a partir d'une console (pour pouvoir la copier tranquillement il faut lancer a partir d'une console
et pas faire glisser la rom sur l'executable) et pas faire glisser la rom sur l'executable)
N'oubliez pas de prŽciser le nom complet du jeu, la taille du fichier et toutes N'oubliez pas de pr<EFBFBD>ciser le nom complet du jeu, la taille du fichier et toutes
les infos que vous trouverez pertinante (manipulation a faire etc...) les infos que vous trouverez pertinante (manipulation a faire etc...)
8 -> Remerciement 8 -> Remerciement
Loopy, Y0Shi, Marrat Fayzullin, et bcp d'autre pour la documentation technique Loopy, Y0Shi, Marrat Fayzullin, et bcp d'autre pour la documentation technique
sur la NES sur la NES
Ainsi que tout ceux que j'ai pu oublier Ainsi que tout ceux que j'ai pu oublier
9 -> LitŽrature 9 -> Lit<EFBFBD>rature
[A faire.] [A faire.]
@ -196,8 +196,8 @@ Vous pouvez me contacter grace au forum yAronet: http://www.yaronet.com
Et surtout grace au lien suivant : http://www.yaronet.com/posts.php?sl=&s=2339 Et surtout grace au lien suivant : http://www.yaronet.com/posts.php?sl=&s=2339
Vous pouvez aussi me joindre par mail en m'Žcrivant ˆ Vous pouvez aussi me joindre par mail en m'<EFBFBD>crivant <20>
"godzil chez godzil point net" "petines chez godzil point net"
Vous pouvez aussi essayer de visiter mon site : http://www.godzil.net Vous pouvez aussi essayer de visiter mon site : http://www.godzil.net
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -1,5 +1,5 @@
25/02/2008 25/02/2008
- Finish th Quick6502 C project to merge it into TI-NESulator [ ] - Finish th Quick6502 C project to merge it into peTI-NESulator [ ]
- Extract graphic primitive to be less dependent of Allegro [ ] - Extract graphic primitive to be less dependent of Allegro [ ]
- Rewrite sound engine [ ] - Rewrite sound engine [ ]

View File

@ -0,0 +1,168 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# git_local_changes(<var>)
#
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
# Uses the return code of "git diff-index --quiet HEAD --".
# Does not regard untracked files.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)
# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()
if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()
function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()
# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()
#message(STATUS "Arguments to execute_process: ${ARGN}")
execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
#${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(git_local_changes _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()
execute_process(COMMAND
"${GIT_EXECUTABLE}"
diff-index --quiet HEAD --
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(res EQUAL 0)
set(${_var} "CLEAN" PARENT_SCOPE)
else()
set(${_var} "DIRTY" PARENT_SCOPE)
endif()
endfunction()

View File

@ -0,0 +1,41 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
set(HEAD_HASH)
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
else()
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()
if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()

1
external/portaudio vendored Submodule

@ -0,0 +1 @@
Subproject commit 1bdcb9e41357ec76d8cf73f9ef278202a3ea1e3b

6
sonar-project.properties Normal file
View File

@ -0,0 +1,6 @@
sonar.projectKey=peTI-NESulator
sonar.projectName=peTI-NESulator
sonar.projectVersion=git-edition
sonar.sources=src
sonar.cfamily.build-wrapper-output=sonar/bw-output

View File

@ -1,14 +1,9 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2016 986-Studio. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
########################## ##########################
# Configurations variables # Configurations variables
########################## ##########################
@ -24,50 +19,59 @@ set(USE_ALLEGRO ON CACHE BOOL "Use Allegro backend")
option(COVERALLS "Generate coveralls data" OFF) option(COVERALLS "Generate coveralls data" OFF)
option(WARN_AS_ERROR "Enable warning as error" OFF)
########################## ##########################
# Link & Compile flags # Link & Compile flags
########################## ##########################
set (CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Werror ${PLATFORM_FLAGS}") set(COMP_FLAGS "-march=native -Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-write-strings ${PLATFORM_FLAGS}")
set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-unused-result -Werror ${PLATFORM_FLAGS}") if (WARN_AS_ERROR)
set(COMP_FLAGS "${COMP_FLAGS} -Werror")
endif()
set(CMAKE_C_FLAGS ${COMP_FLAGS})
set(CMAKE_CXX_FLAGS ${COMP_FLAGS})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/external/coveralls-cmake/cmake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/external/coveralls-cmake/cmake)
add_definitions (-DNO_DECIMAL) add_executable(petines main.c paddle.c NESCarts.c)
add_definitions(-DNO_DECIMAL)
if (PPU_ISPAL) if (PPU_ISPAL)
add_definitions (-DISPAL) add_definitions(-DISPAL)
else (PPU_ISPAL) else (PPU_ISPAL)
add_definitions (-DISNTSC) add_definitions(-DISNTSC)
endif (PPU_ISPAL) endif (PPU_ISPAL)
if (Q6502_DEBUGGER) if (Q6502_DEBUGGER)
add_definitions (-DDEBUG) add_definitions(-DDEBUG)
endif (Q6502_DEBUGGER) endif (Q6502_DEBUGGER)
if (USE_SOUND) if (USE_SOUND)
add_definitions (-DUSE_SOUND) add_definitions(-DUSE_SOUND)
endif (USE_SOUND) endif (USE_SOUND)
if (DETECT_BUS_CONFLICT) if (DETECT_BUS_CONFLICT)
add_definitions (-DDETECT_BUS_CONFLICT) add_definitions(-DDETECT_BUS_CONFLICT)
endif (DETECT_BUS_CONFLICT) endif (DETECT_BUS_CONFLICT)
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)
else(CMAKE_BUILD_TYPE MATCHES Rel) else (CMAKE_BUILD_TYPE MATCHES Rel)
SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Debug info is forced" FORCE) SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Debug info is forced" FORCE)
endif(CMAKE_BUILD_TYPE MATCHES Rel) endif (CMAKE_BUILD_TYPE MATCHES Rel)
set(CMAKE_C_FLAGS -pg) set(CMAKE_C_FLAGS -pg)
endif (USE_PROFILING) endif (USE_PROFILING)
if (COVERALLS) if (COVERALLS)
add_definitions (-DRUN_COVERAGE) add_definitions(-DRUN_COVERAGE)
include(Coveralls) include(Coveralls)
coveralls_turn_on_coverage() coveralls_turn_on_coverage()
endif() endif ()
include_directories(include) include_directories(include)
@ -80,27 +84,26 @@ add_subdirectory(ppu)
if (TARGET_TI68k) if (TARGET_TI68k)
add_subdirectory(os/ti68k) add_subdirectory(os/ti68k)
elseif (WIN32) elseif (WIN32)
add_subdirectory(os/win32) add_subdirectory(os/win32)
else (TARGET_TI68k) else (TARGET_TI68k)
add_subdirectory(os/unix) add_subdirectory(os/unix)
endif (TARGET_TI68k) endif (TARGET_TI68k)
find_library(PTHREADLIB pthread) #find_library(PTHREADLIB pthread)
if (COVERALLS) if (COVERALLS)
set(COVERAGE_SRCS src/main.c src/paddle.c src/NESCarts.c ${COVERAGE_SRCS}) set(COVERAGE_SRCS src/main.c src/paddle.c src/NESCarts.c ${COVERAGE_SRCS})
# Create the coveralls target. # Create the coveralls target.
coveralls_setup( coveralls_setup(
"${COVERAGE_SRCS}" # The source files. "${COVERAGE_SRCS}" # The source files.
ON # If we should upload. ON # If we should upload.
) # (Optional) Alternate project cmake module path. ) # (Optional) Alternate project cmake module path.
endif() endif ()
target_link_libraries(petines apu corecpu mappermanager memorymanager pluginsmanager ppu oslib)# ${PTHREADLIB})
add_executable(tines main.c paddle.c NESCarts.c) add_test(NAME petines_test_1 COMMAND $<TARGET_FILE:petines> ${PROJECT_SOURCE_DIR}/data/bad_apple_2.nes)
target_link_libraries(tines apu corecpu mappermanager memorymanager pluginsmanager ppu oslib ${PTHREADLIB}) add_test(NAME petines_test_2 COMMAND $<TARGET_FILE:petines> ${PROJECT_SOURCE_DIR}/data/trollburner_demo.nes)
add_test(NAME tines_test COMMAND $<TARGET_FILE:tines> ${PROJECT_SOURCE_DIR}/data/bad_apple_2.nes)

View File

@ -1,19 +1,15 @@
/* /*
* Cart manager - The TI-NESulator Project * Cart manager - The peTI-NESulator Project
* NESCart.c * NESCart.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
/* System Headers */ /* System Headers */
#if !defined(__TIGCC__) && !defined(__GCC4TI__) && !defined(__GTC__) #if !defined(__TIGCC__) && !defined(__GCC4TI__) && !defined(__GTC__)
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <memory.h> #include <memory.h>
@ -24,96 +20,100 @@
#include <tigcclib.h> #include <tigcclib.h>
#endif #endif
/* TI-NES headers */ /* peTI-NESulator headers */
#include <os_dependent.h> #include <os_dependent.h>
#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> #include <sys/mman.h>
void DumpCartProperties(FILE *out, NesCart * cart) void DumpCartProperties(FILE *out, NesCart *cart)
{ {
console_printf(Console_Verbose, console_printf(Console_Verbose,
"'%s' informations:\n" "'%s' informations:\n"
" Total ROM Size : 0x%06lX | Total VROM Size : 0x%06lX\n" " Total ROM Size : 0x%06lX | Total VROM Size : 0x%06lX\n"
" Mapper ID : 0x%06X | Mirroring ? : %s\n" " Mapper ID : 0x%06X | Mirroring ? : %s\n"
" Battery ? : %s | 4 Screen ? : %s \n" " Battery ? : %s | 4 Screen ? : %s \n"
" PROMBanks start at : %p |\n" " PROMBanks start at : %p |\n"
" VROMBanks start at : %p |\n", " VROMBanks start at : %p |\n",
cart->FileName, cart->FileName,
cart->PROMSize, cart->PROMSize,
cart->VROMSize, cart->VROMSize,
cart->MapperID, cart->MapperID,
cart->Flags & iNES_MIRROR? "Horizontal" : "Vertical", (cart->Flags & iNES_MIRROR) ? "Horizontal" : "Vertical",
cart->Flags & iNES_BATTERY? "Yes": "No ", (cart->Flags & iNES_BATTERY) ? "Yes" : "No ",
cart->Flags & iNES_4SCREEN? "Yes": "No ", (cart->Flags & iNES_4SCREEN) ? "Yes" : "No ",
cart->PROMBanks, cart->PROMBanks,
cart->VROMBanks); cart->VROMBanks);
} }
int LoadCart(const char *filename, NesCart * cart) int LoadCart(const char *filename, NesCart *cart)
{ {
char buffer[6]; char buffer[6];
/* Load the cart into memory */ /* Load the cart into memory */
cart->File = (byte *)LoadFilePtr((char *)filename); cart->File = (uint8_t *)LoadFilePtr((char *)filename);
if ((cart->File == NULL) || (cart->File == MAP_FAILED)) if ((cart->File == NULL) || (cart->File == MAP_FAILED))
return -1; {
return -1;
sprintf(buffer, "%c%c%c%c", 0x4E, 0x45, 0x53, 0x1A); }
/* Verify that this is a real iNES valid file */ sprintf(buffer, "%c%c%c%c", 0x4E, 0x45, 0x53, 0x1A);
if (memcmp(cart->File, buffer, 4))
return -1; /* Verify that this is a real iNES valid file */
if (memcmp(cart->File, buffer, 4) != 0)
{
return -1;
}
/* Before go elsewhere, verify that the header is clean ! /* Before go elsewhere, verify that the header is clean !
(aka no DiskDude! in it) */ (aka no DiskDude! in it) */
if (memcmp(cart->File+7, "DiskDude!", 9) == 0) if (memcmp(cart->File + 7, "DiskDude!", 9) == 0)
{ {
console_printf(Console_Warning, "\n" console_printf(Console_Warning, "\n"
"*******************WARNING****************\n" "*******************WARNING****************\n"
"* The header of this game is not clean *\n" "* The header of this game is not clean *\n"
"* (DiskDude! pollution) I will only use *\n" "* (DiskDude! pollution) I will only use *\n"
"* basic MapperID (mapper 0-15). This can *\n" "* basic MapperID (mapper 0-15). This can *\n"
"* led to unexpected behavior... *\n" "* led to unexpected behavior... *\n"
"* *\n" "* *\n"
"* PLEASE CLEAN THIS FILE! *\n" "* PLEASE CLEAN THIS FILE! *\n"
"******************WARNING*****************\n\n"); "******************WARNING*****************\n\n");
/* So this rom file is not clean, we can only rely on the "basic" mapperID */ /* So this rom file is not clean, we can only rely on the "basic" mapperID */
cart->MapperID = cart->File[6]>>4; /* Mapper Type */ cart->MapperID = cart->File[6] >> 4; /* Mapper Type */
} }
else else
{ /* This rom file is clean, we can read the extended MapperID */ { /* This rom file is clean, we can read the extended MapperID */
cart->MapperID = (cart->File[6]>>4)|(cart->File[7]&0xF0); /* Mapper Type */ cart->MapperID = (cart->File[6] >> 4) | (cart->File[7] & 0xF0); /* Mapper Type */
} }
/* Now fill the structure */ /* Now fill the structure */
cart->FileName = (char *)filename; cart->FileName = (char *)filename;
cart->PROMSize = cart->File[4] * 16 * 1024; /* Size of PROM */ cart->PROMSize = cart->File[4] * 16U * 1024U; /* Size of PROM */
cart->VROMSize = cart->File[5] * 8 * 1024; /* Size of VROM */ cart->VROMSize = cart->File[5] * 8U * 1024U; /* Size of VROM */
cart->Flags = cart->File[6] & 0x0F; cart->Flags = cart->File[6] & 0x0F;
/* We don't and we will never support trainer-ed ROM */ /* We don't and we will never support trainer-ed ROM */
if (cart->Flags & iNES_TRAINER) if (cart->Flags & iNES_TRAINER)
{ {
console_printf(Console_Error, "\n" console_printf(Console_Error, "\n"
"********************ERROR*****************\n" "********************ERROR*****************\n"
"* This cart have an embedded trainer. *\n" "* This cart have an embedded trainer. *\n"
"* There is NO support for them. *\n" "* There is NO support for them. *\n"
"* Please use a CLEAN dump if you want *\n" "* Please use a CLEAN dump if you want *\n"
"* to play this game. *\n" "* to play this game. *\n"
"********************ERROR*****************\n\n"); "********************ERROR*****************\n\n");
return -1; return -1;
} }
cart->PROMBanks = cart->File + 16; /* Pointer on the first PROM */ cart->PROMBanks = cart->File + 16; /* Pointer on the first PROM */
cart->VROMBanks = cart->PROMBanks + cart->PROMSize; /* Pointer on the first VROM */ cart->VROMBanks = cart->PROMBanks + cart->PROMSize; /* Pointer on the first VROM */
DumpCartProperties(stdout, cart); DumpCartProperties(stdout, cart);
return 0; return 0;
} }

View File

@ -1,13 +1,8 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2016 986-Studio. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$ add_library(apu apu.c apu.c)
# $Author$ target_link_libraries(apu portaudio_static)
# $HeadURL$
# $Revision$
add_library(apu SndUnixT.c Sound.c)
#add_library(apu SndAlleg.c Sound.c)

View File

@ -1,434 +0,0 @@
/*
* Allegro Sound Driver for EMULib Sound system - The TI-NESulator Project
* SndAlleg.C
*
* Created by Manoel Trapier
* Copyright 2003-2008 986 Corp. All rights reserved.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*
*/
#include <Sound.h>
/* Allegro includes */
#ifdef __APPLE__
#define USE_CONSOLE
#include <Allegro/allegro.h>
#else
#define USE_CONSOLE
#include <allegro.h>
#endif
#include <os_dependent.h>
#include <stdlib.h>
#include <stdio.h>
//#include <unistd.h>
//#include <fcntl.h>
#include <pthread.h>
//#include <sys/ioctl.h>
#define AUDIO_CONV(A) (128+(A))
AUDIOSTREAM *stream;
static pthread_t ThreadID;
static int SoundRate = 0;
static int MasterVolume = 64;
static int MasterSwitch = (1<<SND_CHANNELS)-1;
static int LoopFreq = 25;
static int NoiseGen = 1;
static int Suspended = 0;
static int SoundRun = 0;
static struct
{
int Type; /* Channel type (SND_*) */
int Freq; /* Channel frequency (Hz) */
int Volume; /* Channel volume (0..255) */
const signed char *Data; /* Wave data (-128..127 each) */
int Length; /* Wave length in Data */
int Rate; /* Wave playback rate (or 0Hz) */
int Pos; /* Wave current position in Data */
int Count; /* Phase counter */
} CH[SND_CHANNELS];
static void UnixSetWave(int Channel,const signed char *Data,int Length,int Rate);
static void UnixSetSound(int Channel,int NewType);
static void UnixDrum(int Type,int Force);
static void UnixSetChannels(int Volume,int Switch);
static void UnixSound(int Channel,int NewFreq,int NewVolume);
static int OpenSoundDevice(int Rate,int Verbose);
static void *DSPLoop(void *Arg);
/** StopSound() **********************************************/
/** Temporarily suspend sound. **/
/*************************************************************/
void StopSound(void) { Suspended=1; }
/** ResumeSound() ********************************************/
/** Resume sound after StopSound(). **/
/*************************************************************/
void ResumeSound(void) { Suspended=0; }
/** OpenSoundDevice() ****************************************/
/** Open /dev/dsp with a given level of sound quality. **/
/** Returns 0 if failed or sound quality (Mode). **/
/*************************************************************/
static int OpenSoundDevice(int Rate,int Verbose)
{
voice_start(stream->voice);
if(Verbose) puts("OK");
return(Rate);
}
/** DSPLoop() ************************************************/
/** Main loop of the sound server. **/
/*************************************************************/
static void *DSPLoop(void *Arg)
{
int Wave[SND_BUFSIZE];
unsigned char *Buf;
register int J,I,K,L,M,N,L1,L2,A1,A2,V;
int FreqCount;
N = L = A2 = 0;
for(J=0;J<SND_CHANNELS;J++)
{
CH[J].Type = SND_MELODIC;
CH[J].Count = 0;
CH[J].Volume = 0;
CH[J].Freq = 0;
}
FreqCount=SoundRate/SND_BUFSIZE;
for(;;)
{
Buf = get_audio_stream_buffer(stream);
if (Buf) {
FreqCount-=LoopFreq;
/* If suspending sound... */
if(Suspended)
{
/* Close sound device */
while(Suspended) sleep(1);
/* Reopen sound device */
SoundRate=OpenSoundDevice(SoundRate,0);
}
/* Waveform generator */
for(J=0,M=MasterSwitch;M&&(J<SND_CHANNELS);J++,M>>=1)
if(CH[J].Freq&&(V=CH[J].Volume)&&(M&1))
switch(CH[J].Type)
{
case SND_NOISE: /* White Noise */
/* For high frequencies, recompute volume */
if(CH[J].Freq<=SoundRate) K=0x10000*CH[J].Freq/SoundRate;
else { V=V*SoundRate/CH[J].Freq;K=0x10000; }
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L1+=K;
if(L1&0xFFFF0000)
{
L1&=0xFFFF;
if((NoiseGen<<=1)&0x80000000) NoiseGen^=0x08000001;
}
Wave[I]+=NoiseGen&1? V:-V;
}
CH[J].Count=L1;
break;
case SND_WAVE: /* Custom Waveform */
/* Waveform data must have correct length! */
if(CH[J].Length<=0) break;
/* Start counting */
K = CH[J].Rate>0? (SoundRate<<15)/CH[J].Freq/CH[J].Rate
: (SoundRate<<15)/CH[J].Freq/CH[J].Length;
L1 = CH[J].Pos%CH[J].Length;
L2 = CH[J].Count;
A1 = CH[J].Data[L1]*V;
/* If expecting interpolation... */
if(L2<K)
{
/* Compute interpolation parameters */
A2 = CH[J].Data[(L1+1)%CH[J].Length]*V;
L = (L2>>15)+1;
N = ((K-(L2&0x7FFF))>>15)+1;
}
/* Add waveform to the buffer */
for(I=0;I<SND_BUFSIZE;I++)
if(L2<K)
{
/* Interpolate linearly */
Wave[I]+=A1+L*(A2-A1)/N;
/* Next waveform step */
L2+=0x8000;
/* Next interpolation step */
L++;
}
else
{
L1 = (L1+L2/K)%CH[J].Length;
L2 = (L2%K)+0x8000;
A1 = CH[J].Data[L1]*V;
Wave[I]+=A1;
/* If expecting interpolation... */
if(L2<K)
{
/* Compute interpolation parameters */
A2 = CH[J].Data[(L1+1)%CH[J].Length]*V;
L = 1;
N = ((K-L2)>>15)+1;
}
}
/* End counting */
CH[J].Pos = L1;
CH[J].Count = L2;
break;
case SND_QS_DU0:
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+=L1&0x2000?(L2&0x8000? V:0):(L2&0x8000? 0:-V);
L1=L2;
}
CH[J].Count=L1;
break;
case SND_QS_DU1:
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+=L1&0x4000?(L2&0x8000? V:0):(L2&0x8000? 0:-V);
L1=L2;
}
CH[J].Count=L1;
break;
case SND_QS_DU3:
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+=L1&0xC000?(L2&0x4000? V:0):(L2&0xC000? 0:-V);
L1=L2;
}
CH[J].Count=L1;
break;
case SND_QS_DU2:
case SND_MELODIC: /* Melodic Sound */
default: /* Default Sound */
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+=L1&0x8000? (L2&0x8000? V:0):(L2&0x8000? 0:-V);
L1=L2;
}
CH[J].Count=L1;
break;
case SND_TRIANGLE: /* Default Sound */
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+= L1&0x8000?V:-V /*(L2&0x8000? V:0):(L2&0x8000? 0:-V)*/;
L1=L2;
}
CH[J].Count=L1;
break;
}
/* Mix and convert waveforms */
for(J=0;J<SND_BUFSIZE;J++)
{
I=(Wave[J]*MasterVolume)>>16;
I=I<-128? -128:I>127? 127:I;
Buf[J]=AUDIO_CONV(I);
Wave[J]=0;
}
free_audio_stream_buffer(stream);
}
}
return(0);
}
/** InitSound() **********************************************/
/** Initialize DSP. Returns Rate on success, 0 otherwise. **/
/** Mode is 0 to skip initialization (will be silent). **/
/*************************************************************/
int InitSound(int Rate,int Verbose)
{
/* If sound was initialized, kill it */
TrashSound();
/* Silence requested */
if(Rate<=0) return(0);
/* Synthesis rate should be at least 8kHz */
if(Rate<8192) Rate=44100;
/* Initialize things */
SoundRate = 0;
ThreadID = 0;
Suspended = 0;
/* Set driver functions */
SndDriver.SetSound = UnixSetSound;
SndDriver.Drum = UnixDrum;
SndDriver.SetChannels = UnixSetChannels;
SndDriver.Sound = UnixSound;
SndDriver.SetWave = UnixSetWave;
if (install_sound(DIGI_AUTODETECT, MIDI_NONE, "") != 0)
{
console_printf(Console_Error, "%s!\n", allegro_error);
return 1;
}
stream = play_audio_stream(SND_BUFSIZE, 8, FALSE, Rate, 255, 128);
if (!stream) {
console_printf(Console_Error, "Error creating audio stream!\n");
return 1;
}
voice_stop(stream->voice);
/* Open sound device */
if(Verbose) puts("Starting sound server:");
if(!(Rate=OpenSoundDevice(Rate,Verbose))) return(0);
/* Create DSPLoop() thread */
if(Verbose) console_printf(Console_Default, " Creating thread...");
if(pthread_create(&ThreadID,0,DSPLoop,0))
{ if(Verbose) puts("FAILED");return(0); }
/* Detach the thread */
pthread_detach(ThreadID);
/* Done */
SoundRun = 1;
if(Verbose) puts("OK");
return(SoundRate=Rate);
}
/** TrashSound() *********************************************/
/** Shut DSP down. **/
/*************************************************************/
void TrashSound(void)
{
if (SoundRun == 1)
{
StopSound();
console_printf(Console_Default, "%s: Kill thread...\n", __func__);
if(ThreadID) pthread_cancel(ThreadID);
}
SoundRun = 0;
SoundRate = 0;
ThreadID = 0;
}
/** UnixSound() **********************************************/
/** Generate sound of given frequency (Hz) and volume **/
/** (0..255) via given channel. **/
/*************************************************************/
void UnixSound(int Channel,int NewFreq,int NewVolume)
{
if((Channel<0)||(Channel>=SND_CHANNELS)) return;
if(!NewVolume||!NewFreq) { NewVolume=0;NewFreq=0; }
CH[Channel].Volume = NewVolume;
CH[Channel].Freq = NewFreq;
}
/** UnixSetChannels() ****************************************/
/** Set master volume (0..255) and turn channels on/off. **/
/** Each bit in Toggle corresponds to a channel (1=on). **/
/*************************************************************/
void UnixSetChannels(int MVolume,int MSwitch)
{
/* Set new MasterSwitch value */
MasterSwitch = MSwitch;
MasterVolume = MVolume;
}
/** UnixSetSound() *******************************************/
/** Set sound type (SND_NOISE/SND_MELODIC) for a given **/
/** channel. **/
/*************************************************************/
void UnixSetSound(int Channel,int NewType)
{
if((Channel<0)||(Channel>=SND_CHANNELS)) return;
CH[Channel].Type = NewType;
}
/** UnixSetWave() ********************************************/
/** Set waveform for a given channel. The channel will be **/
/** marked with sound type SND_WAVE. Set Rate=0 if you want **/
/** waveform to be an instrument or set it to the waveform **/
/** own playback rate. **/
/*************************************************************/
void UnixSetWave(int Channel,const signed char *Data,int Length,int Rate)
{
if((Channel<0)||(Channel>=SND_CHANNELS)||(Length<=0)) return;
CH[Channel].Type = SND_WAVE;
CH[Channel].Length = Length;
CH[Channel].Rate = Rate;
CH[Channel].Pos = 0;
CH[Channel].Count = 0;
CH[Channel].Data = Data;
}
/** UnixDrum() ***********************************************/
/** Hit a drum of a given type with given force. **/
/*************************************************************/
void UnixDrum(int Type,int Force)
{
/* This function is currently empty */
}

View File

@ -1,556 +0,0 @@
/** EMULib Emulation Library *********************************/
/** **/
/** SndUnix.c **/
/** **/
/** This file contains standard sound generation routines **/
/** for Unix using /dev/dsp and /dev/audio. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2002 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
//#include "Sound.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <os_dependent.h>
#if 0
#ifdef SUN_AUDIO
#include <sys/audioio.h>
#include <sys/conf.h>
#include <stropts.h>
#define AUDIO_CONV(A) (ULAW[0xFF&(128+(A))])
static unsigned char ULAW[256] =
{
31, 31, 31, 32, 32, 32, 32, 33,
33, 33, 33, 34, 34, 34, 34, 35,
35, 35, 35, 36, 36, 36, 36, 37,
37, 37, 37, 38, 38, 38, 38, 39,
39, 39, 39, 40, 40, 40, 40, 41,
41, 41, 41, 42, 42, 42, 42, 43,
43, 43, 43, 44, 44, 44, 44, 45,
45, 45, 45, 46, 46, 46, 46, 47,
47, 47, 47, 48, 48, 49, 49, 50,
50, 51, 51, 52, 52, 53, 53, 54,
54, 55, 55, 56, 56, 57, 57, 58,
58, 59, 59, 60, 60, 61, 61, 62,
62, 63, 63, 64, 65, 66, 67, 68,
69, 70, 71, 72, 73, 74, 75, 76,
77, 78, 79, 81, 83, 85, 87, 89,
91, 93, 95, 99, 103, 107, 111, 119,
255, 247, 239, 235, 231, 227, 223, 221,
219, 217, 215, 213, 211, 209, 207, 206,
205, 204, 203, 202, 201, 200, 199, 198,
219, 217, 215, 213, 211, 209, 207, 206,
205, 204, 203, 202, 201, 200, 199, 198,
197, 196, 195, 194, 193, 192, 191, 191,
190, 190, 189, 189, 188, 188, 187, 187,
186, 186, 185, 185, 184, 184, 183, 183,
182, 182, 181, 181, 180, 180, 179, 179,
178, 178, 177, 177, 176, 176, 175, 175,
175, 175, 174, 174, 174, 174, 173, 173,
173, 173, 172, 172, 172, 172, 171, 171,
171, 171, 170, 170, 170, 170, 169, 169,
169, 169, 168, 168, 168, 168, 167, 167,
167, 167, 166, 166, 166, 166, 165, 165,
165, 165, 164, 164, 164, 164, 163, 163
};
#else /* SUN_AUDIO */
#ifdef __FreeBSD__
#include <machine/soundcard.h>
#endif
#ifdef __NetBSD__
#include <soundcard.h>
#endif
#ifdef __linux__
#include <sys/soundcard.h>
#endif
#define AUDIO_CONV(A) (128+(A))
#endif /* SUN_AUDIO */
static pthread_t ThreadID;
static int SoundFD;
static int SoundRate = 0;
static int MasterVolume = 64;
static int MasterSwitch = (1<<SND_CHANNELS)-1;
static int LoopFreq = 25;
static int NoiseGen = 1;
static int Suspended = 0;
static struct
{
int Type; /* Channel type (SND_*) */
int Freq; /* Channel frequency (Hz) */
int Volume; /* Channel volume (0..255) */
signed char *Data; /* Wave data (-128..127 each) */
int Length; /* Wave length in Data */
int Rate; /* Wave playback rate (or 0Hz) */
int Pos; /* Wave current position in Data */
int Count; /* Phase counter */
} CH[SND_CHANNELS];
static void UnixSetWave(int Channel, signed char *Data,int Length,int Freq);
static void UnixSetSound(int Channel,int NewType);
static void UnixDrum(int Type,int Force);
static void UnixSetChannels(int Volume,int Switch);
static void UnixSound(int Channel,int NewFreq,int NewVolume);
static int OpenSoundDevice(int Rate,int Verbose);
static void *DSPLoop(void *Arg);
/** StopSound() **********************************************/
/** Temporarily suspend sound. **/
/*************************************************************/
void StopSound(void) { Suspended=1; }
/** ResumeSound() ********************************************/
/** Resume sound after StopSound(). **/
/*************************************************************/
void ResumeSound(void) { Suspended=0; }
/** OpenSoundDevice() ****************************************/
/** Open /dev/dsp with a given level of sound quality. **/
/** Returns 0 if failed or sound quality (Mode). **/
/*************************************************************/
static int OpenSoundDevice(int Rate,int Verbose)
{
int I,J,K;
#ifdef SUN_AUDIO
if(Verbose) console_printf(Console_Default, " Opening /dev/audio...");
if((SoundFD=open("/dev/audio",O_WRONLY | O_NONBLOCK))==-1)
{
if(Verbose) puts("FAILED");
return(0);
}
/*
** Sun's specific initialization should be here...
** We assume, that it's set to 8000Hz u-law mono right now.
*/
#else /* SUN_AUDIO */
/* At first, we need to open /dev/dsp: */
if(Verbose) console_printf(Console_Default, " Opening /dev/dsp...");
I=((SoundFD=open("/dev/dsp",O_WRONLY))<0);
/* Set 8-bit sound */
if(!I)
{
if(Verbose) console_printf(Console_Default, "OK\n Setting mode: 8bit...");
J=AFMT_U8;
I=(ioctl(SoundFD,SNDCTL_DSP_SETFMT,&J)<0);
}
/* Set mono sound */
if(!I)
{
if(Verbose) console_printf(Console_Default, "mono...");
J=0;
I=(ioctl(SoundFD,SNDCTL_DSP_STEREO,&J)<0);
}
/* Set sampling rate */
if(!I)
{
if(Verbose) console_printf(Console_Default, "OK\n Setting sampling rate: %dHz...",Rate);
I=(ioctl(SoundFD,SNDCTL_DSP_SPEED,&Rate)<0);
if(Verbose) console_printf(Console_Default, "(got %dHz)...",Rate);
}
/* Here we set the number of buffers to use */
if(!I)
{
if(Verbose)
printf
(
"OK\n Adjusting buffers: %d buffers %d bytes each...",
SND_BUFFERS,1<<SND_BITS
);
/* Set buffer length and number of buffers */
J=K=SND_BITS|(SND_BUFFERS<<16);
I=(ioctl(SoundFD,SNDCTL_DSP_SETFRAGMENT,&J)<0);
/* Buffer length as n, not 2^n! */
if((J&0xFFFF)<16) J=(J&0xFFFF0000)|(1<<(J&0xFFFF));
K=(1<<SND_BITS)|(SND_BUFFERS<<16);
/* If something went wrong... */
if(J!=K)
{
if((J>>16)<SND_BUFFERS) I=-1;
if((J&0xFFFF)!=(1<<SND_BITS)) I=-1;
}
}
/* If something failed, fall out */
if(I) { if(Verbose) puts("FAILED");return(0); }
#endif /* SUN_AUDIO */
if(Verbose) puts("OK");
return(Rate);
}
/** DSPLoop() ************************************************/
/** Main loop of the sound server. **/
/*************************************************************/
static void *DSPLoop(void *Arg)
{
int Wave[SND_BUFSIZE];
unsigned char Buf[SND_BUFSIZE];
register int J,I,K,L,M,N,L1,L2,A1,A2,V;
int FreqCount;
int ret;
L = N = A2 = 0;
for(J=0;J<SND_CHANNELS;J++)
{
CH[J].Type = SND_MELODIC;
CH[J].Count = 0;
CH[J].Volume = 0;
CH[J].Freq = 0;
}
FreqCount=SoundRate/SND_BUFSIZE;
for(;;FreqCount-=LoopFreq)
{
/* If suspending sound... */
if(Suspended)
{
/* Close sound device */
#ifndef SUN_AUDIO
ioctl(SoundFD,SNDCTL_DSP_RESET);
#endif
close(SoundFD);
/* Suspend execution until Suspended=0 */
while(Suspended) sleep(1);
/* Reopen sound device */
SoundRate=OpenSoundDevice(SoundRate,0);
}
/* Waveform generator */
for(J=0,M=MasterSwitch;M&&(J<SND_CHANNELS);J++,M>>=1)
if(CH[J].Freq&&(V=CH[J].Volume)&&(M&1))
switch(CH[J].Type)
{
case SND_NOISE: /* White Noise */
/* For high frequencies, recompute volume */
if(CH[J].Freq<=SoundRate) K=0x10000*CH[J].Freq/SoundRate;
else { V=V*SoundRate/CH[J].Freq;K=0x10000; }
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L1+=K;
if(L1&0xFFFF0000)
{
L1&=0xFFFF;
if((NoiseGen<<=1)&0x80000000) NoiseGen^=0x08000001;
}
Wave[I]+=NoiseGen&1? V:-V;
}
CH[J].Count=L1;
break;
case SND_WAVE: /* Custom Waveform */
/* Waveform data must have correct length! */
if(CH[J].Length<=0) break;
/* Start counting */
K = CH[J].Rate>0? (SoundRate<<15)/CH[J].Freq/CH[J].Rate
: (SoundRate<<15)/CH[J].Freq/CH[J].Length;
L1 = CH[J].Pos%CH[J].Length;
L2 = CH[J].Count;
A1 = CH[J].Data[L1]*V;
/* If expecting interpolation... */
if(L2<K)
{
/* Compute interpolation parameters */
A2 = CH[J].Data[(L1+1)%CH[J].Length]*V;
L = (L2>>15)+1;
N = ((K-(L2&0x7FFF))>>15)+1;
}
/* Add waveform to the buffer */
for(I=0;I<SND_BUFSIZE;I++)
if(L2<K)
{
/* Interpolate linearly */
Wave[I]+=A1+L*(A2-A1)/N;
/* Next waveform step */
L2+=0x8000;
/* Next interpolation step */
L++;
}
else
{
L1 = (L1+L2/K)%CH[J].Length;
L2 = (L2%K)+0x8000;
A1 = CH[J].Data[L1]*V;
Wave[I]+=A1;
/* If expecting interpolation... */
if(L2<K)
{
/* Compute interpolation parameters */
A2 = CH[J].Data[(L1+1)%CH[J].Length]*V;
L = 1;
N = ((K-L2)>>15)+1;
}
}
/* End counting */
CH[J].Pos = L1;
CH[J].Count = L2;
break;
case SND_QS_DU0:
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+=L1&0x2000?(L2&0x8000? V:0):(L2&0x8000? 0:-V);
L1=L2;
}
CH[J].Count=L1;
break;
case SND_QS_DU1:
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+=L1&0x4000?(L2&0x8000? V:0):(L2&0x8000? 0:-V);
L1=L2;
}
CH[J].Count=L1;
break;
case SND_QS_DU3:
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+=L1&0xC000?(L2&0x4000? V:0):(L2&0xC000? 0:-V);
L1=L2;
}
CH[J].Count=L1;
break;
case SND_QS_DU2:
case SND_MELODIC: /* Melodic Sound */
default: /* Default Sound */
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+=L1&0x8000? (L2&0x8000? V:0):(L2&0x8000? 0:-V);
L1=L2;
}
CH[J].Count=L1;
break;
case SND_TRIANGLE: /* Default Sound */
/* Do not allow frequencies that are too high */
if(CH[J].Freq>=SoundRate/3) break;
K=0x10000*CH[J].Freq/SoundRate;
L1=CH[J].Count;
V<<=7;
for(I=0;I<SND_BUFSIZE;I++)
{
L2=L1+K;
Wave[I]+= L1&0x2000?V:-V /*(L2&0x8000? V:0):(L2&0x8000? 0:-V)*/;
L1=L2;
}
CH[J].Count=L1;
break;
}
/* Mix and convert waveforms */
for(J=0;J<SND_BUFSIZE;J++)
{
I=(Wave[J]*MasterVolume)>>16;
I=I<-128? -128:I>127? 127:I;
Buf[J]=AUDIO_CONV(I);
Wave[J]=0;
}
if(SoundFD==-1) sleep(1);
else
{
#ifdef SUN_AUDIO
/* Flush output first, don't care about return status. After this
** write next buffer of audio data. This method produces a horrible
** click on each buffer :( Any ideas, how to fix this?
*/
ioctl(SoundFD,AUDIO_DRAIN);
write(SoundFD,Buf,SND_BUFSIZE);
#else
/* We'll block here until next DMA buffer becomes free. It happens
** once per (1<<SND_BITS)/SoundRate seconds.
*/
ret = write(SoundFD,Buf,SND_BUFSIZE);
#endif
}
}
return(0);
}
/** InitSound() **********************************************/
/** Initialize DSP. Returns Rate on success, 0 otherwise. **/
/** Mode is 0 to skip initialization (will be silent). **/
/*************************************************************/
int InitSound(int Rate,int Verbose)
{
/* If sound was initialized, kill it */
TrashSound();
/* Silence requested */
if(Rate<=0) return(0);
/* Synthesis rate should be at least 8kHz */
if(Rate<8192) Rate=44100;
/* Initialize things */
SoundRate = 0;
SoundFD = -1;
ThreadID = 0;
Suspended = 0;
/* Set driver functions */
SndDriver.SetSound = UnixSetSound;
SndDriver.Drum = UnixDrum;
SndDriver.SetChannels = UnixSetChannels;
SndDriver.Sound = UnixSound;
SndDriver.SetWave = UnixSetWave;
/* Open sound device */
if(Verbose) puts("Starting sound server:");
if(!(Rate=OpenSoundDevice(Rate,Verbose))) return(0);
/* Create DSPLoop() thread */
if(Verbose) console_printf(Console_Default, " Creating thread...");
if(pthread_create(&ThreadID,0,DSPLoop,0))
{ if(Verbose) puts("FAILED");return(0); }
/* Detach the thread */
pthread_detach(ThreadID);
/* Done */
if(Verbose) puts("OK");
return(SoundRate=Rate);
}
/** TrashSound() *********************************************/
/** Shut DSP down. **/
/*************************************************************/
void TrashSound(void)
{
StopSound();
console_printf(Console_Default, "%s: Kill thread...\n", __func__);
if(ThreadID) pthread_cancel(ThreadID);
console_printf(Console_Default, "%s: close /dev/xxx ...\n", __func__);
if(SoundFD!=-1) close(SoundFD);
SoundRate = 0;
SoundFD = -1;
ThreadID = 0;
}
/** UnixSound() **********************************************/
/** Generate sound of given frequency (Hz) and volume **/
/** (0..255) via given channel. **/
/*************************************************************/
void UnixSound(int Channel,int NewFreq,int NewVolume)
{
if((Channel<0)||(Channel>=SND_CHANNELS)) return;
if(!NewVolume||!NewFreq) { NewVolume=0;NewFreq=0; }
CH[Channel].Volume = NewVolume;
CH[Channel].Freq = NewFreq;
}
/** UnixSetChannels() ****************************************/
/** Set master volume (0..255) and turn channels on/off. **/
/** Each bit in Toggle corresponds to a channel (1=on). **/
/*************************************************************/
void UnixSetChannels(int MVolume,int MSwitch)
{
/* Set new MasterSwitch value */
MasterSwitch = MSwitch;
MasterVolume = MVolume;
}
/** UnixSetSound() *******************************************/
/** Set sound type (SND_NOISE/SND_MELODIC) for a given **/
/** channel. **/
/*************************************************************/
void UnixSetSound(int Channel,int NewType)
{
if((Channel<0)||(Channel>=SND_CHANNELS)) return;
CH[Channel].Type = NewType;
}
/** UnixSetWave() ********************************************/
/** Set waveform for a given channel. The channel will be **/
/** marked with sound type SND_WAVE. Set Rate=0 if you want **/
/** waveform to be an instrument or set it to the waveform **/
/** own playback rate. **/
/*************************************************************/
void UnixSetWave(int Channel, signed char *Data, int Length, int Freq)
{
if((Channel<0)||(Channel>=SND_CHANNELS)||(Length<=0)) return;
CH[Channel].Type = SND_WAVE;
CH[Channel].Length = Length;
CH[Channel].Rate = Freq;
CH[Channel].Pos = 0;
CH[Channel].Count = 0;
CH[Channel].Data = Data;
}
/** UnixDrum() ***********************************************/
/** Hit a drum of a given type with given force. **/
/*************************************************************/
void UnixDrum(int Type,int Force)
{
/* This function is currently empty */
}
#endif

View File

@ -1,504 +0,0 @@
/** EMULib Emulation Library *********************************/
/** **/
/** Sound.c **/
/** **/
/** This file file implements core part of the sound API **/
/** and functions needed to log soundtrack into a MIDI **/
/** file. See Sound.h for declarations. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2007 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
/*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*/
#include "Sound.h"
#include <stdio.h>
#include <string.h>
#ifdef UNIX
#include <unistd.h>
#endif
typedef unsigned char byte;
typedef unsigned short word;
struct SndDriverStruct SndDriver =
{
(void (*)(int,int))0,
(void (*)(int,int))0,
(void (*)(int,int))0,
(void (*)(int,int,int))0,
(void (*)(int,signed char *,int,int))0,
(const signed char *(*)(int))0
};
static const struct { byte Note;word Wheel; } Freqs[4096] =
{
#include "MIDIFreq.h"
};
static const int Programs[5] =
{
80, /* SND_MELODIC/SND_RECTANGLE */
80, /* SND_TRIANGLE */
122, /* SND_NOISE */
122, /* SND_PERIODIC */
80 /* SND_WAVE */
};
static struct
{
int Type;
int Note;
int Pitch;
int Level;
} CH[MIDI_CHANNELS] =
{
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 },
{ -1,-1,-1,-1 }
};
static const char *LogName = 0;
static int Logging = MIDI_OFF;
static int TickCount = 0;
static int LastMsg = -1;
static int DrumOn = 0;
static FILE *MIDIOut = 0;
static void MIDISound(int Channel,int Freq,int Volume);
static void MIDISetSound(int Channel,int Type);
static void MIDIDrum(int Type,int Force);
static void MIDIMessage(byte D0,byte D1,byte D2);
static void NoteOn(byte Channel,byte Note,byte Level);
static void NoteOff(byte Channel);
static void WriteDelta(void);
static void WriteTempo(int Freq);
/** SHIFT() **************************************************/
/** Make MIDI channel#10 last, as it is normally used for **/
/** percussion instruments only and doesn't sound nice. **/
/*************************************************************/
#define SHIFT(Ch) (Ch==15? 9:Ch>8? Ch+1:Ch)
/** Sound() **************************************************/
/** Generate sound of given frequency (Hz) and volume **/
/** (0..255) via given channel. Setting Freq=0 or Volume=0 **/
/** turns sound off. **/
/*************************************************************/
void Sound(int Channel,int Freq,int Volume)
{
if(Channel<0) return;
Freq = Freq<0? 0:Freq;
Volume = Volume<0? 0:Volume>255? 255:Volume;
/* Call sound driver if present */
if(SndDriver.Sound) (*SndDriver.Sound)(Channel,Freq,Volume);
/* Log sound to MIDI file */
MIDISound(Channel,Freq,Volume);
}
/** Drum() ***************************************************/
/** Hit a drum of given type with given force (0..255). **/
/** MIDI drums can be used by ORing their numbers with **/
/** SND_MIDI. **/
/*************************************************************/
void Drum(int Type,int Force)
{
Force = Force<0? 0:Force>255? 255:Force;
if(SndDriver.Drum) (*SndDriver.Drum)(Type,Force);
/* Log drum to MIDI file */
MIDIDrum(Type,Force);
}
/** SetSound() ***********************************************/
/** Set sound type at a given channel. MIDI instruments can **/
/** be set directly by ORing their numbers with SND_MIDI. **/
/*************************************************************/
void SetSound(int Channel,int Type)
{
if(Channel<0) return;
if(SndDriver.SetSound) (*SndDriver.SetSound)(Channel,Type);
/* Log instrument change to MIDI file */
MIDISetSound(Channel,Type);
}
/** SetChannels() ********************************************/
/** Set master volume (0..255) and switch channels on/off. **/
/** Each channel N has corresponding bit 2^N in Switch. Set **/
/** or reset this bit to turn the channel on or off. **/
/*************************************************************/
void SetChannels(int Volume,int Switch)
{
Volume = Volume<0? 0:Volume>255? 255:Volume;
if(SndDriver.SetChannels) (*SndDriver.SetChannels)(Volume,Switch);
}
/** SetWave() ************************************************/
/** Set waveform for a given channel. The channel will be **/
/** marked with sound type SND_WAVE. Set Rate=0 if you want **/
/** waveform to be an instrument or set it to the waveform **/
/** own playback rate. **/
/*************************************************************/
void SetWave(int Channel,signed char *Data,int Length,int Rate)
{
if((Channel<0)||(Length<=0)) return;
if(SndDriver.SetWave) (*SndDriver.SetWave)(Channel,Data,Length,Rate);
/* Log instrument change to MIDI file */
MIDISetSound(Channel,Rate? -1:SND_MELODIC);
}
/** GetWave() ************************************************/
/** Get current read position for the buffer set with the **/
/** SetWave() call. Returns 0 if no buffer has been set, or **/
/** if there is no playrate set (i.e. wave is instrument). **/
/*************************************************************/
const signed char *GetWave(int Channel)
{
return(SndDriver.GetWave? (*SndDriver.GetWave)(Channel):0);
}
/** InitMIDI() ***********************************************/
/** Initialize soundtrack logging into MIDI file FileName. **/
/** Repeated calls to InitMIDI() will close current MIDI **/
/** file and continue logging into a new one. **/
/*************************************************************/
void InitMIDI(const char *FileName)
{
int WasLogging;
/* Must pass a name! */
if(!FileName) return;
/* Memorize logging status */
WasLogging=Logging;
/* If MIDI logging in progress, close current file */
if(MIDIOut) TrashMIDI();
/* Set log file name and ticks/second parameter, no logging yet */
LogName = FileName;
Logging = MIDI_OFF;
LastMsg = -1;
TickCount = 0;
MIDIOut = 0;
DrumOn = 0;
/* If was logging, restart */
if(WasLogging) MIDILogging(MIDI_ON);
}
/** TrashMIDI() **********************************************/
/** Finish logging soundtrack and close the MIDI file. **/
/*************************************************************/
void TrashMIDI(void)
{
long Length;
int J;
/* If not logging, drop out */
if(!MIDIOut) return;
/* Turn sound off */
for(J=0;J<MIDI_CHANNELS;J++) NoteOff(J);
/* End of track */
MIDIMessage(0xFF,0x2F,0x00);
/* Put track length in file */
fseek(MIDIOut,0,SEEK_END);
Length=ftell(MIDIOut)-22;
fseek(MIDIOut,18,SEEK_SET);
fputc((Length>>24)&0xFF,MIDIOut);
fputc((Length>>16)&0xFF,MIDIOut);
fputc((Length>>8)&0xFF,MIDIOut);
fputc(Length&0xFF,MIDIOut);
/* Done logging */
fclose(MIDIOut);
Logging = MIDI_OFF;
LastMsg = -1;
TickCount = 0;
MIDIOut = 0;
}
/** MIDILogging() ********************************************/
/** Turn soundtrack logging on/off and return its current **/
/** status. Possible values of Switch are MIDI_OFF (turn **/
/** logging off), MIDI_ON (turn logging on), MIDI_TOGGLE **/
/** (toggle logging), and MIDI_QUERY (just return current **/
/** state of logging). **/
/*************************************************************/
int MIDILogging(int Switch)
{
static const char MThd[] = "MThd\0\0\0\006\0\0\0\1";
/* ID DataLen Fmt Trks */
static const char MTrk[] = "MTrk\0\0\0\0";
/* ID TrkLen */
int J,I;
/* Toggle logging if requested */
if(Switch==MIDI_TOGGLE) Switch=!Logging;
if((Switch==MIDI_ON)||(Switch==MIDI_OFF))
if(Switch^Logging)
{
/* When turning logging off, silence all channels */
if(!Switch&&MIDIOut)
for(J=0;J<MIDI_CHANNELS;J++) NoteOff(J);
/* When turning logging on, open MIDI file */
if(Switch&&!MIDIOut&&LogName)
{
/* No messages have been sent yet */
LastMsg=-1;
/* Clear all storage */
for(J=0;J<MIDI_CHANNELS;J++)
CH[J].Note=CH[J].Pitch=CH[J].Level=-1;
/* Open new file and write out the header */
MIDIOut=fopen(LogName,"wb");
if(!MIDIOut) return(MIDI_OFF);
if(fwrite(MThd,1,12,MIDIOut)!=12)
{ fclose(MIDIOut);MIDIOut=0;return(MIDI_OFF); }
fputc((MIDI_DIVISIONS>>8)&0xFF,MIDIOut);
fputc(MIDI_DIVISIONS&0xFF,MIDIOut);
if(fwrite(MTrk,1,8,MIDIOut)!=8)
{ fclose(MIDIOut);MIDIOut=0;return(MIDI_OFF); }
/* Write out the tempo */
WriteTempo(MIDI_DIVISIONS);
}
/* Turn logging off on failure to open MIDIOut */
if(!MIDIOut) Switch=MIDI_OFF;
/* Assign new switch value */
Logging=Switch;
/* If switching logging on... */
if(Switch)
{
/* Start logging without a pause */
TickCount=0;
/* Write instrument changes */
for(J=0;J<MIDI_CHANNELS;J++)
if((CH[J].Type>=0)&&(CH[J].Type&0x10000))
{
I=CH[J].Type&~0x10000;
CH[J].Type=-1;
MIDISetSound(J,I);
}
}
}
/* Return current logging status */
return(Logging);
}
/** MIDITicks() **********************************************/
/** Log N 1ms MIDI ticks. **/
/*************************************************************/
void MIDITicks(int N)
{
if(Logging&&MIDIOut&&(N>0)) TickCount+=N;
}
/** MIDISound() **********************************************/
/** Set sound frequency (Hz) and volume (0..255) for a **/
/** given channel. **/
/*************************************************************/
void MIDISound(int Channel,int Freq,int Volume)
{
int MIDIVolume,MIDINote,MIDIWheel;
/* If logging off, file closed, or invalid channel, drop out */
if(!Logging||!MIDIOut||(Channel>=MIDI_CHANNELS-1)||(Channel<0)) return;
/* Frequency must be in range */
if((Freq<MIDI_MINFREQ)||(Freq>MIDI_MAXFREQ)) Freq=0;
/* Volume must be in range */
if(Volume<0) Volume=0; else if(Volume>255) Volume=255;
/* Instrument number must be valid */
if(CH[Channel].Type<0) Freq=0;
if(!Volume||!Freq) NoteOff(Channel);
else
{
/* SND_TRIANGLE is twice quieter than SND_MELODIC */
if(CH[Channel].Type==SND_TRIANGLE) Volume=(Volume+1)/2;
/* Compute MIDI note parameters */
MIDIVolume = (127*Volume+128)/255;
MIDINote = Freqs[Freq/3].Note;
MIDIWheel = Freqs[Freq/3].Wheel;
/* Play new note */
NoteOn(Channel,MIDINote,MIDIVolume);
/* Change pitch */
if(CH[Channel].Pitch!=MIDIWheel)
{
MIDIMessage(0xE0+SHIFT(Channel),MIDIWheel&0x7F,(MIDIWheel>>7)&0x7F);
CH[Channel].Pitch=MIDIWheel;
}
}
}
/** MIDISetSound() *******************************************/
/** Set sound type for a given channel. **/
/*************************************************************/
void MIDISetSound(int Channel,int Type)
{
/* Channel must be valid */
if((Channel>=MIDI_CHANNELS-1)||(Channel<0)) return;
/* If instrument changed... */
if(CH[Channel].Type!=Type)
{
/* If logging off or file closed, drop out */
if(!Logging||!MIDIOut) CH[Channel].Type=Type|0x10000;
else
{
CH[Channel].Type=Type;
if(Type<0) NoteOff(Channel);
else
{
Type=Type&SND_MIDI? (Type&0x7F):Programs[Type%5];
MIDIMessage(0xC0+SHIFT(Channel),Type,255);
}
}
}
}
/** MIDIDrum() ***********************************************/
/** Hit a drum of a given type with given force. **/
/*************************************************************/
void MIDIDrum(int Type,int Force)
{
/* If logging off or invalid channel, drop out */
if(!Logging||!MIDIOut) return;
/* The only non-MIDI drum is a click ("Low Wood Block") */
Type=Type&DRM_MIDI? (Type&0x7F):77;
/* Release previous drum */
if(DrumOn) MIDIMessage(0x89,DrumOn,127);
/* Hit next drum */
if(Type) MIDIMessage(0x99,Type,(Force&0xFF)/2);
DrumOn=Type;
}
/** MIDIMessage() ********************************************/
/** Write out a MIDI message. **/
/*************************************************************/
void MIDIMessage(byte D0,byte D1,byte D2)
{
/* Write number of ticks that passed */
WriteDelta();
/* Write out the command */
if(D0!=LastMsg) { LastMsg=D0;fputc(D0,MIDIOut); }
/* Write out the arguments */
if(D1<128)
{
fputc(D1,MIDIOut);
if(D2<128) fputc(D2,MIDIOut);
}
}
/** NoteOn() *************************************************/
/** Turn on a note on a given channel. **/
/*************************************************************/
void NoteOn(byte Channel,byte Note,byte Level)
{
Note = Note>0x7F? 0x7F:Note;
Level = Level>0x7F? 0x7F:Level;
if((CH[Channel].Note!=Note)||(CH[Channel].Level!=Level))
{
if(CH[Channel].Note>=0) NoteOff(Channel);
MIDIMessage(0x90+SHIFT(Channel),Note,Level);
CH[Channel].Note=Note;
CH[Channel].Level=Level;
}
}
/** NoteOff() ************************************************/
/** Turn off a note on a given channel. **/
/*************************************************************/
void NoteOff(byte Channel)
{
if(CH[Channel].Note>=0)
{
MIDIMessage(0x80+SHIFT(Channel),CH[Channel].Note,127);
CH[Channel].Note=-1;
}
}
/** WriteDelta() *********************************************/
/** Write number of ticks since the last MIDI command and **/
/** reset the counter. **/
/*************************************************************/
void WriteDelta(void)
{
if(TickCount<128) fputc(TickCount,MIDIOut);
else
{
if(TickCount<128*128)
{
fputc((TickCount>>7)|0x80,MIDIOut);
fputc(TickCount&0x7F,MIDIOut);
}
else
{
fputc(((TickCount>>14)&0x7F)|0x80,MIDIOut);
fputc(((TickCount>>7)&0x7F)|0x80,MIDIOut);
fputc(TickCount&0x7F,MIDIOut);
}
}
TickCount=0;
}
/** WriteTempo() *********************************************/
/** Write out soundtrack tempo (Hz). **/
/*************************************************************/
void WriteTempo(int Freq)
{
int J;
J=500000*MIDI_DIVISIONS*2/Freq;
WriteDelta();
fputc(0xFF,MIDIOut);
fputc(0x51,MIDIOut);
fputc(0x03,MIDIOut);
fputc((J>>16)&0xFF,MIDIOut);
fputc((J>>8)&0xFF,MIDIOut);
fputc(J&0xFF,MIDIOut);
}

10
src/apu/apu.c Normal file
View File

@ -0,0 +1,10 @@
/*
* APU emulation - The peTI-NESulator Project
* apu.c
*
* Created by Manoël Trapier.
* Copyright (c) 2002-2019 986-Studio.
*
*/
/* Empty, for now */

View File

@ -1,14 +1,9 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
if (COVERALLS) if (COVERALLS)
set(COVERAGE_SRCS src/corecpu/corecpu.c ${COVERAGE_SRCS} PARENT_SCOPE) set(COVERAGE_SRCS src/corecpu/corecpu.c ${COVERAGE_SRCS} PARENT_SCOPE)
endif() endif()

View File

@ -1,838 +0,0 @@
/** M6502: portable 6502 emulator ****************************/
/** **/
/** Codes.h **/
/** **/
/** This file contains implementation for the main table of **/
/** 6502 commands. It is included from 6502.c. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2002 **/
/** Alex Krasivsky 1996 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
/*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*/
case 0x10:
if (R->P & N_FLAG)
R->PC.W++;
else
{
M_JR;
} break; /* BPL * REL */
case 0x30:
if (R->P & N_FLAG)
{
M_JR;
}
else
R->PC.W++;
break; /* BMI * REL */
case 0xD0:
if (R->P & Z_FLAG)
R->PC.W++;
else
{
M_JR;
} break; /* BNE * REL */
case 0xF0:
if (R->P & Z_FLAG)
{
M_JR;
}
else
R->PC.W++;
break; /* BEQ * REL */
case 0x90:
if (R->P & C_FLAG)
R->PC.W++;
else
{
M_JR;
} break; /* BCC * REL */
case 0xB0:
if (R->P & C_FLAG)
{
M_JR;
}
else
R->PC.W++;
break; /* BCS * REL */
case 0x50:
if (R->P & V_FLAG)
R->PC.W++;
else
{
M_JR;
} break; /* BVC * REL */
case 0x70:
if (R->P & V_FLAG)
{
M_JR;
}
else
R->PC.W++;
break; /* BVS * REL */
/* RTI */
case 0x40:
M_POP(R->P);
//R->P |= R_FLAG;
M_POP(R->PC.B.l);
M_POP(R->PC.B.h);
break;
/* RTS */
case 0x60:
M_POP(R->PC.B.l);
M_POP(R->PC.B.h);
R->PC.W++;
break;
/* JSR $ssss ABS */
case 0x20:
K.B.l = Op6502(R->PC.W++);
K.B.h = Op6502(R->PC.W);
M_PUSH(R->PC.B.h);
M_PUSH(R->PC.B.l);
R->PC = K;
break;
/* JMP $ssss ABS */
case 0x4C:
M_LDWORD(K);
R->PC = K;
break;
/* JMP ($ssss) ABDINDIR */
case 0x6C:
M_LDWORD(K);
R->PC.B.l = Rd6502(K.W);
K.B.l++;
R->PC.B.h = Rd6502(K.W);
break;
/* BRK */
case 0x00:
R->PC.W++;
M_PUSH(R->PC.B.h);
M_PUSH(R->PC.B.l);
M_PUSH(R->P | B_FLAG);
R->P = (R->P | I_FLAG) & ~D_FLAG;
R->PC.B.l = Rd6502(0xFFFE);
R->PC.B.h = Rd6502(0xFFFF);
break;
/* CLI */
case 0x58:
if ((R->IRequest != INT_NONE) && (R->P & I_FLAG))
{
R->AfterCLI = 1;
R->IBackup = R->ICount;
R->ICount = 1;
}
R->P &= ~I_FLAG;
break;
/* PLP */
case 0x28:
M_POP(I);
if ((R->IRequest != INT_NONE) && ((I ^ R->P) & ~I & I_FLAG))
{
R->AfterCLI = 1;
R->IBackup = R->ICount;
R->ICount = 1;
}
R->P = I /*| R_FLAG*/ | B_FLAG;
break;
case 0x08:
M_PUSH(R->P);
break; /* PHP */
case 0x18:
R->P &= ~C_FLAG;
break; /* CLC */
case 0xB8:
R->P &= ~V_FLAG;
break; /* CLV */
case 0xD8:
R->P &= ~D_FLAG;
break; /* CLD */
case 0x38:
R->P |= C_FLAG;
break; /* SEC */
case 0xF8:
R->P |= D_FLAG;
break; /* SED */
case 0x78:
R->P |= I_FLAG;
break; /* SEI */
case 0x48:
M_PUSH(R->A);
break; /* PHA */
case 0x68:
M_POP(R->A);
M_FL(R->A);
break; /* PLA */
case 0x98:
R->A = R->Y;
M_FL(R->A);
break; /* TYA */
case 0xA8:
R->Y = R->A;
M_FL(R->Y);
break; /* TAY */
case 0xC8:
R->Y++;
M_FL(R->Y);
break; /* INY */
case 0x88:
R->Y--;
M_FL(R->Y);
break; /* DEY */
case 0x8A:
R->A = R->X;
M_FL(R->A);
break; /* TXA */
case 0xAA:
R->X = R->A;
M_FL(R->X);
break; /* TAX */
case 0xE8:
R->X++;
M_FL(R->X);
break; /* INX */
case 0xCA:
R->X--;
M_FL(R->X);
break; /* DEX */
default: /* In CMOS version unrecognized instructions are concidered as
NOP */
case 0xEA:
break; /* NOP */
case 0x9A:
R->S = R->X;
break; /* TXS */
case 0xBA:
R->X = R->S;
M_FL(R->X);
break; /* TSX */
case 0x24:
MR_Zp(I);
M_BIT(I);
break; /* BIT $ss ZP */
case 0x2C:
MR_Ab(I);
M_BIT(I);
break; /* BIT $ssss ABS */
case 0x05:
MR_Zp(I);
M_ORA(I);
break; /* ORA $ss ZP */
case 0x06:
MM_Zp(M_ASL);
break; /* ASL $ss ZP */
case 0x25:
MR_Zp(I);
M_AND(I);
break; /* AND $ss ZP */
case 0x26:
MM_Zp(M_ROL);
break; /* ROL $ss ZP */
case 0x45:
MR_Zp(I);
M_EOR(I);
break; /* EOR $ss ZP */
case 0x46:
MM_Zp(M_LSR);
break; /* LSR $ss ZP */
case 0x65:
MR_Zp(I);
M_ADC(I);
break; /* ADC $ss ZP */
case 0x66:
MM_Zp(M_ROR);
break; /* ROR $ss ZP */
case 0x84:
MW_Zp(R->Y);
break; /* STY $ss ZP */
case 0x85:
MW_Zp(R->A);
break; /* STA $ss ZP */
case 0x86:
MW_Zp(R->X);
break; /* STX $ss ZP */
case 0xA4:
MR_Zp(R->Y);
M_FL(R->Y);
break; /* LDY $ss ZP */
case 0xA5:
MR_Zp(R->A);
M_FL(R->A);
break; /* LDA $ss ZP */
case 0xA6:
MR_Zp(R->X);
M_FL(R->X);
break; /* LDX $ss ZP */
case 0xC4:
MR_Zp(I);
M_CMP(R->Y, I);
break; /* CPY $ss ZP */
case 0xC5:
MR_Zp(I);
M_CMP(R->A, I);
break; /* CMP $ss ZP */
case 0xC6:
MM_Zp(M_DEC);
break; /* DEC $ss ZP */
case 0xE4:
MR_Zp(I);
M_CMP(R->X, I);
break; /* CPX $ss ZP */
case 0xE5:
MR_Zp(I);
M_SBC(I);
break; /* SBC $ss ZP */
case 0xE6:
MM_Zp(M_INC);
break; /* INC $ss ZP */
case 0x0D:
MR_Ab(I);
M_ORA(I);
break; /* ORA $ssss ABS */
case 0x0E:
MM_Ab(M_ASL);
break; /* ASL $ssss ABS */
case 0x2D:
MR_Ab(I);
M_AND(I);
break; /* AND $ssss ABS */
case 0x2E:
MM_Ab(M_ROL);
break; /* ROL $ssss ABS */
case 0x4D:
MR_Ab(I);
M_EOR(I);
break; /* EOR $ssss ABS */
case 0x4E:
MM_Ab(M_LSR);
break; /* LSR $ssss ABS */
case 0x6D:
MR_Ab(I);
M_ADC(I);
break; /* ADC $ssss ABS */
case 0x6E:
MM_Ab(M_ROR);
break; /* ROR $ssss ABS */
case 0x8C:
MW_Ab(R->Y);
break; /* STY $ssss ABS */
case 0x8D:
MW_Ab(R->A);
break; /* STA $ssss ABS */
case 0x8E:
MW_Ab(R->X);
break; /* STX $ssss ABS */
case 0xAC:
MR_Ab(R->Y);
M_FL(R->Y);
break; /* LDY $ssss ABS */
case 0xAD:
MR_Ab(R->A);
M_FL(R->A);
break; /* LDA $ssss ABS */
case 0xAE:
MR_Ab(R->X);
M_FL(R->X);
break; /* LDX $ssss ABS */
case 0xCC:
MR_Ab(I);
M_CMP(R->Y, I);
break; /* CPY $ssss ABS */
case 0xCD:
MR_Ab(I);
M_CMP(R->A, I);
break; /* CMP $ssss ABS */
case 0xCE:
MM_Ab(M_DEC);
break; /* DEC $ssss ABS */
case 0xEC:
MR_Ab(I);
M_CMP(R->X, I);
break; /* CPX $ssss ABS */
case 0xED:
MR_Ab(I);
M_SBC(I);
break; /* SBC $ssss ABS */
case 0xEE:
MM_Ab(M_INC);
break; /* INC $ssss ABS */
case 0x09:
MR_Im(I);
M_ORA(I);
break; /* ORA #$ss IMM */
case 0x29:
MR_Im(I);
M_AND(I);
break; /* AND #$ss IMM */
case 0x49:
MR_Im(I);
M_EOR(I);
break; /* EOR #$ss IMM */
case 0x69:
MR_Im(I);
M_ADC(I);
break; /* ADC #$ss IMM */
case 0xA0:
MR_Im(R->Y);
M_FL(R->Y);
break; /* LDY #$ss IMM */
case 0xA2:
MR_Im(R->X);
M_FL(R->X);
break; /* LDX #$ss IMM */
case 0xA9:
MR_Im(R->A);
M_FL(R->A);
break; /* LDA #$ss IMM */
case 0xC0:
MR_Im(I);
M_CMP(R->Y, I);
break; /* CPY #$ss IMM */
case 0xC9:
MR_Im(I);
M_CMP(R->A, I);
break; /* CMP #$ss IMM */
case 0xE0:
MR_Im(I);
M_CMP(R->X, I);
break; /* CPX #$ss IMM */
case 0xE9:
MR_Im(I);
M_SBC(I);
break; /* SBC #$ss IMM */
case 0x15:
MR_Zx(I);
M_ORA(I);
break; /* ORA $ss,x ZP,x */
case 0x16:
MM_Zx(M_ASL);
break; /* ASL $ss,x ZP,x */
case 0x35:
MR_Zx(I);
M_AND(I);
break; /* AND $ss,x ZP,x */
case 0x36:
MM_Zx(M_ROL);
break; /* ROL $ss,x ZP,x */
case 0x55:
MR_Zx(I);
M_EOR(I);
break; /* EOR $ss,x ZP,x */
case 0x56:
MM_Zx(M_LSR);
break; /* LSR $ss,x ZP,x */
case 0x75:
MR_Zx(I);
M_ADC(I);
break; /* ADC $ss,x ZP,x */
case 0x76:
MM_Zx(M_ROR);
break; /* ROR $ss,x ZP,x */
case 0x94:
MW_Zx(R->Y);
break; /* STY $ss,x ZP,x */
case 0x95:
MW_Zx(R->A);
break; /* STA $ss,x ZP,x */
case 0x96:
MW_Zy(R->X);
break; /* STX $ss,y ZP,y */
case 0xB4:
MR_Zx(R->Y);
M_FL(R->Y);
break; /* LDY $ss,x ZP,x */
case 0xB5:
MR_Zx(R->A);
M_FL(R->A);
break; /* LDA $ss,x ZP,x */
case 0xB6:
MR_Zy(R->X);
M_FL(R->X);
break; /* LDX $ss,y ZP,y */
case 0xD5:
MR_Zx(I);
M_CMP(R->A, I);
break; /* CMP $ss,x ZP,x */
case 0xD6:
MM_Zx(M_DEC);
break; /* DEC $ss,x ZP,x */
case 0xF5:
MR_Zx(I);
M_SBC(I);
break; /* SBC $ss,x ZP,x */
case 0xF6:
MM_Zx(M_INC);
break; /* INC $ss,x ZP,x */
case 0x19:
MR_Ay(I);
M_ORA(I);
break; /* ORA $ssss,y ABS,y */
case 0x1D:
MR_Ax(I);
M_ORA(I);
break; /* ORA $ssss,x ABS,x */
case 0x1E:
MM_Ax(M_ASL);
break; /* ASL $ssss,x ABS,x */
case 0x39:
MR_Ay(I);
M_AND(I);
break; /* AND $ssss,y ABS,y */
case 0x3D:
MR_Ax(I);
M_AND(I);
break; /* AND $ssss,x ABS,x */
case 0x3E:
MM_Ax(M_ROL);
break; /* ROL $ssss,x ABS,x */
case 0x59:
MR_Ay(I);
M_EOR(I);
break; /* EOR $ssss,y ABS,y */
case 0x5D:
MR_Ax(I);
M_EOR(I);
break; /* EOR $ssss,x ABS,x */
case 0x5E:
MM_Ax(M_LSR);
break; /* LSR $ssss,x ABS,x */
case 0x79:
MR_Ay(I);
M_ADC(I);
break; /* ADC $ssss,y ABS,y */
case 0x7D:
MR_Ax(I);
M_ADC(I);
break; /* ADC $ssss,x ABS,x */
case 0x7E:
MM_Ax(M_ROR);
break; /* ROR $ssss,x ABS,x */
case 0x99:
MW_Ay(R->A);
break; /* STA $ssss,y ABS,y */
case 0x9D:
MW_Ax(R->A);
break; /* STA $ssss,x ABS,x */
case 0xB9:
MR_Ay(R->A);
M_FL(R->A);
break; /* LDA $ssss,y ABS,y */
case 0xBC:
MR_Ax(R->Y);
M_FL(R->Y);
break; /* LDY $ssss,x ABS,x */
case 0xBD:
MR_Ax(R->A);
M_FL(R->A);
break; /* LDA $ssss,x ABS,x */
case 0xBE:
MR_Ay(R->X);
M_FL(R->X);
break; /* LDX $ssss,y ABS,y */
case 0xD9:
MR_Ay(I);
M_CMP(R->A, I);
break; /* CMP $ssss,y ABS,y */
case 0xDD:
MR_Ax(I);
M_CMP(R->A, I);
break; /* CMP $ssss,x ABS,x */
case 0xDE:
MM_Ax(M_DEC);
break; /* DEC $ssss,x ABS,x */
case 0xF9:
MR_Ay(I);
M_SBC(I);
break; /* SBC $ssss,y ABS,y */
case 0xFD:
MR_Ax(I);
M_SBC(I);
break; /* SBC $ssss,x ABS,x */
case 0xFE:
MM_Ax(M_INC);
break; /* INC $ssss,x ABS,x */
case 0x01:
MR_Ix(I);
M_ORA(I);
break; /* ORA ($ss,x) INDEXINDIR */
case 0x11:
MR_Iy(I);
M_ORA(I);
break; /* ORA ($ss),y INDIRINDEX */
case 0x21:
MR_Ix(I);
M_AND(I);
break; /* AND ($ss,x) INDEXINDIR */
case 0x31:
MR_Iy(I);
M_AND(I);
break; /* AND ($ss),y INDIRINDEX */
case 0x41:
MR_Ix(I);
M_EOR(I);
break; /* EOR ($ss,x) INDEXINDIR */
case 0x51:
MR_Iy(I);
M_EOR(I);
break; /* EOR ($ss),y INDIRINDEX */
case 0x61:
MR_Ix(I);
M_ADC(I);
break; /* ADC ($ss,x) INDEXINDIR */
case 0x71:
MR_Iy(I);
M_ADC(I);
break; /* ADC ($ss),y INDIRINDEX */
case 0x81:
MW_Ix(R->A);
break; /* STA ($ss,x) INDEXINDIR */
case 0x91:
MW_Iy(R->A);
break; /* STA ($ss),y INDIRINDEX */
case 0xA1:
MR_Ix(R->A);
M_FL(R->A);
break; /* LDA ($ss,x) INDEXINDIR */
case 0xB1:
MR_Iy(R->A);
M_FL(R->A);
break; /* LDA ($ss),y INDIRINDEX */
case 0xC1:
MR_Ix(I);
M_CMP(R->A, I);
break; /* CMP ($ss,x) INDEXINDIR */
case 0xD1:
MR_Iy(I);
M_CMP(R->A, I);
break; /* CMP ($ss),y INDIRINDEX */
case 0xE1:
MR_Ix(I);
M_SBC(I);
break; /* SBC ($ss,x) INDEXINDIR */
case 0xF1:
MR_Iy(I);
M_SBC(I);
break; /* SBC ($ss),y INDIRINDEX */
case 0x0A:
M_ASL(R->A);
break; /* ASL a ACC */
case 0x2A:
M_ROL(R->A);
break; /* ROL a ACC */
case 0x4A:
M_LSR(R->A);
break; /* LSR a ACC */
case 0x6A:
M_ROR(R->A);
break; /* ROR a ACC */

View File

@ -1,482 +0,0 @@
/** M6502: portable 6502 emulator ****************************/
/** **/
/** Debug.c **/
/** **/
/** This file contains the built-in debugging routine for **/
/** the 6502 emulator which is called on each 6502 step **/
/** when Trap!=0. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-1997 **/
/** Alex Krasivsky 1996 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
/*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*/
#include "M6502.h"
#ifdef DEBUG
#include <allegro.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <ppu/ppu.h>
#include <mappers/manager.h>
#include <memory/manager.h>
#include <Sound.h>
#define RDWORD(A) (Rd6502(A+1)*256+Rd6502(A))
extern unsigned char *Memory;
void showlastop();
enum Addressing_Modes
{
Ac = 0, Il, Im, Ab, Zp, Zx, Zy, Ax, Ay, Rl, Ix, Iy, In, No
};
static char *mn[] =
{
"adc ", "and ", "asl ", "bcc ", "bcs ", "beq ", "bit ", "bmi ",
"bne ", "bpl ", "brk", "bvc ", "bvs ", "clc", "cld", "cli",
"clv", "cmp ", "cpx ", "cpy ", "dec ", "dex", "dey", "inx",
"iny", "eor ", "inc ", "jmp ", "jsr ", "lda ", "nop ", "ldx ",
"ldy ", "lsr ", "ora ", "pha", "php", "pla", "plp", "rol ",
"ror ", "rti", "rts", "sbc ", "sta ", "stx ", "sty ", "sec ",
"sed", "sei", "tax", "tay", "txa", "tya", "tsx", "txs"
};
static byte ad[512] =
{
10, Il, 34, Ix, No, No, No, No, No, No, 34, Zp, 2, Zp, No, No,
36, Il, 34, Im, 2, Ac, No, No, No, No, 34, Ab, 2, Ab, No, No,
9, Rl, 34, Iy, No, No, No, No, No, No, 34, Zx, 2, Zx, No, No,
13, Il, 34, Ay, No, No, No, No, No, No, 34, Ax, 2, Ax, No, No,
28, Ab, 1, Ix, No, No, No, No, 6, Zp, 1, Zp, 39, Zp, No, No,
38, Il, 1, Im, 39, Ac, No, No, 6, Ab, 1, Ab, 39, Ab, No, No,
7, Rl, 1, Iy, No, No, No, No, No, No, 1, Zx, 39, Zx, No, No,
47, Il, 1, Ay, No, No, No, No, No, No, 1, Ax, 39, Ax, No, No,
41, Il, 25, Ix, No, No, No, No, No, No, 25, Zp, 33, Zp, No, No,
35, Il, 25, Im, 33, Ac, No, No, 27, Ab, 25, Ab, 33, Ab, No, No,
11, Rl, 25, Iy, No, No, No, No, No, No, 25, Zx, 33, Zx, No, No,
15, Il, 25, Ay, No, No, No, No, No, No, 25, Ax, 33, Ax, No, No,
42, Il, 0, Ix, No, No, No, No, No, No, 0, Zp, 40, Zp, No, No,
37, Il, 0, Im, 40, Ac, No, No, 27, In, 0, Ab, 40, Ab, No, No,
12, Rl, 0, Iy, No, No, No, No, No, No, 0, Zx, 40, Zx, No, No,
49, Il, 0, Ay, No, No, No, No, No, No, 0, Ax, 40, Ax, No, No,
No, No, 44, Ix, No, No, No, No, 46, Zp, 44, Zp, 45, Zp, No, No,
22, Il, No, No, 52, Il, No, No, 46, Ab, 44, Ab, 45, Ab, No, No,
3, Rl, 44, Iy, No, No, No, No, 46, Zx, 44, Zx, 45, Zy, No, No,
53, Il, 44, Ay, 55, Il, No, No, No, No, 44, Ax, No, No, No, No,
32, Im, 29, Ix, 31, Im, No, No, 32, Zp, 29, Zp, 31, Zp, No, No,
51, Il, 29, Im, 50, Il, No, No, 32, Ab, 29, Ab, 31, Ab, No, No,
4, Rl, 29, Iy, No, No, No, No, 32, Zx, 29, Zx, 31, Zy, No, No,
16, Il, 29, Ay, 54, Il, No, No, 32, Ax, 29, Ax, 31, Ay, No, No,
19, Im, 17, Ix, No, No, No, No, 19, Zp, 17, Zp, 20, Zp, No, No,
24, Il, 17, Im, 21, Il, No, No, 19, Ab, 17, Ab, 20, Ab, No, No,
8, Rl, 17, Iy, No, No, No, No, No, No, 17, Zx, 20, Zx, No, No,
14, Il, 17, Ay, No, No, No, No, No, No, 17, Ax, 20, Ax, No, No,
18, Im, 43, Ix, No, No, No, No, 18, Zp, 43, Zp, 26, Zp, No, No,
23, Il, 43, Im, 30, Il, No, No, 18, Ab, 43, Ab, 26, Ab, No, No,
5, Rl, 43, Iy, No, No, No, No, No, No, 43, Zx, 26, Zx, No, No,
48, Il, 43, Ay, No, No, No, No, No, No, 43, Ax, 26, Ax, No, No
};
/** DAsm() ****************************************************/
/** This function will disassemble a single command and **/
/** return the number of bytes disassembled. **/
/**************************************************************/
int DAsm(char *S, word A)
{
byte J;
word B, OP, TO;
B = A;
OP = Rd6502(B++) * 2;
switch (ad[OP + 1])
{
case Ac:
sprintf(S, "%s a", mn[ad[OP]]);
break;
case Il:
sprintf(S, "%s", mn[ad[OP]]);
break;
case Rl:
J = Rd6502(B++);
TO = A + 2 + ((J < 0x80) ? J : (J - 256));
sprintf(S, "%s $%04X", mn[ad[OP]], TO);
break;
case Im:
sprintf(S, "%s #$%02X", mn[ad[OP]], Rd6502(B++));
break;
case Zp:
sprintf(S, "%s $%02X", mn[ad[OP]], Rd6502(B++));
break;
case Zx:
sprintf(S, "%s $%02X,x", mn[ad[OP]], Rd6502(B++));
break;
case Zy:
sprintf(S, "%s $%02X,y", mn[ad[OP]], Rd6502(B++));
break;
case Ix:
sprintf(S, "%s ($%02X,x)", mn[ad[OP]], Rd6502(B++));
break;
case Iy:
sprintf(S, "%s ($%02X),y", mn[ad[OP]], Rd6502(B++));
break;
case Ab:
sprintf(S, "%s $%04X", mn[ad[OP]], RDWORD(B));
B += 2;
break;
case Ax:
sprintf(S, "%s $%04X,x", mn[ad[OP]], RDWORD(B));
B += 2;
break;
case Ay:
sprintf(S, "%s $%04X,y", mn[ad[OP]], RDWORD(B));
B += 2;
break;
case In:
sprintf(S, "%s ($%04X)", mn[ad[OP]], RDWORD(B));
B += 2;
break;
default:
sprintf(S, ".db $%02X; <Invalid OPcode>", OP / 2);
}
return (B - A);
}
/** Debug6502() **********************************************/
/** This function should exist if DEBUG is #defined. When **/
/** Trace!=0, it is called after each command executed by **/
/** the CPU, and given the 6502 registers. Emulation exits **/
/** if Debug6502() returns 0. **/
/*************************************************************/
byte Debug6502(M6502 * R)
{
static char FA[8] = "NVRBDIZC";
char S[128];
byte F;
int J, I;
DAsm(S, R->PC.W);
printf
(
"A:%02X P:%02X X:%02X Y:%02X S:%04X PC:%04X Flags:[",
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)
printf("%c", F & 0x80 ? FA[J] : '.');
puts("]");
printf
(
"AT PC: [%02X - %s] AT SP: [%02X %02X %02X]\n",
Rd6502(R->PC.W), S,
Rd6502(0x0100 + (byte) (R->S + 1)),
Rd6502(0x0100 + (byte) (R->S + 2)),
Rd6502(0x0100 + (byte) (R->S + 3))
);
S[0] = 0;
remove_keyboard();
#ifdef USE_SOUND
StopSound();
#endif
while (1)
{
printf("\n[Command,'?']-> ");
fflush(stdout);
fflush(stdin);
fgets(S, 50, stdin);
for (J = 0; S[J] >= ' '; J++)
S[J] = toupper(S[J]);
S[J] = '\0';
switch (S[0])
{
case 'H':
case '?':
puts("\n***** Built-in 6502 Debugger Commands *****");
puts("<CR> : Break at the next instruction");
puts("= <addr> : Break at addr");
puts("+ <offset> : Break at PC + offset");
puts("t <addr> : Set PC to addr");
puts("c : Continue without break");
puts("j <addr> : Continue from addr");
puts("m <addr> : Memory dump at addr");
puts("d <addr> : Disassembly at addr");
puts("v : Show ;interrupt vectors");
puts("?,h : Show this help text");
puts("r : Show Register Status");
puts("q : Exit 6502 emulation");
puts("----- TI-NES Specific -----");
puts("w : Dump Memory State");
puts("o : Show PPU registers");
puts("p <addr> : Dump PPU memory at addr");
puts("a : Dump all memory to memory.log");
puts("s : Dump sprite table to sprite.log");
puts("n <nb> : Dump name table <nb> to nt.log");
puts("z : Dump mapper status");
puts("i : SpriteTable Dump");
puts("g <nb> : Get sprite <nb> info");
break;
case '\0':
return (1);
case 'Z':
mapper_dump(stdout);
break;
case 'W':
DumpMemoryState(stdout);
break;
case 'A':
{
FILE * fpDmpMem;
if ((fpDmpMem = fopen("memory.log", "wb")) != NULL)
{
// fwrite(Memory, 1, 0x8000, fpDmpMem);
//fwrite(mLBank, 1, 0x4000, fpDmpMem);
//fwrite(mUBank, 1, 0x4000, fpDmpMem);
fclose(fpDmpMem);
}
}
break;
case '=':
if (strlen(S) >= 2)
{
sscanf(S + 1, "%hX", &(R->Trap));
R->Trace = 0;
return (1);
}
break;
case '+':
if (strlen(S) >= 2)
{
sscanf(S + 1, "%hX", &(R->Trap));
R->Trap += R->PC.W;
R->Trace = 0;
return (1);
}
break;
case 'J':
if (strlen(S) >= 2)
{
sscanf(S + 1, "%hX", &(R->PC.W));
R->Trace = 0;
return (1);
}
break;
case 'T':
if (strlen(S) >= 2)
{
sscanf(S + 1, "%hX", &(R->PC.W));
R->Trace = 1;
}
break;
case 'C':
R->Trap = 0xFFFF;
R->Trace = 0;
install_keyboard();
//ResumeSound();
SetSound(0, SND_RECTANGLE);
SetSound(1, SND_RECTANGLE);
SetSound(2, SND_TRIANGLE);
SetSound(3, SND_NOISE);
return (1);
case 'Q':
return (0);
case 'V':
puts("\n6502 Interrupt Vectors:");
printf("[$FFFC] INIT: $%04X\n", Rd6502(0xFFFC) + 256 * Rd6502(0xFFFD));
printf("[$FFFE] IRQ: $%04X\n", Rd6502(0xFFFE) + 256 * Rd6502(0xFFFF));
printf("[$FFFA] NMI: $%04X\n", Rd6502(0xFFFA) + 256 * Rd6502(0xFFFB));
break;
case 'M':
{
word Addr;
if (strlen(S) > 1)
sscanf(S + 1, "%hX", &Addr);
else
Addr = R->PC.W;
puts("");
for (J = 0; J < 16; J++)
{
printf("%04X: ", Addr);
for (I = 0; I < 16; I++, Addr++)
printf("%02X ", Rd6502(Addr));
printf(" | ");
Addr -= 16;
for (I = 0; I < 16; I++, Addr++)
putchar(isprint(Rd6502(Addr)) ? Rd6502(Addr) : '.');
puts("");
}
}
break;
case 'R':
printf
(
"A:%02X P:%02X X:%02X Y:%02X S:%04X PC:%04X Flags:[",
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)
printf("%c", F & 0x80 ? FA[J] : '.');
puts("]");
printf
(
"AT PC: [%02X - %s] AT SP: [%02X %02X %02X]\n",
Rd6502(R->PC.W), S,
Rd6502(0x0100 + (byte) (R->S + 1)),
Rd6502(0x0100 + (byte) (R->S + 2)),
Rd6502(0x0100 + (byte) (R->S + 3))
);
break;
case 'D':
{
word Addr;
if (strlen(S) > 1)
sscanf(S + 1, "%hX", &Addr);
else
Addr = R->PC.W;
puts("");
for (J = 0; J < 16; J++)
{
printf("%04X: ", Addr);
Addr += DAsm(S, Addr);
puts(S);
}
}
break;
}
}
/* Continue with emulation */
return (1);
}
#endif /* DEBUG */

View File

@ -1,516 +0,0 @@
/** M6502: portable 6502 emulator ****************************/
/** **/
/** M6502.c **/
/** **/
/** This file contains implementation for 6502 CPU. Don't **/
/** forget to provide Rd6502(), Wr6502(), Loop6502(), and **/
/** possibly Op6502() functions to accomodate the emulated **/
/** machine's architecture. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2002 **/
/** Alex Krasivsky 1996 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
/*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*/
#include "M6502.h"
#include "Tables.h"
#include <stdio.h>
/** INLINE ***************************************************/
/** Different compilers inline C functions differently. **/
/*************************************************************/
#ifdef __GNUC__
#define INLINE inline
#else
#define INLINE static
#endif
int icount = 0;
/** System-Dependent Stuff ***********************************/
/** This is system-dependent code put here to speed things **/
/** up. It has to stay inlined to be fast. **/
/*************************************************************/
#ifdef INES
#define FAST_RDOP
extern byte *Page[];
INLINE byte Op6502(register word A) { return(Page[A>>13][A&0x1FFF]); }
#endif
/** FAST_RDOP ************************************************/
/** With this #define not present, Rd6502() should perform **/
/** the functions of Rd6502(). **/
/*************************************************************/
#ifndef FAST_RDOP
#define Op6502(A) Rd6502(A)
#endif
/** Addressing Methods ***************************************/
/** These macros calculate and return effective addresses. **/
/*************************************************************/
#define MC_Ab(Rg) M_LDWORD(Rg)
#define MC_Zp(Rg) Rg.W=Op6502(R->PC.W++)
#define MC_Zx(Rg) Rg.W=(byte)(Op6502(R->PC.W++)+R->X)
#define MC_Zy(Rg) Rg.W=(byte)(Op6502(R->PC.W++)+R->Y)
#define MC_Ax(Rg) M_LDWORD(Rg);Rg.W+=R->X
#define MC_Ay(Rg) M_LDWORD(Rg);Rg.W+=R->Y
#define MC_Ix(Rg) K.W=(byte)(Op6502(R->PC.W++)+R->X); \
Rg.B.l=Op6502(K.W++);Rg.B.h=Op6502(K.W)
#define MC_Iy(Rg) K.W=Op6502(R->PC.W++); \
Rg.B.l=Op6502(K.W++);Rg.B.h=Op6502(K.W); \
Rg.W+=R->Y
/** Reading From Memory **************************************/
/** These macros calculate address and read from it. **/
/*************************************************************/
#define MR_Ab(Rg) MC_Ab(J);Rg=Rd6502(J.W)
#define MR_Im(Rg) Rg=Op6502(R->PC.W++)
#define MR_Zp(Rg) MC_Zp(J);Rg=Rd6502(J.W)
#define MR_Zx(Rg) MC_Zx(J);Rg=Rd6502(J.W)
#define MR_Zy(Rg) MC_Zy(J);Rg=Rd6502(J.W)
#define MR_Ax(Rg) MC_Ax(J);Rg=Rd6502(J.W)
#define MR_Ay(Rg) MC_Ay(J);Rg=Rd6502(J.W)
#define MR_Ix(Rg) MC_Ix(J);Rg=Rd6502(J.W)
#define MR_Iy(Rg) MC_Iy(J);Rg=Rd6502(J.W)
/** Writing To Memory ****************************************/
/** These macros calculate address and write to it. **/
/*************************************************************/
#define MW_Ab(Rg) MC_Ab(J);Wr6502(J.W,Rg)
#define MW_Zp(Rg) MC_Zp(J);Wr6502(J.W,Rg)
#define MW_Zx(Rg) MC_Zx(J);Wr6502(J.W,Rg)
#define MW_Zy(Rg) MC_Zy(J);Wr6502(J.W,Rg)
#define MW_Ax(Rg) MC_Ax(J);Wr6502(J.W,Rg)
#define MW_Ay(Rg) MC_Ay(J);Wr6502(J.W,Rg)
#define MW_Ix(Rg) MC_Ix(J);Wr6502(J.W,Rg)
#define MW_Iy(Rg) MC_Iy(J);Wr6502(J.W,Rg)
/** Modifying Memory *****************************************/
/** These macros calculate address and modify it. **/
/*************************************************************/
#define MM_Ab(Cmd) MC_Ab(J);I=Rd6502(J.W);Cmd(I);Wr6502(J.W,I)
#define MM_Zp(Cmd) MC_Zp(J);I=Rd6502(J.W);Cmd(I);Wr6502(J.W,I)
#define MM_Zx(Cmd) MC_Zx(J);I=Rd6502(J.W);Cmd(I);Wr6502(J.W,I)
#define MM_Ax(Cmd) MC_Ax(J);I=Rd6502(J.W);Cmd(I);Wr6502(J.W,I)
/** Other Macros *********************************************/
/** Calculating flags, stack, jumps, arithmetics, etc. **/
/*************************************************************/
#define M_FL(Rg) R->P=(R->P&~(Z_FLAG|N_FLAG))|ZNTable[Rg]
#define M_LDWORD(Rg) Rg.B.l=Op6502(R->PC.W++);Rg.B.h=Op6502(R->PC.W++)
#define M_PUSH(Rg) Wr6502(0x0100|R->S,Rg);R->S--
#define M_POP(Rg) R->S++;Rg=Op6502(0x0100|R->S)
#define M_JR R->PC.W+=(offset)Op6502(R->PC.W)+1;R->ICount--
#ifdef NO_DECIMAL
#define M_ADC(Rg) \
K.W=R->A+Rg+(R->P&C_FLAG); \
R->P&=~(N_FLAG|V_FLAG|Z_FLAG|C_FLAG); \
R->P|=(~(R->A^Rg)&(R->A^K.B.l)&0x80? V_FLAG:0)| \
(K.B.h? C_FLAG:0)|ZNTable[K.B.l]; \
R->A=K.B.l
/* Warning! C_FLAG is inverted before SBC and after it */
#define M_SBC(Rg) \
K.W=R->A-Rg-(~R->P&C_FLAG); \
R->P&=~(N_FLAG|V_FLAG|Z_FLAG|C_FLAG); \
R->P|=((R->A^Rg)&(R->A^K.B.l)&0x80? V_FLAG:0)| \
(K.B.h? 0:C_FLAG)|ZNTable[K.B.l]; \
R->A=K.B.l
#else /* NO_DECIMAL */
#define M_ADC(Rg) \
if(R->P&D_FLAG) \
{ \
K.B.l=(R->A&0x0F)+(Rg&0x0F)+(R->P&C_FLAG); \
if(K.B.l>9) K.B.l+=6; \
K.B.h=(R->A>>4)+(Rg>>4)+(K.B.l>15? 1:0); \
R->A=(K.B.l&0x0F)|(K.B.h<<4); \
R->P=(R->P&~C_FLAG)|(K.B.h>15? C_FLAG:0); \
} \
else \
{ \
K.W=R->A+Rg+(R->P&C_FLAG); \
R->P&=~(N_FLAG|V_FLAG|Z_FLAG|C_FLAG); \
R->P|=(~(R->A^Rg)&(R->A^K.B.l)&0x80? V_FLAG:0)| \
(K.B.h? C_FLAG:0)|ZNTable[K.B.l]; \
R->A=K.B.l; \
}
/* Warning! C_FLAG is inverted before SBC and after it */
#define M_SBC(Rg) \
if(R->P&D_FLAG) \
{ \
K.B.l=(R->A&0x0F)-(Rg&0x0F)-(~R->P&C_FLAG); \
if(K.B.l&0x10) K.B.l-=6; \
K.B.h=(R->A>>4)-(Rg>>4)-((K.B.l&0x10)>>4); \
if(K.B.h&0x10) K.B.h-=6; \
R->A=(K.B.l&0x0F)|(K.B.h<<4); \
R->P=(R->P&~C_FLAG)|(K.B.h>15? 0:C_FLAG); \
} \
else \
{ \
K.W=R->A-Rg-(~R->P&C_FLAG); \
R->P&=~(N_FLAG|V_FLAG|Z_FLAG|C_FLAG); \
R->P|=((R->A^Rg)&(R->A^K.B.l)&0x80? V_FLAG:0)| \
(K.B.h? 0:C_FLAG)|ZNTable[K.B.l]; \
R->A=K.B.l; \
}
#endif /* NO_DECIMAL */
#define M_CMP(Rg1,Rg2) \
K.W=Rg1-Rg2; \
R->P&=~(N_FLAG|Z_FLAG|C_FLAG); \
R->P|=ZNTable[K.B.l]|(K.B.h? 0:C_FLAG)
#define M_BIT(Rg) \
R->P&=~(N_FLAG|V_FLAG|Z_FLAG); \
R->P|=(Rg&(N_FLAG|V_FLAG))|(Rg&R->A? 0:Z_FLAG)
#define M_AND(Rg) R->A&=Rg;M_FL(R->A)
#define M_ORA(Rg) R->A|=Rg;M_FL(R->A)
#define M_EOR(Rg) R->A^=Rg;M_FL(R->A)
#define M_INC(Rg) Rg++;M_FL(Rg)
#define M_DEC(Rg) Rg--;M_FL(Rg)
#define M_ASL(Rg) R->P&=~C_FLAG;R->P|=Rg>>7;Rg<<=1;M_FL(Rg)
#define M_LSR(Rg) R->P&=~C_FLAG;R->P|=Rg&C_FLAG;Rg>>=1;M_FL(Rg)
#define M_ROL(Rg) K.B.l=(Rg<<1)|(R->P&C_FLAG); \
R->P&=~C_FLAG;R->P|=Rg>>7;Rg=K.B.l; \
M_FL(Rg)
#define M_ROR(Rg) K.B.l=(Rg>>1)|(R->P<<7); \
R->P&=~C_FLAG;R->P|=Rg&C_FLAG;Rg=K.B.l; \
M_FL(Rg)
/** Reset6502() **********************************************/
/** This function can be used to reset the registers before **/
/** starting execution with Run6502(). It sets registers to **/
/** their initial values. **/
/*************************************************************/
void Reset6502(M6502 *R)
{
R->A=R->X=R->Y=0x00;
R->P=Z_FLAG;
R->S=0xFF;
R->PC.B.l=Rd6502(0xFFFC);
R->PC.B.h=Rd6502(0xFFFD);
R->ICount=R->IPeriod;
R->IRequest=INT_NONE;
R->AfterCLI=0;
}
/** Exec6502() ***********************************************/
/** This function will execute a single 6502 opcode. It **/
/** will then return next PC, and current register values **/
/** in R. **/
/*************************************************************/
word Exec6502(M6502 *R)
{
register pair J,K;
register byte I;
I=Op6502(R->PC.W++);
R->ICount-=Cycles[I];
switch(I)
{
#include "Codes.h"
}
/* We are done */
return(R->PC.W);
}
/** Int6502() ************************************************/
/** This function will generate interrupt of a given type. **/
/** INT_NMI will cause a non-maskable interrupt. INT_IRQ **/
/** will cause a normal interrupt, unless I_FLAG set in R. **/
/*************************************************************/
void Int6502(M6502 *R,byte Type)
{
register pair J;
if((Type==INT_NMI)||((Type==INT_IRQ)&&!(R->P&I_FLAG)))
{
R->ICount-=7;
M_PUSH(R->PC.B.h);
M_PUSH(R->PC.B.l);
M_PUSH(R->P & ~(B_FLAG|R_FLAG));
R->P&=~D_FLAG;
if(R->IAutoReset&&(Type==R->IRequest)) R->IRequest=INT_NONE;
if(Type==INT_NMI) J.W=0xFFFA; else { R->P|=I_FLAG;J.W=0xFFFE; }
R->PC.B.l=Rd6502(J.W++);
R->PC.B.h=Rd6502(J.W);
}
}
#ifdef TRACE_EXECUTION
enum Addressing_Modes
{
Ac = 0, Il, Im, Ab, Zp, Zx, Zy, Ax, Ay, Rl, Ix, Iy, In, No
};
static char *mnCAP[] =
{
"ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI",
"BNE", "BPL", "BRK", "BVC", "BVS", "CLC", "CLD", "CLI",
"CLV", "CMP", "CPX", "CPY", "DEC", "DEX", "DEY", "INX",
"INY", "EOR", "INC", "JMP", "JSR", "LDA", "NOP", "LDX",
"LDY", "LSR", "ORA", "PHA", "PHP", "PLA", "PLP", "ROL",
"ROR", "RTI", "RTS", "SBC", "STA", "STX", "STY", "SEC",
"SED", "SEI", "TAX", "TAY", "TXA", "TYA", "TSX", "TXS"
};
#define DAsm DAsmCAP
static byte ad[512] =
{
10, Il, 34, Ix, No, No, No, No, No, No, 34, Zp, 2, Zp, No, No,
36, Il, 34, Im, 2, Ac, No, No, No, No, 34, Ab, 2, Ab, No, No,
9, Rl, 34, Iy, No, No, No, No, No, No, 34, Zx, 2, Zx, No, No,
13, Il, 34, Ay, No, No, No, No, No, No, 34, Ax, 2, Ax, No, No,
28, Ab, 1, Ix, No, No, No, No, 6, Zp, 1, Zp, 39, Zp, No, No,
38, Il, 1, Im, 39, Ac, No, No, 6, Ab, 1, Ab, 39, Ab, No, No,
7, Rl, 1, Iy, No, No, No, No, No, No, 1, Zx, 39, Zx, No, No,
47, Il, 1, Ay, No, No, No, No, No, No, 1, Ax, 39, Ax, No, No,
41, Il, 25, Ix, No, No, No, No, No, No, 25, Zp, 33, Zp, No, No,
35, Il, 25, Im, 33, Ac, No, No, 27, Ab, 25, Ab, 33, Ab, No, No,
11, Rl, 25, Iy, No, No, No, No, No, No, 25, Zx, 33, Zx, No, No,
15, Il, 25, Ay, No, No, No, No, No, No, 25, Ax, 33, Ax, No, No,
42, Il, 0, Ix, No, No, No, No, No, No, 0, Zp, 40, Zp, No, No,
37, Il, 0, Im, 40, Ac, No, No, 27, In, 0, Ab, 40, Ab, No, No,
12, Rl, 0, Iy, No, No, No, No, No, No, 0, Zx, 40, Zx, No, No,
49, Il, 0, Ay, No, No, No, No, No, No, 0, Ax, 40, Ax, No, No,
No, No, 44, Ix, No, No, No, No, 46, Zp, 44, Zp, 45, Zp, No, No,
22, Il, No, No, 52, Il, No, No, 46, Ab, 44, Ab, 45, Ab, No, No,
3, Rl, 44, Iy, No, No, No, No, 46, Zx, 44, Zx, 45, Zy, No, No,
53, Il, 44, Ay, 55, Il, No, No, No, No, 44, Ax, No, No, No, No,
32, Im, 29, Ix, 31, Im, No, No, 32, Zp, 29, Zp, 31, Zp, No, No,
51, Il, 29, Im, 50, Il, No, No, 32, Ab, 29, Ab, 31, Ab, No, No,
4, Rl, 29, Iy, No, No, No, No, 32, Zx, 29, Zx, 31, Zy, No, No,
16, Il, 29, Ay, 54, Il, No, No, 32, Ax, 29, Ax, 31, Ay, No, No,
19, Im, 17, Ix, No, No, No, No, 19, Zp, 17, Zp, 20, Zp, No, No,
24, Il, 17, Im, 21, Il, No, No, 19, Ab, 17, Ab, 20, Ab, No, No,
8, Rl, 17, Iy, No, No, No, No, No, No, 17, Zx, 20, Zx, No, No,
14, Il, 17, Ay, No, No, No, No, No, No, 17, Ax, 20, Ax, No, No,
18, Im, 43, Ix, No, No, No, No, 18, Zp, 43, Zp, 26, Zp, No, No,
23, Il, 43, Im, 30, Il, No, No, 18, Ab, 43, Ab, 26, Ab, No, No,
5, Rl, 43, Iy, No, No, No, No, No, No, 43, Zx, 26, Zx, No, No,
48, Il, 43, Ay, No, No, No, No, No, No, 43, Ax, 26, Ax, No, No
};
#define RDWORD(A) (Rd6502(A+1)*256+Rd6502(A))
/** DAsm() ****************************************************/
/** This function will disassemble a single command and **/
/** return the number of bytes disassembled. **/
/**************************************************************/
int DAsmCAP(char *S, word A)
{
byte J;
word B, OP, TO;
B = A;
OP = Rd6502(B++) * 2;
switch (ad[OP + 1])
{
case Ac:
sprintf(S, "%s A", mnCAP[ad[OP]]);
break;
case Il:
sprintf(S, "%s", mnCAP[ad[OP]]);
break;
case Rl:
J = Rd6502(B++);
TO = A + 2 + ((J < 0x80) ? J : (J - 256));
sprintf(S, "%s $%04x", mnCAP[ad[OP]], TO);
break;
case Im:
sprintf(S, "%s #$%02x", mnCAP[ad[OP]], Rd6502(B++));
break;
case Zp:
sprintf(S, "%s $%02x", mnCAP[ad[OP]], Rd6502(B++));
break;
case Zx:
sprintf(S, "%s $%02x,X", mnCAP[ad[OP]], Rd6502(B++));
break;
case Zy:
sprintf(S, "%s $%02x,Y", mnCAP[ad[OP]], Rd6502(B++));
break;
case Ix:
sprintf(S, "%s ($%02x,X)", mnCAP[ad[OP]], Rd6502(B++));
break;
case Iy:
sprintf(S, "%s ($%02x),Y", mnCAP[ad[OP]], Rd6502(B++));
break;
case Ab:
sprintf(S, "%s $%04x", mnCAP[ad[OP]], RDWORD(B));
B += 2;
break;
case Ax:
sprintf(S, "%s $%04x,X", mnCAP[ad[OP]], RDWORD(B));
B += 2;
break;
case Ay:
sprintf(S, "%s $%04x,Y", mnCAP[ad[OP]], RDWORD(B));
B += 2;
break;
case In:
sprintf(S, "%s ($%04x)", mnCAP[ad[OP]], RDWORD(B));
B += 2;
break;
default:
sprintf(S, ".db $%02x; <Invalid OPcode>", OP / 2);
}
return (B - A);
}
extern unsigned short ScanLine;
#endif
/** Run6502() ************************************************/
/** This function will run 6502 code until Loop6502() call **/
/** returns INT_QUIT. It will return the PC at which **/
/** emulation stopped, and current register values in R. **/
/*************************************************************/
word Run6502(M6502 *R)
{
register pair J,K;
register byte I;
byte nb_of_cycle;
for(;;)
{
#ifdef DEBUG
/* Turn tracing on when reached trap address */
if(R->PC.W==R->Trap) R->Trace=1;
/* Call single-step debugger, exit if requested */
if(R->Trace)
if(!Debug6502(R)) return(R->PC.W);
#endif
#ifdef TRACE_EXECUTION
while(1)
{
static char FA[8] = "NV.BDIZC";
char S[128];
byte F;
int J, I;
DAsm(S, R->PC.W);
printf
(
"AT PC: [%02x - %s]\n",
Rd6502(R->PC.W), S
);
break;
}
#endif
I=Op6502(R->PC.W++);
nb_of_cycle = Cycles[I];
//#ifdef DEBUG
// pushop(I);
//#endif
icount++;
switch(I)
{
#include "Codes.h"
}
#ifdef TRACE_EXECUTION
while(1)
{
static char FA[8] = "NV.BDIZC";
char S[128];
byte F;
int J, I;
printf
(
"A:%02x X:%02x Y:%02x S:%04x, PC:%04x Flags:[",
R->A, R->X, R->Y, R->S + 0x0100, R->PC.W
);
for (J = 0, F = R->P; J < 8; J++, F <<= 1)
printf("%c", F & 0x80 ? FA[J] : '.');
printf("], Stack[%02x, %02x, %02x], %03d, %03d\n",
Rd6502(0x0100 + (byte) (R->S + 1)),
Rd6502(0x0100 + (byte) (R->S + 2)),
Rd6502(0x0100 + (byte) (R->S + 3)),
R->ICount,
ScanLine
);
break;
}
#endif
R->ICount-= nb_of_cycle;
/* If cycle counter expired... */
if(R->ICount<=0)
{
/* If we have come after CLI, get INT_? from IRequest */
/* Otherwise, get it from the loop handler */
if(R->AfterCLI)
{
I=R->IRequest; /* Get pending interrupt */
R->ICount+=R->IBackup-1; /* Restore the ICount */
R->AfterCLI=0; /* Done with AfterCLI state */
}
else
{
I=Loop6502(R); /* Call the periodic handler */
R->ICount+=R->IPeriod; /* Reset the cycle counter */
if(!I) I=R->IRequest; /* Realize pending interrupt */
}
if(I==INT_QUIT) return(R->PC.W); /* Exit if INT_QUIT */
if(I) Int6502(R,I); /* Interrupt if needed */
}
}
/* Execution stopped */
return(R->PC.W);
}

View File

@ -1,148 +0,0 @@
/** M6502: portable 6502 emulator ****************************/
/** **/
/** M6502.h **/
/** **/
/** This file contains declarations relevant to emulation **/
/** of 6502 CPU. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2002 **/
/** Alex Krasivsky 1996 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
/*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*/
#ifndef M6502_H
#define M6502_H
/* Loop6502() returns: */
#define INT_NONE 0 /* No interrupt required */
#define INT_IRQ 1 /* Standard IRQ interrupt */
#define INT_NMI 2 /* Non-maskable interrupt */
#define INT_QUIT 3 /* Exit the emulation */
/* 6502 status flags: */
#define C_FLAG 0x01 /* 1: Carry occured */
#define Z_FLAG 0x02 /* 1: Result is zero */
#define I_FLAG 0x04 /* 1: Interrupts disabled */
#define D_FLAG 0x08 /* 1: Decimal mode */
#define B_FLAG 0x10 /* Break [0 on stk after int] */
#define R_FLAG 0x20 /* Always 1 */
#define V_FLAG 0x40 /* 1: Overflow occured */
#define N_FLAG 0x80 /* 1: Result is negative */
/** Simple Datatypes *****************************************/
/** NOTICE: sizeof(byte)=1 and sizeof(word)=2 **/
/*************************************************************/
#ifndef BYTE_TYPE_DEFINED
#define BYTE_TYPE_DEFINED
typedef unsigned char byte;
#endif
#ifndef WORD_TYPE_DEFINED
#define WORD_TYPE_DEFINED
typedef unsigned short word;
#endif
typedef signed char offset;
/** Structured Datatypes *************************************/
/** NOTICE: #define LSB_FIRST for machines where least **/
/** signifcant byte goes first. **/
/*************************************************************/
typedef union
{
#ifdef LSB_FIRST
struct { byte l,h; } B;
#else
struct { byte h,l; } B;
#endif
word W;
} pair;
typedef struct
{
byte A,P,X,Y,S; /* CPU registers and program counter */
pair PC;
int IPeriod,ICount; /* Set IPeriod to number of CPU cycles */
/* between calls to Loop6502() */
byte IRequest; /* Set to the INT_IRQ when pending IRQ */
byte AfterCLI; /* Private, don't touch */
int IBackup; /* Private, don't touch */
byte IAutoReset; /* Set to 1 to autom. reset IRequest */
byte TrapBadOps; /* Set to 1 to warn of illegal opcodes */
word Trap; /* Set Trap to address to trace from */
byte Trace; /* Set Trace=1 to start tracing */
void *User; /* Arbitrary user data (ID,RAM*,etc.) */
} M6502;
/** Reset6502() **********************************************/
/** This function can be used to reset the registers before **/
/** starting execution with Run6502(). It sets registers to **/
/** their initial values. **/
/*************************************************************/
void Reset6502(register M6502 *R);
/** Exec6502() ***********************************************/
/** This function will execute a single 6502 opcode. It **/
/** will then return next PC, and current register values **/
/** in R. **/
/*************************************************************/
word Exec6502(register M6502 *R);
/** Int6502() ************************************************/
/** This function will generate interrupt of a given type. **/
/** INT_NMI will cause a non-maskable interrupt. INT_IRQ **/
/** will cause a normal interrupt, unless I_FLAG set in R. **/
/*************************************************************/
void Int6502(register M6502 *R,register byte Type);
/** Run6502() ************************************************/
/** This function will run 6502 code until Loop6502() call **/
/** returns INT_QUIT. It will return the PC at which **/
/** emulation stopped, and current register values in R. **/
/*************************************************************/
word Run6502(register M6502 *R);
/** Rd6502()/Wr6502/Op6502() *********************************/
/** These functions are called when access to RAM occurs. **/
/** They allow to control memory access. Op6502 is the same **/
/** as Rd6502, but used to read *opcodes* only, when many **/
/** checks can be skipped to make it fast. It is only **/
/** required if there is a #define FAST_RDOP. **/
/************************************ TO BE WRITTEN BY USER **/
void Wr6502(register word Addr,register byte Value);
byte Rd6502(register word Addr);
byte Op6502(register word Addr);
/** Debug6502() **********************************************/
/** This function should exist if DEBUG is #defined. When **/
/** Trace!=0, it is called after each command executed by **/
/** the CPU, and given the 6502 registers. Emulation exits **/
/** if Debug6502() returns 0. **/
/*************************************************************/
byte Debug6502(register M6502 *R);
/** Loop6502() ***********************************************/
/** 6502 emulation calls this function periodically to **/
/** check if the system hardware requires any interrupts. **/
/** This function must return one of following values: **/
/** INT_NONE, INT_IRQ, INT_NMI, or INT_QUIT to exit the **/
/** emulation loop. **/
/************************************ TO BE WRITTEN BY USER **/
byte Loop6502(register M6502 *R);
/** Patch6502() **********************************************/
/** Emulation calls this function when it encounters an **/
/** unknown opcode. This can be used to patch the code to **/
/** emulate BIOS calls, such as disk and tape access. The **/
/** function should return 1 if the exception was handled, **/
/** or 0 if the opcode was truly illegal. **/
/************************************ TO BE WRITTEN BY USER **/
byte Patch6502(register byte Op,register M6502 *R);
#endif /* M6502_H */

View File

@ -1,71 +0,0 @@
/** M6502: portable 6502 emulator ****************************/
/** **/
/** Tables.h **/
/** **/
/** This file contains tables of used by 6502 emulation to **/
/** compute NEGATIVE and ZERO flags. There are also timing **/
/** tables for 6502 opcodes. This file is included from **/
/** 6502.c. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2002 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
/*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*/
static byte Cycles[256] =
{
7, 6, 2, 1, 5, 3, 5, 5, 3, 2, 2, 1, 6, 4, 6, 2,
2, 5, 5, 1, 5, 4, 6, 5, 2, 4, 2, 1, 6, 4, 6, 2,
6, 6, 2, 1, 3, 3, 5, 5, 4, 2, 2, 1, 4, 4, 6, 2,
2, 5, 5, 1, 4, 4, 6, 5, 2, 4, 2, 1, 4, 4, 6, 2,
6, 6, 2, 1, 3, 3, 5, 5, 3, 2, 2, 1, 3, 4, 6, 2,
2, 5, 5, 1, 4, 4, 6, 5, 2, 4, 3, 1, 8, 4, 6, 2,
6, 6, 2, 1, 3, 3, 5, 5, 4, 2, 2, 1, 6, 4, 6, 2,
2, 5, 5, 1, 4, 4, 6, 5, 5, 4, 4, 1, 6, 4, 6, 2,
3, 6, 2, 1, 3, 3, 3, 5, 2, 2, 2, 1, 4, 4, 4, 2,
2, 6, 5, 1, 4, 4, 4, 5, 2, 5, 2, 1, 4, 5, 5, 2,
2, 6, 2, 1, 3, 3, 3, 5, 2, 2, 2, 1, 4, 4, 4, 2,
2, 5, 5, 1, 4, 4, 4, 5, 2, 4, 2, 1, 4, 4, 4, 2,
2, 6, 2, 1, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 2,
2, 5, 5, 1, 4, 4, 6, 5, 2, 4, 3, 2, 4, 4, 6, 2,
2, 6, 2, 1, 3, 3, 5, 5, 2, 2, 2, 1, 4, 4, 6, 2,
2, 5, 5, 1, 4, 4, 6, 5, 2, 4, 4, 1, 4, 4, 6, 2
};
byte ZNTable[256] =
{
Z_FLAG, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG, N_FLAG,
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,9 @@
/* /*
* Cart manager - The TI-NESulator Project * Cart manager - The peTI-NESulator Project
* NESCart.h * NESCart.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*/ */
#ifndef NESCARTS_H #ifndef NESCARTS_H
@ -23,18 +18,18 @@
#define iNES_4SCREEN 0x08 #define iNES_4SCREEN 0x08
typedef struct NesCart_ typedef struct NesCart_
{ {
uint32_t 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 */
uint8_t Flags; uint8_t Flags;
char *FileName; char *FileName;
uint8_t *File; /* Pointer on the file in memory */ uint8_t *File; /* Pointer on the file in memory */
uint8_t *PROMBanks; /* Pointer on the first PROM */ uint8_t *PROMBanks; /* Pointer on the first PROM */
uint8_t *VROMBanks; /* Pointer on the first VROM */ uint8_t *VROMBanks; /* Pointer on the first VROM */
} NesCart; } NesCart;
void DumpCartProperties(); void DumpCartProperties(FILE *out, NesCart *cart);
int LoadCart(const char *filename, NesCart * cart); int LoadCart(const char *filename, NesCart *cart);
#endif #endif

View File

@ -1,237 +0,0 @@
/** EMULib Emulation Library *********************************/
/** **/
/** Sound.h **/
/** **/
/** This file defines standard sound generation API and **/
/** functions needed to log soundtrack into a MIDI file. **/
/** See Sound.c and the sound drivers for the code. **/
/** **/
/** Copyright (C) Marat Fayzullin 1996-2007 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
/*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
*/
#ifndef SOUND_H
#define SOUND_H
#ifdef __cplusplus
extern "C" {
#endif
/* SetSound() arguments: */
#define SND_MELODIC 0 /* Melodic sound (default) */
#define SND_RECTANGLE 0 /* Rectangular wave */
#define SND_QS_DU0 5
#define SND_QS_DU1 6
#define SND_QS_DU2 7
#define SND_QS_DU3 8
#define SND_TRIANGLE 1 /* Triangular wave (1/2 rect.)*/
#define SND_NOISE 2 /* White noise */
#define SND_PERIODIC 3 /* Periodic noise (not im-ed) */
#define SND_WAVE 4 /* Wave sound set by SetWave()*/
#define SND_MIDI 0x100 /* MIDI instrument (ORable) */
/* Drum() arguments: */
#define DRM_CLICK 0 /* Click (default) */
#define DRM_MIDI 0x100 /* MIDI drum (ORable) */
/* MIDI characteristics: */
#define MIDI_CHANNELS 16 /* Number of MIDI channels */
#define MIDI_MINFREQ 9 /* Min MIDI frequency (Hz) */
#define MIDI_MAXFREQ 12285 /* Max MIDI frequency (Hz) */
#define MIDI_DIVISIONS 1000 /* Number of ticks per second */
/* MIDILogging() arguments: */
#define MIDI_OFF 0 /* Turn MIDI logging off */
#define MIDI_ON 1 /* Turn MIDI logging on */
#define MIDI_TOGGLE 2 /* Toggle MIDI logging */
#define MIDI_QUERY 3 /* Query MIDI logging status */
/** TrashSound() *********************************************/
/** Shut down sound driver. Each driver implements its own **/
/** TrashSound() function. **/
/*************************************************************/
void TrashSound(void);
/** Sound() **************************************************/
/** Generate sound of given frequency (Hz) and volume **/
/** (0..255) via given channel. Setting Freq=0 or Volume=0 **/
/** turns sound off. **/
/*************************************************************/
void Sound(int Channel,int Freq,int Volume);
/** Drum() ***************************************************/
/** Hit a drum of given type with given force (0..255). **/
/** MIDI drums can be used by ORing their numbers with **/
/** SND_MIDI. **/
/*************************************************************/
void Drum(int Type,int Force);
/** SetSound() ***********************************************/
/** Set sound type at a given channel. MIDI instruments can **/
/** be set directly by ORing their numbers with SND_MIDI. **/
/*************************************************************/
void SetSound(int Channel,int NewType);
/** SetChannels() ********************************************/
/** Set master volume (0..255) and switch channels on/off. **/
/** Each channel N has corresponding bit 2^N in Switch. Set **/
/** or reset this bit to turn the channel on or off. **/
/*************************************************************/
void SetChannels(int Volume,int Switch);
/** SetWave() ************************************************/
/** Set waveform for a given channel. The channel will be **/
/** marked with sound type SND_WAVE. Set Rate=0 if you want **/
/** waveform to be an instrument or set it to the waveform **/
/** own playback rate. **/
/*************************************************************/
void SetWave(int Channel,signed char *Data,int Length,int Rate);
/** GetWave() ************************************************/
/** Get current read position for the buffer set with the **/
/** SetWave() call. Returns 0 if no buffer has been set, or **/
/** if there is no playrate set (i.e. wave is instrument). **/
/*************************************************************/
const signed char *GetWave(int Channel);
/** InitMIDI() ***********************************************/
/** Initialize soundtrack logging into MIDI file FileName. **/
/** Repeated calls to InitMIDI() will close current MIDI **/
/** file and continue logging into a new one. **/
/*************************************************************/
void InitMIDI(const char *FileName);
/** TrashMIDI() **********************************************/
/** Finish logging soundtrack and close the MIDI file. **/
/*************************************************************/
void TrashMIDI(void);
/** MIDILogging() ********************************************/
/** Turn soundtrack logging on/off and return its current **/
/** status. Possible values of Switch are MIDI_OFF (turn **/
/** logging off), MIDI_ON (turn logging on), MIDI_TOGGLE **/
/** (toggle logging), and MIDI_QUERY (just return current **/
/** state of logging). **/
/*************************************************************/
int MIDILogging(int Switch);
/** MIDITicks() **********************************************/
/** Log N 1ms MIDI ticks. **/
/*************************************************************/
void MIDITicks(int N);
//#ifdef UNIX
#define SND_CHANNELS 4 /* Number of channels */
#define SND_SAMPLESIZE 256 /* Max. SetWave() sample size */
#define SND_BUFSIZE 256 /* Buffer size, <= 2^SND_BITS */
#define SND_BITS 8 /* Number of bits in a fragment */
#define SND_BUFFERS 64 /* Number of fragments, >= 2 */
/* Bigger value results in better behaviour on loaded */
/* but output gets more delayed. */
/** InitSound() **********************************************/
/** Initialize Unix sound driver with given synthesis rate. **/
/** Returns Rate on success, 0 otherwise. Pass Rate=0 to **/
/** skip initialization and be silent. Pass Verbose!=0 to **/
/** see initialization messages. **/
/*************************************************************/
int InitSound(int Rate,int Verbose);
/** StopSound() **********************************************/
/** Temporarily suspend sound. **/
/*************************************************************/
void StopSound(void);
/** ResumeSound() ********************************************/
/** Resume sound after StopSound(). **/
/*************************************************************/
void ResumeSound(void);
//#endif /* UNIX */
#ifdef MSDOS
#define SND_CHANNELS 16 /* Number of sound channels */
#define OPL_CHANNELS 7 /* Number of Adlib channels */
#define SND_SAMPLESIZE 256 /* Max. SetWave() sample size */
#define SND_BUFSIZE 512 /* Buffer size for DMA */
#define SND_MAXDELAY 10 /* Maximal sound delay 1/n s */
/** InitSound() **********************************************/
/** Initialize sound. Returns Rate on success, 0 otherwise. **/
/** Rate=0 to skip initialization (will be silent). **/
/*************************************************************/
int InitSound(unsigned int Rate,unsigned int Latency);
#endif /* MSDOS */
#ifdef WINDOWS
#define SND_CHANNELS 16 /* Number of channels */
#define SND_SAMPLESIZE 256 /* Max. SetWave() sample size */
#define SND_BUFSIZE 512 /* Size of a wave buffer */
#define SND_BUFFERS 32 /* Number of wave buffers */
#include <Windows.h>
/** InitSound() **********************************************/
/** Initialize Windows sound driver with given synthesis **/
/** rate. Returns Rate on success, 0 otherwise. Pass Rate=0 **/
/** to skip initialization and be silent. Pass Rate=1 to **/
/** use MIDI (midiOut). Pass Rate=8192..44100 to use wave **/
/** synthesis (waveOut). Number of wave synthesis buffers **/
/** must be in 2..SND_BUFFERS range. **/
/*************************************************************/
unsigned int InitSound(unsigned int Rate,unsigned int Delay);
#endif /* WINDOWS */
#if 0
#ifndef MSDOS
#ifndef WINDOWS
#ifndef UNIX
#define SND_CHANNELS MIDI_CHANNELS /* Default number */
#endif
#endif
#endif
/** InitSound() **********************************************/
/** Initialize Series60 sound driver with given synthesis **/
/** rate. Returns Rate on success, 0 otherwise. Pass Rate=0 **/
/** to skip initialization and be silent. **/
/*************************************************************/
unsigned int InitSound(unsigned int Rate,unsigned int Delay);
#endif
/** RenderAudio() ********************************************/
/** Render given number of melodic sound samples. Returns **/
/** number of samples actually rendered. **/
/*************************************************************/
unsigned int RenderAudio(unsigned int Samples);
/** SndDriver ************************************************/
/** Each sound driver should fill this structure with **/
/** pointers to hardware-dependent handlers. This has to be **/
/** done inside the InitSound() function. **/
/*************************************************************/
struct SndDriverStruct
{
void (*SetSound)(int Channel,int NewType);
void (*Drum)(int Type,int Force);
void (*SetChannels)(int Volume,int Switch);
void (*Sound)(int Channel,int NewFreq,int NewVolume);
void (*SetWave)(int Channel,signed char *Data,int Length,int Freq);
const signed char *(*GetWave)(int Channel);
};
extern struct SndDriverStruct SndDriver;
#ifdef __cplusplus
}
#endif
#endif /* SOUND_H */

14
src/include/apu/apu.h Normal file
View File

@ -0,0 +1,14 @@
/*
* APU emulation - The peTI-NESulator Project
* apu.h
*
* Created by Manoël Trapier.
* Copyright (c) 2002-2019 986-Studio.
*
*/
#ifndef PETI_NESULATOR_APU_H
#define PETI_NESULATOR_APU_H
/* Empty, for now */
#endif /* PETI_NESULATOR_APU_H */

View File

@ -2,18 +2,13 @@
* ANSI Color definition - The Quick6502 Project * ANSI Color definition - The Quick6502 Project
* include/color.h * include/color.h
* *
* Created by Manoel Trapier on 25/06/10 * Created by Manoël Trapier on 25/06/10
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate:$
* $Author:$
* $HeadURL:$
* $Revision:$
* *
*/ */
#ifndef COLOR_H #ifndef COLOR_H
#define COLOR_H #define COLOR_H
#define ALLOW_COLORS #define ALLOW_COLORS
@ -44,5 +39,5 @@
#define CNORMAL ANSI_COLOR("0") #define CNORMAL ANSI_COLOR("0")
#endif /* COLOR_H */ #endif /* COLOR_H */

View File

@ -2,13 +2,8 @@
* CoreCPU - The Quick6502 Project * CoreCPU - The Quick6502 Project
* corecpu.h * corecpu.h
* *
* Created by Manoel Trapier on 24/02/08 * Created by Manoël Trapier on 24/02/08
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -37,57 +32,57 @@
#include "types.h" #include "types.h"
typedef byte (*quick6502_MemoryReadFunction)(unsigned short addr); typedef uint8_t (*quick6502_MemoryReadFunction)(uint16_t addr);
typedef void (*quick6502_MemoryWriteFunction)(unsigned short addr, byte value); typedef void (*quick6502_MemoryWriteFunction)(uint16_t addr, uint8_t value);
typedef struct quick6502_cpu_ typedef struct quick6502_cpu_
{ {
/* 6502 registers */ /* 6502 registers */
byte reg_A, reg_X, reg_Y; uint8_t reg_A, reg_X, reg_Y;
byte reg_P, reg_S; uint8_t reg_P, reg_S;
unsigned short reg_PC; uint16_t reg_PC;
/* Read/Write memory functions */ /* Read/Write memory functions */
quick6502_MemoryReadFunction memory_read; quick6502_MemoryReadFunction memory_read;
quick6502_MemoryWriteFunction memory_write; quick6502_MemoryWriteFunction memory_write;
quick6502_MemoryReadFunction memory_page0_read; quick6502_MemoryReadFunction memory_page0_read;
quick6502_MemoryWriteFunction memory_page0_write; quick6502_MemoryWriteFunction memory_page0_write;
quick6502_MemoryReadFunction memory_stack_read; quick6502_MemoryReadFunction memory_stack_read;
quick6502_MemoryWriteFunction memory_stack_write; quick6502_MemoryWriteFunction memory_stack_write;
quick6502_MemoryReadFunction memory_opcode_read; quick6502_MemoryReadFunction memory_opcode_read;
/* Timing related */ /* Timing related */
long cycle_done; long cycle_done;
byte exit_loop; uint8_t exit_loop;
byte int_pending; uint8_t int_pending;
/* Other config options */
uint8_t running; /* This field is used to prevent cpu free if this cpu is running */
uint8_t page_crossed;
/* TODO add support for Inst/MemAccess breakpoints */
/* Other config options */
byte running; /* This field is used to prevent cpu free if this cpu is running */
byte page_crossed;
/* TODO add support for Inst/MemAccess breakpoints */
} quick6502_cpu; } quick6502_cpu;
typedef struct quick6502_cpuconfig_ typedef struct quick6502_cpuconfig_
{ {
/* Read/Write memory functions */ /* Read/Write memory functions */
quick6502_MemoryReadFunction memory_read; quick6502_MemoryReadFunction memory_read;
quick6502_MemoryWriteFunction memory_write; quick6502_MemoryWriteFunction memory_write;
quick6502_MemoryReadFunction memory_page0_read; quick6502_MemoryReadFunction memory_page0_read;
quick6502_MemoryWriteFunction memory_page0_write; quick6502_MemoryWriteFunction memory_page0_write;
quick6502_MemoryReadFunction memory_stack_read; quick6502_MemoryReadFunction memory_stack_read;
quick6502_MemoryWriteFunction memory_stack_write; quick6502_MemoryWriteFunction memory_stack_write;
quick6502_MemoryReadFunction memory_opcode_read; quick6502_MemoryReadFunction memory_opcode_read;
} quick6502_cpuconfig; } quick6502_cpuconfig;
/*** Signal that we can send to the CPU ***/ /*** Signal that we can send to the CPU ***/
typedef enum typedef enum
{ {
Q6502_NO_SIGNAL = 0, Q6502_NO_SIGNAL = 0,
Q6502_IRQ_SIGNAL, Q6502_IRQ_SIGNAL,
Q6502_NMI_SIGNAL, Q6502_NMI_SIGNAL,
Q6502_STOPLOOP_SIGNAL Q6502_STOPLOOP_SIGNAL
} quick6502_signal; } quick6502_signal;
/*** Some 6502 related definitions ***/ /*** Some 6502 related definitions ***/
@ -139,7 +134,7 @@ void quick6502_reset(quick6502_cpu *cpu);
* *
* int: (Number of cycle really done) - (Number of cycle asked) * int: (Number of cycle really done) - (Number of cycle asked)
*/ */
int quick6502_run(quick6502_cpu *cpu, int cycles); uint32_t quick6502_run(quick6502_cpu *cpu, uint32_t cycles);
/** Loop CPU until explicit quit */ /** Loop CPU until explicit quit */
void quick6502_loop(quick6502_cpu *cpu); void quick6502_loop(quick6502_cpu *cpu);
@ -151,13 +146,14 @@ void quick6502_exec(quick6502_cpu *cpu);
void quick6502_int(quick6502_cpu *cpu, quick6502_signal signal); void quick6502_int(quick6502_cpu *cpu, quick6502_signal signal);
/** Dump CPU State to the given file */ /** Dump CPU State to the given file */
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 */
#define MINE #define MINE
int quick6502_getinstruction(quick6502_cpu *cpu, char interpret, int quick6502_getinstruction(quick6502_cpu *cpu, char interpret,
unsigned short addr, char *buffer, int *strlength); uint16_t addr, char *buffer, int *strlength);
/** /**
* Free the CPU * Free the CPU
* *

View File

@ -2,18 +2,13 @@
* Log Facility - The Quick6502 Project * Log Facility - The Quick6502 Project
* include/log.h * include/log.h
* *
* Created by Manoel Trapier on 19/05/10 * Created by Manoël Trapier on 19/05/10
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate:$
* $Author:$
* $HeadURL:$
* $Revision:$
* *
*/ */
#ifndef _LOG_H #ifndef _LOG_H
#define _LOG_H #define _LOG_H
enum enum
{ {
@ -38,5 +33,5 @@ void log_real(int level, char *user, char *fmt, ...);
if ((_level <= MAX_DEBUG_LEVEL) || (_level <= LOG_PANIC)) \ if ((_level <= MAX_DEBUG_LEVEL) || (_level <= LOG_PANIC)) \
do { _code; printf("\n"); } while(0) do { _code; printf("\n"); } while(0)
#endif /* _LOG_H */ #endif /* _LOG_H */

View File

@ -1,14 +1,9 @@
/* /*
* Mappers manager & facilities - The TI-NESulator Project * Mappers manager & facilities - The peTI-NESulator Project
* mappers.h * mappers.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -19,11 +14,10 @@
#include <stdio.h> #include <stdio.h>
#include <NESCarts.h> #include <NESCarts.h>
typedef int (*MapperInit) (NesCart * cart); typedef int (*MapperInit)(NesCart *cart);
typedef int (*MapperWriteHook) (register unsigned short Addr, typedef int (*MapperWriteHook)(register uint16_t Addr, register uint8_t Value);
register unsigned char Value); typedef int (*MapperIRQ)(int cycledone);
typedef int (*MapperIRQ) (int cycledone); typedef void (*MapperDump)(FILE *fp);
typedef void (*MapperDump) ();
#ifdef __TINES_MAPPERS__ #ifdef __TINES_MAPPERS__
@ -38,23 +32,26 @@ extern NesCart *Cart;
#define GETLAST16KBANK(c) ((c->PROMSize>>14)-1) #define GETLAST16KBANK(c) ((c->PROMSize>>14)-1)
#define GETLAST32KBANK(c) ((c->PROMSize>>15)-1) #define GETLAST32KBANK(c) ((c->PROMSize>>15)-1)
void set_vrom_bank_1k(unsigned short addr,int slot); void set_vrom_bank_1k(uint16_t addr, int slot);
void set_vrom_bank_2k(unsigned short addr,int slot); void set_vrom_bank_2k(uint16_t addr, int slot);
void set_vrom_bank_4k(unsigned short addr,int slot); void set_vrom_bank_4k(uint16_t addr, int slot);
void set_vrom_bank_8k(unsigned short addr, int slot); void set_vrom_bank_8k(uint16_t addr, int slot);
void set_prom_bank_8k(unsigned short addr,int slot); void set_prom_bank_8k(uint16_t addr, int slot);
void set_prom_bank_16k(unsigned short addr,int slot); void set_prom_bank_16k(uint16_t addr, int slot);
void set_prom_bank_32k(unsigned short addr,int slot); void set_prom_bank_32k(uint16_t addr, int slot);
#else /* __TINES_MAPPERS__ */ #else /* __TINES_MAPPERS__ */
/* Available functions outside of mappers */ /* Available functions outside of mappers */
void mapper_list (); void mapper_list();
int mapper_init (NesCart *cart);
extern int (*mapper_irqloop) (int cyclodone); int mapper_init(NesCart *cart);
extern void (*mapper_dump) (FILE *fp);
extern MapperIRQ mapper_irqloop;
extern MapperDump mapper_dump;
extern MapperWriteHook mapper_hook;
#endif /* __TINES_MAPPERS__ */ #endif /* __TINES_MAPPERS__ */

View File

@ -1,14 +1,9 @@
/* /*
* 6502 Memory manager - The TI-NESulator Project * 6502 Memory manager - The peTI-NESulator Project
* memory.h - Taken from the Quick6502 project * memory.h - Taken from the Quick6502 project
* *
* Created by Manoel Trapier on 18/09/06. * Created by Manoël Trapier on 18/09/06.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#ifndef MEMORY_H #ifndef MEMORY_H
@ -23,46 +18,35 @@
#define ATTR_PAGE_GHOST 0x02 #define ATTR_PAGE_GHOST 0x02
#define ATTR_PAGE_MAPPED 0x01 #define ATTR_PAGE_MAPPED 0x01
typedef byte (*func_rdhook)(byte /* addr */); typedef uint8_t (*func_rdhook)(uint8_t /* addr */);
typedef void (*func_wrhook)(byte addr, byte data);
typedef void (*func_wrhook)(uint8_t addr, uint8_t data);
/* Functions to manage pages data */ /* Functions to manage pages data */
void set_page_ptr(byte page, byte *ptr); void set_page_ptr(uint8_t page, uint8_t *ptr);
void set_page_ptr_1k(byte page, byte *ptr); void set_page_ptr_1k(uint8_t page, uint8_t *ptr);
void set_page_ptr_2k(byte page, byte *ptr); void set_page_ptr_2k(uint8_t page, uint8_t *ptr);
void set_page_ptr_4k(byte page, byte *ptr); void set_page_ptr_4k(uint8_t page, uint8_t *ptr);
void set_page_ptr_8k(byte page, byte *ptr); void set_page_ptr_8k(uint8_t page, uint8_t *ptr);
void set_page_ptr_16k(byte page, byte *ptr); void set_page_ptr_16k(uint8_t page, uint8_t *ptr);
void set_page_ptr_32k(byte page, byte *ptr); void set_page_ptr_32k(uint8_t page, uint8_t *ptr);
uint8_t *get_page_ptr(uint8_t page);
byte *get_page_ptr(byte page);
/* Functions to set pages attributes */ /* Functions to set pages attributes */
void set_page_rd_hook(uint8_t page, func_rdhook func);
void set_page_rd_hook(byte page, func_rdhook func); void set_page_wr_hook(uint8_t page, func_wrhook func);
void set_page_readable(uint8_t page, uint8_t value);
void set_page_wr_hook(byte page, func_wrhook func); void set_page_writeable(uint8_t page, uint8_t value);
void set_page_ghost(uint8_t page, uint8_t value, uint8_t ghost);
void set_page_readable(byte page, bool value); uint8_t get_page_attributes(uint8_t page);
func_rdhook get_page_rdhook(uint8_t page);
void set_page_writeable(byte page, bool value); func_wrhook get_page_wrhook(uint8_t page);
void set_page_ghost(byte page, bool value, byte ghost);
byte get_page_attributes(byte page);
func_rdhook get_page_rdhook(byte page);
func_wrhook get_page_wrhook(byte page);
/* Generalist functions */ /* Generalist functions */
void InitMemory(); void InitMemory();
uint8_t ReadMemory(uint8_t page, uint8_t addr);
byte ReadMemory(byte page, byte addr); void WriteMemory(uint8_t page, uint8_t addr, uint8_t value);
void WriteMemory(byte page, byte addr, byte value);
void DumpMemoryState(FILE *fp); void DumpMemoryState(FILE *fp);
#endif #endif

View File

@ -1,14 +1,9 @@
/* /*
* OS Dependent functions - The TI-NESulator Project * OS Dependent functions - The peTI-NESulator Project
* os_dependent.h * os_dependent.h
* *
* Created by Manoel TRAPIER on 08/05/08. * Created by Manoël Trapier on 08/05/08.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -16,17 +11,23 @@
#define OS_DEPENDENT_H #define OS_DEPENDENT_H
#include <stdint.h> #include <stdint.h>
#include "text.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); int graphics_drawline(uint32_t x, uint32_t y, uint32_t x1, uint32_t y1, uint32_t colour);
int graphics_drawRect(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint32_t colour);
int graphics_drawFillrect(int x0, int y0, int w, int h, uint32_t colour);
int graphics_getScreenSize(int *w, int *h);
void vsync(void);
typedef struct Palette_t typedef struct Palette_t
{ {
uint8_t r,g,b,a; uint8_t r, g, b, a;
} Palette; } Palette;
int getKeyStatus(int key); int getKeyStatus(int key);
@ -34,21 +35,32 @@ int getKeyStatus(int key);
/* Sound related functions */ /* Sound related functions */
/* IO functions */ /* IO functions */
void *LoadFilePtr(char * filename); void *LoadFilePtr(char *filename);
/* Console functions */ /* Console functions */
typedef enum ConsoleLevel_t typedef enum ConsoleLevel_t
{ {
Console_Error = 0, Console_Error = 0,
Console_Warning, Console_Warning,
Console_Alert, Console_Alert,
Console_Default, Console_Default,
Console_Verbose, Console_Verbose,
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, ...);
#define KEY_ENTER (257)
#define KEY_LEFT (263)
#define KEY_RIGHT (262)
#define KEY_UP (265)
#define KEY_DOWN (264)
//#define KEY_ENTER 13
#endif /* OS_DEPENDENT_H */ #endif /* OS_DEPENDENT_H */

View File

@ -1,36 +1,23 @@
/* /*
* Paddle manager - The TI-NESulator Project * Paddle manager - The peTI-NESulator Project
* paddle.h * paddle.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#ifndef PADDLE_H #ifndef PADDLE_H
#define PADDLE_H #define PADDLE_H
typedef struct Paddle_ typedef struct Paddle_
{ {
uint8_t bitPos;
unsigned char Bit; uint8_t strobeState;
unsigned char LastWrite;
} Paddle; } Paddle;
uint8_t ReadPaddle(Paddle *pdl);
unsigned char ReadPaddle(Paddle * pdl); void InitPaddle(Paddle *pdl);
void WritePaddle(Paddle *pdl, uint8_t val);
void InitPaddle(Paddle * pdl);
void WritePaddle(Paddle * pdl, unsigned char val);
#endif #endif

View File

@ -1,266 +1,260 @@
/* Generated data file from file 'stdin' */ /* Generated data file from file 'stdin' */
/*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $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 },
{ 0x17, 0x02, 0x28, 0x00 }, { 0x17, 0x02, 0x28, 0x00 },
{ 0x22, 0x00, 0x1D, 0xB7 }, { 0x22, 0x00, 0x1D, 0xB7 },
{ 0x24, 0x01, 0x0A, 0xB7 }, { 0x24, 0x01, 0x0A, 0xB7 },
{ 0x24, 0x04, 0x02, 0xB7 }, { 0x24, 0x04, 0x02, 0xB7 },
{ 0x1B, 0x09, 0x01, 0xB7 }, { 0x1B, 0x09, 0x01, 0xB7 },
{ 0x11, 0x10, 0x01, 0x00 }, { 0x11, 0x10, 0x01, 0x00 },
{ 0x05, 0x15, 0x01, 0x00 }, { 0x05, 0x15, 0x01, 0x00 },
{ 0x01, 0x17, 0x02, 0xB7 }, { 0x01, 0x17, 0x02, 0xB7 },
{ 0x00, 0x14, 0x0B, 0xBF }, { 0x00, 0x14, 0x0B, 0xBF },
{ 0x01, 0x11, 0x1B, 0xBF }, { 0x01, 0x11, 0x1B, 0xBF },
{ 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x2F, 0x30, 0x2F, 0xB7 }, { 0x2F, 0x30, 0x2F, 0xB7 },
{ 0x05, 0x1A, 0x37, 0xBF }, { 0x05, 0x1A, 0x37, 0xBF },
{ 0x12, 0x10, 0x3B, 0xBF }, { 0x12, 0x10, 0x3B, 0xBF },
{ 0x23, 0x09, 0x38, 0xB7 }, { 0x23, 0x09, 0x38, 0xB7 },
{ 0x31, 0x06, 0x2E, 0xBF }, { 0x31, 0x06, 0x2E, 0xBF },
{ 0x35, 0x08, 0x18, 0xB7 }, { 0x35, 0x08, 0x18, 0xB7 },
{ 0x35, 0x0D, 0x08, 0x00 }, { 0x35, 0x0D, 0x08, 0x00 },
{ 0x2D, 0x16, 0x03, 0xB7 }, { 0x2D, 0x16, 0x03, 0xB7 },
{ 0x22, 0x1E, 0x01, 0x00 }, { 0x22, 0x1E, 0x01, 0x00 },
{ 0x0E, 0x24, 0x01, 0x00 }, { 0x0E, 0x24, 0x01, 0x00 },
{ 0x05, 0x26, 0x06, 0x00 }, { 0x05, 0x26, 0x06, 0x00 },
{ 0x02, 0x26, 0x16, 0xB7 }, { 0x02, 0x26, 0x16, 0xB7 },
{ 0x02, 0x22, 0x2A, 0xBF }, { 0x02, 0x22, 0x2A, 0xBF },
{ 0x0B, 0x0B, 0x0B, 0xBF }, { 0x0B, 0x0B, 0x0B, 0xBF },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 },
{ 0x3D, 0x3D, 0x3E, 0x00 }, { 0x3D, 0x3D, 0x3E, 0x00 },
{ 0x12, 0x2C, 0x3E, 0xB7 }, { 0x12, 0x2C, 0x3E, 0xB7 },
{ 0x22, 0x25, 0x3F, 0xB7 }, { 0x22, 0x25, 0x3F, 0xB7 },
{ 0x30, 0x1E, 0x3E, 0xB7 }, { 0x30, 0x1E, 0x3E, 0xB7 },
{ 0x3A, 0x1B, 0x3B, 0xBF }, { 0x3A, 0x1B, 0x3B, 0xBF },
{ 0x3D, 0x1D, 0x2E, 0xB7 }, { 0x3D, 0x1D, 0x2E, 0xB7 },
{ 0x3D, 0x20, 0x1B, 0xB7 }, { 0x3D, 0x20, 0x1B, 0xB7 },
{ 0x3B, 0x28, 0x11, 0x07 }, { 0x3B, 0x28, 0x11, 0x07 },
{ 0x35, 0x30, 0x08, 0x01 }, { 0x35, 0x30, 0x08, 0x01 },
{ 0x26, 0x35, 0x08, 0x00 }, { 0x26, 0x35, 0x08, 0x00 },
{ 0x14, 0x37, 0x11, 0x00 }, { 0x14, 0x37, 0x11, 0x00 },
{ 0x0F, 0x37, 0x25, 0x00 }, { 0x0F, 0x37, 0x25, 0x00 },
{ 0x0A, 0x36, 0x37, 0xB7 }, { 0x0A, 0x36, 0x37, 0xB7 },
{ 0x18, 0x19, 0x19, 0xB7 }, { 0x18, 0x19, 0x19, 0xB7 },
{ 0x01, 0x01, 0x01, 0xB7 }, { 0x01, 0x01, 0x01, 0xB7 },
{ 0x01, 0x01, 0x01, 0xB7 }, { 0x01, 0x01, 0x01, 0xB7 },
{ 0x3E, 0x3E, 0x3E, 0xB7 }, { 0x3E, 0x3E, 0x3E, 0xB7 },
{ 0x2D, 0x37, 0x3E, 0xB7 }, { 0x2D, 0x37, 0x3E, 0xB7 },
{ 0x33, 0x34, 0x3F, 0x10 }, { 0x33, 0x34, 0x3F, 0x10 },
{ 0x37, 0x31, 0x3E, 0x00 }, { 0x37, 0x31, 0x3E, 0x00 },
{ 0x3C, 0x30, 0x3D, 0x00 }, { 0x3C, 0x30, 0x3D, 0x00 },
{ 0x3D, 0x30, 0x38, 0x00 }, { 0x3D, 0x30, 0x38, 0x00 },
{ 0x3D, 0x33, 0x30, 0x00 }, { 0x3D, 0x33, 0x30, 0x00 },
{ 0x3D, 0x36, 0x2B, 0x00 }, { 0x3D, 0x36, 0x2B, 0x00 },
{ 0x3B, 0x39, 0x26, 0x00 }, { 0x3B, 0x39, 0x26, 0x00 },
{ 0x34, 0x3B, 0x27, 0x00 }, { 0x34, 0x3B, 0x27, 0x00 },
{ 0x2E, 0x3C, 0x2D, 0x00 }, { 0x2E, 0x3C, 0x2D, 0x00 },
{ 0x2C, 0x3C, 0x36, 0x00 }, { 0x2C, 0x3C, 0x36, 0x00 },
{ 0x29, 0x3C, 0x3C, 0x00 }, { 0x29, 0x3C, 0x3C, 0x00 },
{ 0x32, 0x31, 0x32, 0xB7 }, { 0x32, 0x31, 0x32, 0xB7 },
{ 0x01, 0x01, 0x01, 0xB7 }, { 0x01, 0x01, 0x01, 0xB7 },
{ 0x01, 0x01, 0x01, 0xB7 }, { 0x01, 0x01, 0x01, 0xB7 },
{ 0x1E, 0x1E, 0x1E, 0xB7 }, { 0x1E, 0x1E, 0x1E, 0xB7 },
{ 0x03, 0x09, 0x28, 0xB7 }, { 0x03, 0x09, 0x28, 0xB7 },
{ 0x0A, 0x04, 0x2B, 0xBF }, { 0x0A, 0x04, 0x2B, 0xBF },
{ 0x17, 0x02, 0x28, 0xB7 }, { 0x17, 0x02, 0x28, 0xB7 },
{ 0x22, 0x00, 0x1D, 0xB7 }, { 0x22, 0x00, 0x1D, 0xB7 },
{ 0x24, 0x01, 0x0A, 0xB7 }, { 0x24, 0x01, 0x0A, 0xB7 },
{ 0x24, 0x04, 0x02, 0x00 }, { 0x24, 0x04, 0x02, 0x00 },
{ 0x1B, 0x09, 0x01, 0x00 }, { 0x1B, 0x09, 0x01, 0x00 },
{ 0x11, 0x10, 0x01, 0x00 }, { 0x11, 0x10, 0x01, 0x00 },
{ 0x05, 0x15, 0x01, 0xB7 }, { 0x05, 0x15, 0x01, 0xB7 },
{ 0x01, 0x17, 0x02, 0x00 }, { 0x01, 0x17, 0x02, 0x00 },
{ 0x00, 0x14, 0x0B, 0xB7 }, { 0x00, 0x14, 0x0B, 0xB7 },
{ 0x01, 0x11, 0x1B, 0x50 }, { 0x01, 0x11, 0x1B, 0x50 },
{ 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x2F, 0x30, 0x2F, 0xBF }, { 0x2F, 0x30, 0x2F, 0xBF },
{ 0x05, 0x1A, 0x37, 0xB7 }, { 0x05, 0x1A, 0x37, 0xB7 },
{ 0x12, 0x10, 0x3B, 0xB7 }, { 0x12, 0x10, 0x3B, 0xB7 },
{ 0x23, 0x09, 0x38, 0x20 }, { 0x23, 0x09, 0x38, 0x20 },
{ 0x31, 0x06, 0x2E, 0xBF }, { 0x31, 0x06, 0x2E, 0xBF },
{ 0x35, 0x08, 0x18, 0xB7 }, { 0x35, 0x08, 0x18, 0xB7 },
{ 0x35, 0x0D, 0x08, 0xBF }, { 0x35, 0x0D, 0x08, 0xBF },
{ 0x2D, 0x16, 0x03, 0xBF }, { 0x2D, 0x16, 0x03, 0xBF },
{ 0x22, 0x1E, 0x01, 0xB7 }, { 0x22, 0x1E, 0x01, 0xB7 },
{ 0x0E, 0x24, 0x01, 0xBF }, { 0x0E, 0x24, 0x01, 0xBF },
{ 0x05, 0x26, 0x06, 0xB7 }, { 0x05, 0x26, 0x06, 0xB7 },
{ 0x02, 0x26, 0x16, 0xBF }, { 0x02, 0x26, 0x16, 0xBF },
{ 0x02, 0x22, 0x2A, 0xBF }, { 0x02, 0x22, 0x2A, 0xBF },
{ 0x0B, 0x0B, 0x0B, 0x00 }, { 0x0B, 0x0B, 0x0B, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x3D, 0x3D, 0x3E, 0xBF }, { 0x3D, 0x3D, 0x3E, 0xBF },
{ 0x12, 0x2C, 0x3E, 0x53 }, { 0x12, 0x2C, 0x3E, 0x53 },
{ 0x22, 0x25, 0x3F, 0x54 }, { 0x22, 0x25, 0x3F, 0x54 },
{ 0x30, 0x1E, 0x3E, 0x46 }, { 0x30, 0x1E, 0x3E, 0x46 },
{ 0x3A, 0x1B, 0x3B, 0x31 }, { 0x3A, 0x1B, 0x3B, 0x31 },
{ 0x3D, 0x1D, 0x2E, 0x3A }, { 0x3D, 0x1D, 0x2E, 0x3A },
{ 0x3D, 0x20, 0x1B, 0x32 }, { 0x3D, 0x20, 0x1B, 0x32 },
{ 0x3B, 0x28, 0x11, 0x54 }, { 0x3B, 0x28, 0x11, 0x54 },
{ 0x35, 0x30, 0x08, 0x30 }, { 0x35, 0x30, 0x08, 0x30 },
{ 0x26, 0x35, 0x08, 0x00 }, { 0x26, 0x35, 0x08, 0x00 },
{ 0x14, 0x37, 0x11, 0x00 }, { 0x14, 0x37, 0x11, 0x00 },
{ 0x0F, 0x37, 0x25, 0x00 }, { 0x0F, 0x37, 0x25, 0x00 },
{ 0x0A, 0x36, 0x37, 0x00 }, { 0x0A, 0x36, 0x37, 0x00 },
{ 0x18, 0x19, 0x19, 0x00 }, { 0x18, 0x19, 0x19, 0x00 },
{ 0x01, 0x01, 0x01, 0x00 }, { 0x01, 0x01, 0x01, 0x00 },
{ 0x01, 0x01, 0x01, 0x00 }, { 0x01, 0x01, 0x01, 0x00 },
{ 0x3E, 0x3E, 0x3E, 0x00 }, { 0x3E, 0x3E, 0x3E, 0x00 },
{ 0x2D, 0x37, 0x3E, 0x00 }, { 0x2D, 0x37, 0x3E, 0x00 },
{ 0x33, 0x34, 0x3F, 0x00 }, { 0x33, 0x34, 0x3F, 0x00 },
{ 0x37, 0x31, 0x3E, 0x00 }, { 0x37, 0x31, 0x3E, 0x00 },
{ 0x3C, 0x30, 0x3D, 0x00 }, { 0x3C, 0x30, 0x3D, 0x00 },
{ 0x3D, 0x30, 0x38, 0x00 }, { 0x3D, 0x30, 0x38, 0x00 },
{ 0x3D, 0x33, 0x30, 0xB7 }, { 0x3D, 0x33, 0x30, 0xB7 },
{ 0x3D, 0x36, 0x2B, 0xB7 }, { 0x3D, 0x36, 0x2B, 0xB7 },
{ 0x3B, 0x39, 0x26, 0x00 }, { 0x3B, 0x39, 0x26, 0x00 },
{ 0x34, 0x3B, 0x27, 0xBF }, { 0x34, 0x3B, 0x27, 0xBF },
{ 0x2E, 0x3C, 0x2D, 0xB7 }, { 0x2E, 0x3C, 0x2D, 0xB7 },
{ 0x2C, 0x3C, 0x36, 0xB7 }, { 0x2C, 0x3C, 0x36, 0xB7 },
{ 0x29, 0x3C, 0x3C, 0xB7 }, { 0x29, 0x3C, 0x3C, 0xB7 },
{ 0x32, 0x31, 0x32, 0xB7 }, { 0x32, 0x31, 0x32, 0xB7 },
{ 0x01, 0x01, 0x01, 0xB7 }, { 0x01, 0x01, 0x01, 0xB7 },
{ 0x01, 0x01, 0x01, 0xB7 }, { 0x01, 0x01, 0x01, 0xB7 },
{ 0x1E, 0x1E, 0x1E, 0x07 }, { 0x1E, 0x1E, 0x1E, 0x07 },
{ 0x03, 0x09, 0x28, 0xB7 }, { 0x03, 0x09, 0x28, 0xB7 },
{ 0x0A, 0x04, 0x2B, 0x0D }, { 0x0A, 0x04, 0x2B, 0x0D },
{ 0x17, 0x02, 0x28, 0x00 }, { 0x17, 0x02, 0x28, 0x00 },
{ 0x22, 0x00, 0x1D, 0xB7 }, { 0x22, 0x00, 0x1D, 0xB7 },
{ 0x24, 0x01, 0x0A, 0xB7 }, { 0x24, 0x01, 0x0A, 0xB7 },
{ 0x24, 0x04, 0x02, 0xB7 }, { 0x24, 0x04, 0x02, 0xB7 },
{ 0x1B, 0x09, 0x01, 0xB7 }, { 0x1B, 0x09, 0x01, 0xB7 },
{ 0x11, 0x10, 0x01, 0x00 }, { 0x11, 0x10, 0x01, 0x00 },
{ 0x05, 0x15, 0x01, 0x00 }, { 0x05, 0x15, 0x01, 0x00 },
{ 0x01, 0x17, 0x02, 0xB7 }, { 0x01, 0x17, 0x02, 0xB7 },
{ 0x00, 0x14, 0x0B, 0x00 }, { 0x00, 0x14, 0x0B, 0x00 },
{ 0x01, 0x11, 0x1B, 0xB7 }, { 0x01, 0x11, 0x1B, 0xB7 },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x2F, 0x30, 0x2F, 0xB7 }, { 0x2F, 0x30, 0x2F, 0xB7 },
{ 0x05, 0x1A, 0x37, 0xBF }, { 0x05, 0x1A, 0x37, 0xBF },
{ 0x12, 0x10, 0x3B, 0xB7 }, { 0x12, 0x10, 0x3B, 0xB7 },
{ 0x23, 0x09, 0x38, 0xB7 }, { 0x23, 0x09, 0x38, 0xB7 },
{ 0x31, 0x06, 0x2E, 0x00 }, { 0x31, 0x06, 0x2E, 0x00 },
{ 0x35, 0x08, 0x18, 0xBF }, { 0x35, 0x08, 0x18, 0xBF },
{ 0x35, 0x0D, 0x08, 0xB7 }, { 0x35, 0x0D, 0x08, 0xB7 },
{ 0x2D, 0x16, 0x03, 0xB7 }, { 0x2D, 0x16, 0x03, 0xB7 },
{ 0x22, 0x1E, 0x01, 0xB7 }, { 0x22, 0x1E, 0x01, 0xB7 },
{ 0x0E, 0x24, 0x01, 0x00 }, { 0x0E, 0x24, 0x01, 0x00 },
{ 0x05, 0x26, 0x06, 0x00 }, { 0x05, 0x26, 0x06, 0x00 },
{ 0x02, 0x26, 0x16, 0xB7 }, { 0x02, 0x26, 0x16, 0xB7 },
{ 0x02, 0x22, 0x2A, 0x06 }, { 0x02, 0x22, 0x2A, 0x06 },
{ 0x0B, 0x0B, 0x0B, 0xB7 }, { 0x0B, 0x0B, 0x0B, 0xB7 },
{ 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00 },
{ 0x3D, 0x3D, 0x3E, 0xB7 }, { 0x3D, 0x3D, 0x3E, 0xB7 },
{ 0x12, 0x2C, 0x3E, 0xB7 }, { 0x12, 0x2C, 0x3E, 0xB7 },
{ 0x22, 0x25, 0x3F, 0xB7 }, { 0x22, 0x25, 0x3F, 0xB7 },
{ 0x30, 0x1E, 0x3E, 0xB7 }, { 0x30, 0x1E, 0x3E, 0xB7 },
{ 0x3A, 0x1B, 0x3B, 0x00 }, { 0x3A, 0x1B, 0x3B, 0x00 },
{ 0x3D, 0x1D, 0x2E, 0x00 }, { 0x3D, 0x1D, 0x2E, 0x00 },
{ 0x3D, 0x20, 0x1B, 0xB7 }, { 0x3D, 0x20, 0x1B, 0xB7 },
{ 0x3B, 0x28, 0x11, 0xB7 }, { 0x3B, 0x28, 0x11, 0xB7 },
{ 0x35, 0x30, 0x08, 0x03 }, { 0x35, 0x30, 0x08, 0x03 },
{ 0x26, 0x35, 0x08, 0xB7 }, { 0x26, 0x35, 0x08, 0xB7 },
{ 0x14, 0x37, 0x11, 0xBF }, { 0x14, 0x37, 0x11, 0xBF },
{ 0x0F, 0x37, 0x25, 0x00 }, { 0x0F, 0x37, 0x25, 0x00 },
{ 0x0A, 0x36, 0x37, 0xB7 }, { 0x0A, 0x36, 0x37, 0xB7 },
{ 0x18, 0x19, 0x19, 0xB7 }, { 0x18, 0x19, 0x19, 0xB7 },
{ 0x01, 0x01, 0x01, 0xB7 }, { 0x01, 0x01, 0x01, 0xB7 },
{ 0x01, 0x01, 0x01, 0xB7 }, { 0x01, 0x01, 0x01, 0xB7 },
{ 0x3E, 0x3E, 0x3E, 0x00 }, { 0x3E, 0x3E, 0x3E, 0x00 },
{ 0x2D, 0x37, 0x3E, 0x00 }, { 0x2D, 0x37, 0x3E, 0x00 },
{ 0x33, 0x34, 0x3F, 0xB7 }, { 0x33, 0x34, 0x3F, 0xB7 },
{ 0x37, 0x31, 0x3E, 0xB7 }, { 0x37, 0x31, 0x3E, 0xB7 },
{ 0x3C, 0x30, 0x3D, 0x00 }, { 0x3C, 0x30, 0x3D, 0x00 },
{ 0x3D, 0x30, 0x38, 0x00 }, { 0x3D, 0x30, 0x38, 0x00 },
{ 0x3D, 0x33, 0x30, 0xB7 }, { 0x3D, 0x33, 0x30, 0xB7 },
{ 0x3D, 0x36, 0x2B, 0xB7 }, { 0x3D, 0x36, 0x2B, 0xB7 },
{ 0x3B, 0x39, 0x26, 0xB7 }, { 0x3B, 0x39, 0x26, 0xB7 },
{ 0x34, 0x3B, 0x27, 0xBF }, { 0x34, 0x3B, 0x27, 0xBF },
{ 0x2E, 0x3C, 0x2D, 0xBF }, { 0x2E, 0x3C, 0x2D, 0xBF },
{ 0x2C, 0x3C, 0x36, 0xB7 }, { 0x2C, 0x3C, 0x36, 0xB7 },
{ 0x29, 0x3C, 0x3C, 0xBF }, { 0x29, 0x3C, 0x3C, 0xBF },
{ 0x32, 0x31, 0x32, 0xB7 }, { 0x32, 0x31, 0x32, 0xB7 },
{ 0x01, 0x01, 0x01, 0x00 }, { 0x01, 0x01, 0x01, 0x00 },
{ 0x01, 0x01, 0x01, 0xB7 }, { 0x01, 0x01, 0x01, 0xB7 },
{ 0x1E, 0x1E, 0x1E, 0xB7 }, { 0x1E, 0x1E, 0x1E, 0xB7 },
{ 0x03, 0x09, 0x28, 0x08 }, { 0x03, 0x09, 0x28, 0x08 },
{ 0x0A, 0x04, 0x2B, 0xBF }, { 0x0A, 0x04, 0x2B, 0xBF },
{ 0x17, 0x02, 0x28, 0xB7 }, { 0x17, 0x02, 0x28, 0xB7 },
{ 0x22, 0x00, 0x1D, 0x08 }, { 0x22, 0x00, 0x1D, 0x08 },
{ 0x24, 0x01, 0x0A, 0xB7 }, { 0x24, 0x01, 0x0A, 0xB7 },
{ 0x24, 0x04, 0x02, 0x08 }, { 0x24, 0x04, 0x02, 0x08 },
{ 0x1B, 0x09, 0x01, 0xB7 }, { 0x1B, 0x09, 0x01, 0xB7 },
{ 0x11, 0x10, 0x01, 0x00 }, { 0x11, 0x10, 0x01, 0x00 },
{ 0x05, 0x15, 0x01, 0xBF }, { 0x05, 0x15, 0x01, 0xBF },
{ 0x01, 0x17, 0x02, 0xB7 }, { 0x01, 0x17, 0x02, 0xB7 },
{ 0x00, 0x14, 0x0B, 0xB7 }, { 0x00, 0x14, 0x0B, 0xB7 },
{ 0x01, 0x11, 0x1B, 0x08 }, { 0x01, 0x11, 0x1B, 0x08 },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x00, 0x00, 0x00, 0x08 }, { 0x00, 0x00, 0x00, 0x08 },
{ 0x2F, 0x30, 0x2F, 0x01 }, { 0x2F, 0x30, 0x2F, 0x01 },
{ 0x05, 0x1A, 0x37, 0x08 }, { 0x05, 0x1A, 0x37, 0x08 },
{ 0x12, 0x10, 0x3B, 0x0D }, { 0x12, 0x10, 0x3B, 0x0D },
{ 0x23, 0x09, 0x38, 0x00 }, { 0x23, 0x09, 0x38, 0x00 },
{ 0x31, 0x06, 0x2E, 0xB7 }, { 0x31, 0x06, 0x2E, 0xB7 },
{ 0x35, 0x08, 0x18, 0xB7 }, { 0x35, 0x08, 0x18, 0xB7 },
{ 0x35, 0x0D, 0x08, 0xB7 }, { 0x35, 0x0D, 0x08, 0xB7 },
{ 0x2D, 0x16, 0x03, 0xB7 }, { 0x2D, 0x16, 0x03, 0xB7 },
{ 0x22, 0x1E, 0x01, 0x00 }, { 0x22, 0x1E, 0x01, 0x00 },
{ 0x0E, 0x24, 0x01, 0x00 }, { 0x0E, 0x24, 0x01, 0x00 },
{ 0x05, 0x26, 0x06, 0xB7 }, { 0x05, 0x26, 0x06, 0xB7 },
{ 0x02, 0x26, 0x16, 0x00 }, { 0x02, 0x26, 0x16, 0x00 },
{ 0x02, 0x22, 0x2A, 0xB7 }, { 0x02, 0x22, 0x2A, 0xB7 },
{ 0x0B, 0x0B, 0x0B, 0xB7 }, { 0x0B, 0x0B, 0x0B, 0xB7 },
{ 0x00, 0x00, 0x00, 0x08 }, { 0x00, 0x00, 0x00, 0x08 },
{ 0x00, 0x00, 0x00, 0xB7 }, { 0x00, 0x00, 0x00, 0xB7 },
{ 0x3D, 0x3D, 0x3E, 0xB7 }, { 0x3D, 0x3D, 0x3E, 0xB7 },
{ 0x12, 0x2C, 0x3E, 0xBF }, { 0x12, 0x2C, 0x3E, 0xBF },
{ 0x22, 0x25, 0x3F, 0xBF }, { 0x22, 0x25, 0x3F, 0xBF },
{ 0x30, 0x1E, 0x3E, 0xB7 }, { 0x30, 0x1E, 0x3E, 0xB7 },
{ 0x3A, 0x1B, 0x3B, 0xBF }, { 0x3A, 0x1B, 0x3B, 0xBF },
{ 0x3D, 0x1D, 0x2E, 0xB7 }, { 0x3D, 0x1D, 0x2E, 0xB7 },
{ 0x3D, 0x20, 0x1B, 0x00 }, { 0x3D, 0x20, 0x1B, 0x00 },
{ 0x3B, 0x28, 0x11, 0xB7 }, { 0x3B, 0x28, 0x11, 0xB7 },
{ 0x35, 0x30, 0x08, 0x00 }, { 0x35, 0x30, 0x08, 0x00 },
{ 0x26, 0x35, 0x08, 0x00 }, { 0x26, 0x35, 0x08, 0x00 },
{ 0x14, 0x37, 0x11, 0x00 }, { 0x14, 0x37, 0x11, 0x00 },
{ 0x0F, 0x37, 0x25, 0xB7 }, { 0x0F, 0x37, 0x25, 0xB7 },
{ 0x0A, 0x36, 0x37, 0xB7 }, { 0x0A, 0x36, 0x37, 0xB7 },
{ 0x18, 0x19, 0x19, 0x00 }, { 0x18, 0x19, 0x19, 0x00 },
{ 0x01, 0x01, 0x01, 0x00 }, { 0x01, 0x01, 0x01, 0x00 },
{ 0x01, 0x01, 0x01, 0x00 }, { 0x01, 0x01, 0x01, 0x00 },
{ 0x3E, 0x3E, 0x3E, 0x00 }, { 0x3E, 0x3E, 0x3E, 0x00 },
{ 0x2D, 0x37, 0x3E, 0xB7 }, { 0x2D, 0x37, 0x3E, 0xB7 },
{ 0x33, 0x34, 0x3F, 0x00 }, { 0x33, 0x34, 0x3F, 0x00 },
{ 0x37, 0x31, 0x3E, 0xB7 }, { 0x37, 0x31, 0x3E, 0xB7 },
{ 0x3C, 0x30, 0x3D, 0xBF }, { 0x3C, 0x30, 0x3D, 0xBF },
{ 0x3D, 0x30, 0x38, 0xB7 }, { 0x3D, 0x30, 0x38, 0xB7 },
{ 0x3D, 0x33, 0x30, 0x08 }, { 0x3D, 0x33, 0x30, 0x08 },
{ 0x3D, 0x36, 0x2B, 0x01 }, { 0x3D, 0x36, 0x2B, 0x01 },
{ 0x3B, 0x39, 0x26, 0x01 }, { 0x3B, 0x39, 0x26, 0x01 },
{ 0x34, 0x3B, 0x27, 0x00 }, { 0x34, 0x3B, 0x27, 0x00 },
{ 0x2E, 0x3C, 0x2D, 0xB7 }, { 0x2E, 0x3C, 0x2D, 0xB7 },
{ 0x2C, 0x3C, 0x36, 0xB7 }, { 0x2C, 0x3C, 0x36, 0xB7 },
{ 0x29, 0x3C, 0x3C, 0x08 }, { 0x29, 0x3C, 0x3C, 0x08 },
{ 0x32, 0x31, 0x32, 0xB7 }, { 0x32, 0x31, 0x32, 0xB7 },
{ 0x01, 0x01, 0x01, 0x08 }, { 0x01, 0x01, 0x01, 0x08 },
{ 0x01, 0x01, 0x01, 0xBF }, { 0x01, 0x01, 0x01, 0xBF },
}; };

View File

@ -1,46 +1,38 @@
/* /*
* Plugins manager - The TI-NESulator Project * Plugins manager - The peTI-NESulator Project
* plugins.h * plugins.h
* *
* Created by Manoel TRAPIER on 02/04/07. * Created by Manoël Trapier on 02/04/07.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#ifndef PLUGINS_H #ifndef PLUGINS_H
#define PLUGINS_H #define PLUGINS_H
#include <types.h> #include <types.h>
/* Function pointer for prototyping function that plugins may export */ /* Function pointer for prototyping function that plugins may export */
typedef int (*PluginInit) (void); typedef int (*PluginInit)(void);
typedef int (*PluginDeinit) (void); typedef int (*PluginDeinit)(void);
typedef void (*PluginKeypress) (void); typedef void (*PluginKeypress)(void);
#ifdef __TINES_PLUGINS__ #ifdef __TINES_PLUGINS__
/* Available functions for plugins */ /* Available functions for plugins */
int plugin_install_keypressHandler(byte key, PluginKeypress); int plugin_install_keypressHandler(uint8_t key, PluginKeypress);
int plugin_remove_keypressHandler(byte key, PluginKeypress); int plugin_remove_keypressHandler(uint8_t key, PluginKeypress);
#else /* __TINES_PLUGINS__ */ #else /* __TINES_PLUGINS__ */
/* Available functions outside of plugins */ /* Available functions outside of plugins */
int plugin_keypress(byte key); int plugin_keypress();
/* Real Prototype: TBD */ /* Real Prototype: TBD */
void plugin_list(); void plugin_list();
int plugin_load(int id); int plugin_load(int id);
int plugin_unload(int id); int plugin_unload(int id);
#endif /* __TINES_PLUGINS__ */ #endif /* __TINES_PLUGINS__ */
#endif /* PLUGINS_H */ #endif /* PLUGINS_H */

View File

@ -1,14 +1,9 @@
/* /*
* PPU debug utilities - The TI-NESulator Project * PPU debug utilities - The peTI-NESulator Project
* ppu.debug.h * ppu.debug.h
* *
* Created by Manoel Trapier on 12/04/07. * Created by Manoël Trapier on 12/04/07.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */

View File

@ -1,16 +1,11 @@
/* /*
* PPU emulation - The TI-NESulator Project * PPU emulation - The peTI-NESulator Project
* ppu.h * ppu.h
* *
* 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 Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -31,13 +26,9 @@ typedef struct PPU_Sprite_
PPU must be initialized after memory initialisation.. PPU must be initialized after memory initialisation..
*/ */
int ppu_init(); int ppu_init();
int ppu_hblank(uint16_t scanline); int ppu_hblank(uint16_t scanline);
uint8_t ppu_readReg(uint8_t id); uint8_t ppu_readReg(uint8_t id);
void ppu_writeReg(uint8_t id, uint8_t val); void ppu_writeReg(uint8_t id, uint8_t val);
void ppu_fillSprRamDMA(uint8_t value); void ppu_fillSprRamDMA(uint8_t value);
#define PPU_MIRROR_HORIZTAL 0 #define PPU_MIRROR_HORIZTAL 0
@ -55,13 +46,9 @@ void ppu_fillSprRamDMA(uint8_t value);
void ppu_setMirroring(uint8_t direction); void ppu_setMirroring(uint8_t direction);
void ppu_setSingleScreen(uint8_t screen); void ppu_setSingleScreen(uint8_t screen);
void ppu_setScreenMode(uint8_t mode); void ppu_setScreenMode(uint8_t mode);
PPU_Sprite ppu_getSprite(uint16_t i); PPU_Sprite ppu_getSprite(uint16_t i);
uint8_t ppu_memoryRead(uint8_t page, uint8_t addr);
unsigned char ppu_memoryRead(uint8_t page, uint8_t addr); void ppu_memoryWrite(uint8_t page, uint8_t addr, uint8_t 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

@ -1,14 +1,9 @@
/* /*
* PPU Memory manager - The TI-NESulator Project * PPU Memory manager - The peTI-NESulator Project
* ppu.memory.h - Inspired from the memory manager of the Quick6502 Project. * ppu.memory.h - Inspired from the memory manager of the Quick6502 Project.
* *
* Created by Manoel Trapier on 12/04/07. * Created by Manoël Trapier on 12/04/07.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -16,18 +11,15 @@
int ppu_initMemory(); int ppu_initMemory();
void ppu_setPagePtr (byte page, byte *ptr); void ppu_setPagePtr(uint8_t page, uint8_t *ptr);
void ppu_setPagePtr1k(byte page, byte *ptr); void ppu_setPagePtr1k(uint8_t page, uint8_t *ptr);
void ppu_setPagePtr2k(byte page, byte *ptr); void ppu_setPagePtr2k(uint8_t page, uint8_t *ptr);
void ppu_setPagePtr4k(byte page, byte *ptr); void ppu_setPagePtr4k(uint8_t page, uint8_t *ptr);
void ppu_setPagePtr8k(byte page, byte *ptr); void ppu_setPagePtr8k(uint8_t page, uint8_t *ptr);
void ppu_memoryDumpState(FILE *fp); void ppu_memoryDumpState(FILE *fp);
uint8_t ppu_readMemory(uint8_t page, uint8_t addr);
byte ppu_readMemory(byte page, byte addr); void ppu_writeMemory(uint8_t page, uint8_t addr, uint8_t value);
void ppu_writeMemory(byte page, byte addr, byte value); void ppu_setPageGhost(uint8_t page, uint8_t value, uint8_t ghost);
void ppu_setPageGhost(byte page, bool value, byte ghost);
#else #else
#error Must only be included inside the PPU code #error Must only be included inside the PPU code

58
src/include/text.h Normal file
View File

@ -0,0 +1,58 @@
/*
* FbLib graphic library
*
* Created by Manoël TRAPIER.
* Copyright (c) 2003-2019 986-Studio. All rights reserved.
*
*/
#ifndef _FBLIB_INCLUDE_TEXT_H
#define _FBLIB_INCLUDE_TEXT_H
typedef struct FBLibFont
{
char *name; /* Font name. */
int height; /* Height in pixels. */
int index_mask; /* ((1 << N) - 1). */
int *offset; /* (1 << N) offsets into index. */
int *index;
uint32_t *content;
//void *private;
} FBLibFont;
/* ? */
FBLibFont *load_psf(char *filename);
void graphics_text_line(int x, int y, int w, int charw, uint32_t color, int valign, void *font, char *text);
int graphics_text_ex(int x, int y, int w, int h,
void *font,
uint32_t bgcolor, uint32_t fgcolor,
char valign, char halign,
uint16_t options,
void *format, ...);
void graphics_get_text_size(int *width, int *height,
const FBLibFont *font,
const char *text);
void graphics_draw_text (int x, int y,
uint32_t colour,
const FBLibFont *font,
const char *text);
#define TEXT_VALIGN_LEFT (1)
#define TEXT_VALIGN_RIGHT (2)
#define TEXT_VALIGN_CENTER (3)
#define TEXT_HALIGN_TOP (1)
#define TEXT_HALIGN_CENTER (2)
#define TEXT_HALIGN_BOTTOM (3)
#define TEXT_OPT_WORDWRAP (1<<0)
#define TEXT_DEFAULTFONT ((void*)(1))
#define TEXT_SMALLFONT ((void*)(2))
#define TEXT_LARGEFONT ((void*)(3))
#endif /* _FBLIB_INCLUDE_TEXT_H */

View File

@ -1,14 +1,9 @@
/* /*
* Base type definitions - The TI-NESulator Project * Base type definitions - The peTI-NESulator Project
* types.h - Taken from the Quick6502 project * types.h - Taken from the Quick6502 project
* *
* Created by Manoel Trapier on 18/09/06. * Created by Manoël Trapier on 18/09/06.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -17,13 +12,6 @@
#include <stdint.h> #include <stdint.h>
#ifndef BYTE_TYPE_DEFINED
#define BYTE_TYPE_DEFINED
typedef uint8_t byte;
#endif
typedef uint8_t bool;
#define true (0) #define true (0)
#define false (!true) #define false (!true)

192
src/log.c
View File

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

1655
src/main.c

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,10 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2016 986-Studio. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
file(GLOB mappers_list mappers/*.c) file(GLOB mappers_list mappers/*.c)

View File

@ -1,14 +1,9 @@
/* /*
* Mapper manager - The TI-NESulator Project * Mapper manager - The peTI-NESulator Project
* manager.c * manager.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -19,53 +14,55 @@
#include <os_dependent.h> #include <os_dependent.h>
MapperIRQ mapper_irqloop; MapperIRQ mapper_irqloop;
MapperDump mapper_dump; MapperDump mapper_dump;
MapperWriteHook mapper_hook; MapperWriteHook mapper_hook;
typedef struct Mapper_ typedef struct Mapper_
{ {
byte id; uint8_t id;
char *name; char *name;
MapperInit init; MapperInit init;
MapperIRQ irq; MapperIRQ irq;
MapperDump dump; MapperDump dump;
} Mapper; } Mapper;
#include "mappers_list.h" #include "mappers_list.h"
void mapper_list () void mapper_list()
{ {
Mapper *ptr = &(Mappers[0]); Mapper *ptr = &(Mappers[0]);
console_printf(Console_Default, "Available mapers:\n"); console_printf(Console_Default, "Available mappers:\n");
while(ptr->name != NULL) while (ptr->name != NULL)
{ {
console_printf(Console_Default, "%d - %s\n", ptr->id, ptr->name); console_printf(Console_Default, "%d - %s\n", ptr->id, ptr->name);
ptr++; ptr++;
} }
} }
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 #%d:\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 #%d - '%s'\n", ptr->id, ptr->name); console_printf(Console_Default, "Found mapper ID #%d - '%s'\n", ptr->id, ptr->name);
if (ptr->init) if (ptr->init)
ptr->init (cart); {
ptr->init(cart);
mapper_irqloop = ptr->irq; }
mapper_dump = ptr->dump;
mapper_irqloop = ptr->irq;
return 0; mapper_dump = ptr->dump;
}
ptr++; return 0;
} }
console_printf (Console_Default, "No compatible mapper found!\n"); ptr++;
return -1; }
console_printf(Console_Default, "No compatible mapper found!\n");
return -1;
} }

View File

@ -1,65 +1,64 @@
/* /*
* AOROM Mapper - The TI-NESulator Project * AOROM Mapper - The peTI-NESulator Project
* aorom.c * aorom.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include "aorom.h" #include "aorom.h"
unsigned char aorom_load_bank; uint8_t aorom_load_bank;
void aorom_MapperWriteHook(register byte Addr, register byte Value); void aorom_MapperWriteHook(register uint8_t Addr, register uint8_t Value);
extern byte *ppu_mem_nameTables; extern uint8_t *ppu_mem_nameTables;
int aorom_InitMapper(NesCart * cart) int aorom_InitMapper(NesCart *cart)
{ {
int i; int i;
set_prom_bank_32k(0x8000,0); set_prom_bank_32k(0x8000, 0);
ppu_setScreenMode(PPU_SCMODE_SINGLE); ppu_setScreenMode(PPU_SCMODE_SINGLE);
aorom_load_bank = 0; aorom_load_bank = 0;
/* Register the write hook */ /* Register the write hook */
for (i = 0x80; i < 0x100; i++) for (i = 0x80 ; i < 0x100 ; i++)
{ {
set_page_wr_hook(i, aorom_MapperWriteHook); set_page_wr_hook(i, aorom_MapperWriteHook);
set_page_writeable(i, true); set_page_writeable(i, true);
} }
return 0; return 0;
}
void aorom_MapperWriteHook(register byte Addr, register byte Value) }
void aorom_MapperWriteHook(register uint8_t Addr, register uint8_t Value)
{ {
int BankNb; int BankNb;
if (Value & (1 << 4)) if (Value & (1 << 4))
ppu_setSingleScreen(PPU_SCREEN_000); {
else ppu_setSingleScreen(PPU_SCREEN_000);
ppu_setSingleScreen(PPU_SCREEN_400); }
else
{
ppu_setSingleScreen(PPU_SCREEN_400);
}
BankNb = Value & 0x0F; BankNb = Value & 0x0F;
aorom_load_bank = BankNb; aorom_load_bank = BankNb;
//console_printf(Console_Default, "aorom: Asking bank %d - NT is 0x%04X\n",BankNb,(Value&0x10)?0x2400:0x2000); //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);
} }
void aorom_MapperDump(FILE *fp) void aorom_MapperDump(FILE *fp)
{ {
fprintf(fp,"aorom: bank:%d\n",aorom_load_bank); fprintf(fp, "aorom: bank:%d\n", aorom_load_bank);
} }

View File

@ -1,19 +1,15 @@
/* /*
* AOROM Mapper - The TI-NESulator Project * AOROM Mapper - The peTI-NESulator Project
* aorom.h * aorom.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#define __TINES_MAPPERS__ #define __TINES_MAPPERS__
#include <mappers/manager.h> #include <mappers/manager.h>
int aorom_InitMapper(NesCart * cart); int aorom_InitMapper(NesCart *cart);
void aorom_MapperDump(FILE *fp); void aorom_MapperDump(FILE *fp);

View File

@ -1,49 +1,44 @@
/* /*
* CNROM Mapper - The TI-NESulator Project * CNROM Mapper - The peTI-NESulator Project
* cnrom.c * cnrom.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include "cnrom.h" #include "cnrom.h"
unsigned char cnrom_load_bank; uint8_t cnrom_load_bank;
void cnrom_MapperWriteHook(register byte Addr, register byte Value); void cnrom_MapperWriteHook(register uint8_t Addr, register uint8_t Value);
int cnrom_InitMapper(NesCart * cart) int cnrom_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 the last one */ set_prom_bank_16k(0xC000, GETLAST16KBANK(cart)); /* Set the last one */
cnrom_load_bank = 0; cnrom_load_bank = 0;
/* Register the write hook */ /* Register the write hook */
for (i = 0x80; i < 0x100; i++) for (i = 0x80 ; i < 0x100 ; i++)
{ {
set_page_wr_hook(i, cnrom_MapperWriteHook); set_page_wr_hook(i, cnrom_MapperWriteHook);
set_page_writeable(i, true); set_page_writeable(i, true);
} }
return 0; return 0;
} }
void cnrom_MapperWriteHook(register byte Addr, register byte Value) void cnrom_MapperWriteHook(register uint8_t Addr, register uint8_t Value)
{ {
set_prom_bank_16k(0x8000,Value); set_prom_bank_16k(0x8000, Value);
cnrom_load_bank = Value; cnrom_load_bank = Value;
} }
void cnrom_MapperDump(FILE *fp) void cnrom_MapperDump(FILE *fp)
{ {
fprintf(fp,"cnrom: bank:%d\n",cnrom_load_bank); fprintf(fp, "cnrom: bank:%d\n", cnrom_load_bank);
} }

View File

@ -1,19 +1,15 @@
/* /*
* CNROM Mapper - The TI-NESulator Project * CNROM Mapper - The peTI-NESulator Project
* cnrom.h * cnrom.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#define __TINES_MAPPERS__ #define __TINES_MAPPERS__
#include <mappers/manager.h> #include <mappers/manager.h>
int cnrom_InitMapper(NesCart * cart); int cnrom_InitMapper(NesCart *cart);
void cnrom_MapperDump(FILE *fp); void cnrom_MapperDump(FILE *fp);

View File

@ -1,14 +1,9 @@
/* /*
* Generic mapper implementation - The TI-NESulator Project * Generic mapper implementation - The peTI-NESulator Project
* genericmapper.h * genericmapper.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -22,7 +17,7 @@ int _InitMapper(NesCart * cart)
} }
int _MapperWriteHook(register word Addr, register byte Value) int _MapperWriteHook(register word Addr, register uint8_t Value)
{ {
if (Addr > 0x7FFF) /* Try to write to the rom */ if (Addr > 0x7FFF) /* Try to write to the rom */

View File

@ -1,34 +1,29 @@
/* /*
* IREMH3001 Mapper - The TI-NESulator Project * IREMH3001 Mapper - The peTI-NESulator Project
* iremh3001.c * iremh3001.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include "iremh3001.h" #include "iremh3001.h"
unsigned short iremh3001_prom_slot[3]; uint16_t iremh3001_prom_slot[3];
unsigned short iremh3001_vrom_slot[8]; uint16_t iremh3001_vrom_slot[8];
int iremh3001_InitMapper(NesCart * cart) int iremh3001_InitMapper(NesCart *cart)
{ {
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));
iremh3001_prom_slot[0] = 0; iremh3001_prom_slot[0] = 0;
iremh3001_prom_slot[1] = 1; iremh3001_prom_slot[1] = 1;
iremh3001_prom_slot[2] = GETLAST16KBANK(cart); iremh3001_prom_slot[2] = GETLAST16KBANK(cart);
set_vrom_bank_8k(0x0000,4); set_vrom_bank_8k(0x0000, 4);
iremh3001_vrom_slot[0] = 0; iremh3001_vrom_slot[0] = 0;
iremh3001_vrom_slot[1] = 0; iremh3001_vrom_slot[1] = 0;
@ -40,88 +35,88 @@ int iremh3001_InitMapper(NesCart * cart)
iremh3001_vrom_slot[7] = 0; iremh3001_vrom_slot[7] = 0;
return 0; return 0;
}
int iremh3001_MapperWriteHook(register byte Addr, register byte Value) }
int iremh3001_MapperWriteHook(register uint8_t Addr, register uint8_t Value)
{ {
#if 0 #if 0
switch(Addr) switch(Addr)
{ {
case 0x8000: /* Set 8k PROM @ 8000 */ case 0x8000: /* Set 8k PROM @ 8000 */
console_printf(Console_Default, "iremh3001: %X: change PROM to %d[%X]\n", Addr, Value, Value); console_printf(Console_Default, "iremh3001: %X: change PROM to %d[%X]\n", Addr, Value, Value);
set_prom_bank_8k(0x8000, Value); set_prom_bank_8k(0x8000, Value);
iremh3001_prom_slot[0] = Value; iremh3001_prom_slot[0] = Value;
break; break;
case 0x9003: /* Mirroring ??? */ case 0x9003: /* Mirroring ??? */
console_printf(Console_Default, "iremh3001: Mirroring[0x%X:%d] ?\n", Value, Value); console_printf(Console_Default, "iremh3001: Mirroring[0x%X:%d] ?\n", Value, Value);
break; break;
case 0x9005: /* IRQ ??? */ case 0x9005: /* IRQ ??? */
console_printf(Console_Default, "iremh3001: IRQ[0x%X:%d] ?\n", Value, Value); console_printf(Console_Default, "iremh3001: IRQ[0x%X:%d] ?\n", Value, Value);
break; break;
case 0x9006: /* IRQ ??? */ case 0x9006: /* IRQ ??? */
console_printf(Console_Default, "iremh3001: IRQ[0x%X:%d] ?\n", Value, Value); console_printf(Console_Default, "iremh3001: IRQ[0x%X:%d] ?\n", Value, Value);
break; break;
case 0xA000: /* Set 8k PROM @ A000 */ case 0xA000: /* Set 8k PROM @ A000 */
console_printf(Console_Default, "iremh3001: %X: change PROM to %d[%X]\n", Addr, Value, Value); console_printf(Console_Default, "iremh3001: %X: change PROM to %d[%X]\n", Addr, Value, Value);
set_prom_bank_8k(0xA000, Value); set_prom_bank_8k(0xA000, Value);
iremh3001_prom_slot[1] = Value; iremh3001_prom_slot[1] = Value;
break; break;
case 0xB000: /* Set 1k VROM @ 0000 */ case 0xB000: /* Set 1k VROM @ 0000 */
case 0xB001: /* Set 1k VROM @ 0400 */ case 0xB001: /* Set 1k VROM @ 0400 */
case 0xB002: /* Set 1k VROM @ 0800 */ case 0xB002: /* Set 1k VROM @ 0800 */
case 0xB003: /* Set 1k VROM @ 0C00 */ case 0xB003: /* Set 1k VROM @ 0C00 */
case 0xB004: /* Set 1k VROM @ 1000 */ case 0xB004: /* Set 1k VROM @ 1000 */
case 0xB005: /* Set 1k VROM @ 1400 */ case 0xB005: /* Set 1k VROM @ 1400 */
case 0xB006: /* Set 1k VROM @ 1800 */ case 0xB006: /* Set 1k VROM @ 1800 */
case 0xB007: /* Set 1k VROM @ 1C00 */ case 0xB007: /* Set 1k VROM @ 1C00 */
console_printf(Console_Default, "iremh3001: %X: change VROM to %d[%X]\n", (Addr&0x0F)<<10, Value, Value); console_printf(Console_Default, "iremh3001: %X: change VROM to %d[%X]\n", (Addr&0x0F)<<10, Value, Value);
set_vrom_bank_1k((Addr&0xF)<<10, Value); set_vrom_bank_1k((Addr&0xF)<<10, Value);
iremh3001_vrom_slot[Addr&0x0F] = Value; iremh3001_vrom_slot[Addr&0x0F] = Value;
break; break;
case 0xC000: /* Set 8k PROM @ C000 */ case 0xC000: /* Set 8k PROM @ C000 */
console_printf(Console_Default, "iremh3001: %X: change PROM to %d[%X]\n", Addr, Value, Value); console_printf(Console_Default, "iremh3001: %X: change PROM to %d[%X]\n", Addr, Value, Value);
set_prom_bank_8k(0xC000, Value); set_prom_bank_8k(0xC000, Value);
iremh3001_prom_slot[2] = Value; iremh3001_prom_slot[2] = Value;
break; break;
default: default:
console_printf(Console_Default, "@:%X -- V:%X", Addr, Value); console_printf(Console_Default, "@:%X -- V:%X", Addr, Value);
return 0; return 0;
} }
#endif #endif
return 1; return 1;
} }
void iremh3001_MapperDump(FILE *fp) void iremh3001_MapperDump(FILE *fp)
{ {
fprintf(fp,"iremh3001: prom: $8000:%d $A000:%d $C000:%d\n", fprintf(fp, "iremh3001: prom: $8000:%d $A000:%d $C000:%d\n",
iremh3001_prom_slot[0], iremh3001_prom_slot[0],
iremh3001_prom_slot[1], iremh3001_prom_slot[1],
iremh3001_prom_slot[2]); iremh3001_prom_slot[2]);
fprintf(fp,"iremh3001: vrom: $0000:%d $0400:%d $0800:%d $0C00:%d\n" \ fprintf(fp, "iremh3001: vrom: $0000:%d $0400:%d $0800:%d $0C00:%d\n" \
" $1000:%d $1400:%d $1800:%d $1C00:%d\n", " $1000:%d $1400:%d $1800:%d $1C00:%d\n",
iremh3001_vrom_slot[0], iremh3001_vrom_slot[0],
iremh3001_vrom_slot[1], iremh3001_vrom_slot[1],
iremh3001_vrom_slot[2], iremh3001_vrom_slot[2],
iremh3001_vrom_slot[3], iremh3001_vrom_slot[3],
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_vrom_slot[7]); iremh3001_vrom_slot[7]);
} }
int iremh3001_MapperIRQ(int cycledone) int iremh3001_MapperIRQ(int cycledone)
{ {
return 0; return 0;
} }

View File

@ -1,20 +1,16 @@
/* /*
* IREMH3001 Mapper - The TI-NESulator Project * IREMH3001 Mapper - The peTI-NESulator Project
* iremh3001.h * iremh3001.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#define __TINES_MAPPERS__ #define __TINES_MAPPERS__
#include <mappers/manager.h> #include <mappers/manager.h>
int iremh3001_InitMapper(NesCart * cart); int iremh3001_InitMapper(NesCart *cart);
void iremh3001_MapperDump(FILE *fp); void iremh3001_MapperDump(FILE *fp);
int iremh3001_MapperIRQ(int cycledone); int iremh3001_MapperIRQ(int cycledone);

View File

@ -1,14 +1,9 @@
/* /*
* MMC1 Mapper - The TI-NESulator Project * MMC1 Mapper - The peTI-NESulator Project
* mmc1.h * mmc1.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -44,67 +39,69 @@ uint8_t mmc1_CurrentBank;
#define MMC1_R3_RESET 0x80 #define MMC1_R3_RESET 0x80
#define MMC1_REG0_DEFAULT MMC1_R0_PRGSIZE | MMC1_R0_PRGAREA #define MMC1_REG0_DEFAULT (MMC1_R0_PRGSIZE | MMC1_R0_PRGAREA)
#define MMC1_REG1_DEFAULT 0 #define MMC1_REG1_DEFAULT (0)
#define MMC1_REG2_DEFAULT 0 #define MMC1_REG2_DEFAULT (0)
#define MMC1_REG3_DEFAULT 0 #define MMC1_REG3_DEFAULT (0)
void mmc1_MapperWriteReg0(register byte Addr, register byte Value); void mmc1_MapperWriteReg0(register uint8_t Addr, register uint8_t Value);
void mmc1_MapperWriteReg1(register byte Addr, register byte Value); void mmc1_MapperWriteReg1(register uint8_t Addr, register uint8_t Value);
void mmc1_MapperWriteReg2(register byte Addr, register byte Value); void mmc1_MapperWriteReg2(register uint8_t Addr, register uint8_t Value);
void mmc1_MapperWriteReg3(register byte Addr, register byte Value); void mmc1_MapperWriteReg3(register uint8_t Addr, register uint8_t Value);
void mmc1_MapperDump(FILE *fp) void mmc1_MapperDump(FILE *fp)
{ {
fprintf(fp,"MMC1: r0:0x%02X r1:0x%02X r2:0x%02X r3:0x%02X\n",MMC1_reg0,MMC1_reg1,MMC1_reg2,MMC1_reg3); fprintf(fp, "MMC1: r0:0x%02X r1:0x%02X r2:0x%02X r3:0x%02X\n", MMC1_reg0, MMC1_reg1, MMC1_reg2, MMC1_reg3);
} }
int mmc1_InitMapper(NesCart * cart) int mmc1_InitMapper(NesCart *cart)
{ {
int i; int i;
MMC1_reg0 = MMC1_REG0_DEFAULT;
MMC1_reg1 = MMC1_REG1_DEFAULT;
MMC1_reg2 = MMC1_REG2_DEFAULT;
MMC1_reg3 = MMC1_REG3_DEFAULT;
set_prom_bank_16k(0x8000,0);
set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
mmc1_CurrentBank = 0;
if (cart->VROMSize > 0)
set_vrom_bank_4k(0x0000,0);
MMC1_reg0 = MMC1_REG0_DEFAULT;
/* Mapper should register itself for write hook */
for (i = 0x80; i < 0xA0 ; i++) MMC1_reg1 = MMC1_REG1_DEFAULT;
MMC1_reg2 = MMC1_REG2_DEFAULT;
MMC1_reg3 = MMC1_REG3_DEFAULT;
set_prom_bank_16k(0x8000, 0);
set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
mmc1_CurrentBank = 0;
if (cart->VROMSize > 0)
{ {
set_page_wr_hook(i, mmc1_MapperWriteReg0); set_vrom_bank_4k(0x0000, 0);
set_page_writeable(i, true);
}
for (i = 0xA0; i < 0xC0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg1);
set_page_writeable(i, true);
}
for (i = 0xC0; i < 0xE0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg2);
set_page_writeable(i, true);
}
for (i = 0xE0; i < 0x100 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg3);
set_page_writeable(i, true);
} }
/* Mapper should register itself for write hook */
for (i = 0x80 ; i < 0xA0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg0);
set_page_writeable(i, true);
}
for (i = 0xA0 ; i < 0xC0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg1);
set_page_writeable(i, true);
}
for (i = 0xC0 ; i < 0xE0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg2);
set_page_writeable(i, true);
}
for (i = 0xE0 ; i < 0x100 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg3);
set_page_writeable(i, true);
}
return 0; return 0;
} }
/* /*
@ -125,24 +122,26 @@ Reg 0
F : 1111 F : 1111
((Addr & 0x6000) >> 13) <- port number ((Addr & 0x6000) >> 13) <- port number
*/ */
#define MMC1_GetReg(a) ((a & 0x6000) >> 13)
/* (Val & 0x01) recuperation du bit */
#define MMC1_GetBit(v) (v & 0x01)
/* ( ( b & (1 << Bit)) | (v << Bit) ) Ajout du bit */
#define MMC1_AddBit(b,v) ( ( b & ~(1 << Bit)) | (v << Bit) )
void mmc1_ApplyReg0Mod() #define MMC1_GetReg(_a) (((_a) & 0x6000) >> 13)
/* (Val & 0x01) recuperation du bit */
#define MMC1_GetBit(_v) ((_v) & 0x01)
/* ( ( b & (1 << Bit)) | (v << Bit) ) Ajout du bit */
#define MMC1_AddBit(_b, _v) ( ( (_b) & ~(1 << Bit)) | ( (_v) << Bit) )
void mmc1_ApplyReg0Mod()
{ {
static uint8_t OldSwitchArea = MMC1_R0_PRGAREA; static uint8_t OldSwitchArea = MMC1_R0_PRGAREA;
//console_printf(Console_Default, "Change to reg0 done ! (0x%x)\n\tMiror flag : %d\n\tOneScreen Flag : %d\n\tPRG Size : %d\n\tPRG Area : %d\n\tVROM Switch size : %d\n", MMC1_reg0, MMC1_reg0 & MMC1_R0_MIRROR, MMC1_reg0 & MMC1_R0_ONESCREEN, MMC1_reg0 & MMC1_R0_PRGAREA, MMC1_reg0 & MMC1_R0_PRGSIZE, MMC1_reg0 & MMC1_R0_VROMSW); //console_printf(Console_Default, "Change to reg0 done ! (0x%x)\n\tMiror flag : %d\n\tOneScreen Flag : %d\n\tPRG Size : %d\n\tPRG Area : %d\n\tVROM Switch size : %d\n", MMC1_reg0, MMC1_reg0 & MMC1_R0_MIRROR, MMC1_reg0 & MMC1_R0_ONESCREEN, MMC1_reg0 & MMC1_R0_PRGAREA, MMC1_reg0 & MMC1_R0_PRGSIZE, MMC1_reg0 & MMC1_R0_VROMSW);
switch (MMC1_reg0 & 0x03) switch (MMC1_reg0 & 0x03)
{ {
default:
case 0: case 0:
ppu_setScreenMode(PPU_SCMODE_SINGLE); ppu_setScreenMode(PPU_SCMODE_SINGLE);
ppu_setSingleScreen(PPU_SCREEN_000); ppu_setSingleScreen(PPU_SCREEN_000);
@ -160,38 +159,38 @@ void mmc1_ApplyReg0Mod()
ppu_setMirroring(PPU_MIRROR_HORIZTAL); ppu_setMirroring(PPU_MIRROR_HORIZTAL);
break; break;
} }
if ( (OldSwitchArea != (MMC1_reg0 & MMC1_R0_PRGAREA)) && ((MMC1_reg0 & MMC1_R0_PRGSIZE) != 0 ) ) if ((OldSwitchArea != (MMC1_reg0 & MMC1_R0_PRGAREA)) && ((MMC1_reg0 & MMC1_R0_PRGSIZE) != 0))
{ {
if ((MMC1_reg0 & MMC1_R0_PRGAREA) != 0) if ((MMC1_reg0 & MMC1_R0_PRGAREA) != 0)
{ /* 0x8000 area */ { /* 0x8000 area */
set_prom_bank_16k(0x8000,mmc1_CurrentBank); set_prom_bank_16k(0x8000, mmc1_CurrentBank);
set_prom_bank_16k(0xC000, GETLAST16KBANK(Cart)); set_prom_bank_16k(0xC000, GETLAST16KBANK(Cart));
} }
else else
{ /* 0xC000 area */ { /* 0xC000 area */
set_prom_bank_16k(0x8000,0);
set_prom_bank_16k(0xC000,mmc1_CurrentBank);
} set_prom_bank_16k(0x8000, 0);
set_prom_bank_16k(0xC000, mmc1_CurrentBank);
}
OldSwitchArea = (MMC1_reg0 & MMC1_R0_PRGAREA); OldSwitchArea = (MMC1_reg0 & MMC1_R0_PRGAREA);
} }
} }
uint32_t VROMBankNb; uint32_t VROMBankNb;
uint8_t Bit = 0; uint8_t Bit = 0;
uint8_t BitBuf = 0; uint8_t BitBuf = 0;
void mmc1_MapperWriteReg0(register byte Addr, register byte Value) void mmc1_MapperWriteReg0(register uint8_t Addr, register uint8_t Value)
{ {
if (Value & 0x80) if (Value & 0x80)
{ {
MMC1_reg0 = MMC1_REG0_DEFAULT; MMC1_reg0 = MMC1_REG0_DEFAULT;
console_printf(Console_Default, "MMC1: Reg0 Reset occured !\n"); console_printf(Console_Default, "MMC1: Reg0 Reset occurred !\n");
mmc1_ApplyReg0Mod(); mmc1_ApplyReg0Mod();
} }
else else
@ -200,25 +199,25 @@ void mmc1_MapperWriteReg0(register byte Addr, register byte Value)
{ /* Pas encore ecrit les 5 bits */ { /* Pas encore ecrit les 5 bits */
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit++; Bit++;
} }
else else
{ {
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit = 0; Bit = 0;
MMC1_reg0 = BitBuf; MMC1_reg0 = BitBuf;
mmc1_ApplyReg0Mod(); mmc1_ApplyReg0Mod();
} }
} }
} }
void mmc1_MapperWriteReg1(register byte Addr, register byte Value) void mmc1_MapperWriteReg1(register uint8_t Addr, register uint8_t Value)
{ {
if (Value & 0x80) if (Value & 0x80)
{ {
MMC1_reg1 = MMC1_REG1_DEFAULT; MMC1_reg1 = MMC1_REG1_DEFAULT;
console_printf(Console_Default, "MMC1: Reg1 Reset occured !\n"); console_printf(Console_Default, "MMC1: Reg1 Reset occurred !\n");
} }
else else
{ {
@ -226,42 +225,43 @@ void mmc1_MapperWriteReg1(register byte Addr, register byte Value)
{ /* Pas encore ecrit les 5 bits */ { /* Pas encore ecrit les 5 bits */
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit++; Bit++;
} }
else else
{ {
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit = 0; Bit = 0;
MMC1_reg1 = BitBuf; MMC1_reg1 = BitBuf;
VROMBankNb = (MMC1_reg1 /* & MMC1_R1_VROMB1 */ ); VROMBankNb = (MMC1_reg1 /* & MMC1_R1_VROMB1 */ );
if (Cart->VROMSize == 0) if (Cart->VROMSize == 0)
{ {
console_printf(Console_Default, "Try to change VROM but with didn't have any VROM ! [%04X]\n", VROMBankNb); console_printf(Console_Default, "Try to change VROM but with didn't have any VROM ! [%04X]\n",
VROMBankNb);
return; return;
} }
if ( (MMC1_reg0 & MMC1_R0_VROMSW) != 0 ) if ((MMC1_reg0 & MMC1_R0_VROMSW) != 0)
{ /* 4K vram */ { /* 4K vram */
//console_printf(Console_Default, "Switching VROM at 0x0000 to 4k bank %d\n", VROMBankNb); //console_printf(Console_Default, "Switching VROM at 0x0000 to 4k bank %d\n", VROMBankNb);
set_vrom_bank_4k(0x0000,VROMBankNb); set_vrom_bank_4k(0x0000, VROMBankNb);
} }
else else
{ /* 8K vram */ { /* 8K vram */
//console_printf(Console_Default, "Switching VROM at 0x0000 to 8k bank %d\n", VROMBankNb>>1); //console_printf(Console_Default, "Switching VROM at 0x0000 to 8k bank %d\n", VROMBankNb>>1);
set_vrom_bank_8k(0x0000,VROMBankNb>>1); set_vrom_bank_8k(0x0000, VROMBankNb >> 1);
} }
} }
} }
} }
void mmc1_MapperWriteReg2(register byte Addr, register byte Value) void mmc1_MapperWriteReg2(register uint8_t Addr, register uint8_t Value)
{ {
if (Value & 0x80) if (Value & 0x80)
{ {
MMC1_reg2 = MMC1_REG2_DEFAULT; MMC1_reg2 = MMC1_REG2_DEFAULT;
console_printf(Console_Default, "MMC1: Reg2 Reset occured !\n"); console_printf(Console_Default, "MMC1: Reg2 Reset occurred !\n");
} }
else else
{ {
@ -269,43 +269,43 @@ void mmc1_MapperWriteReg2(register byte Addr, register byte Value)
{ /* Pas encore ecrit les 5 bits */ { /* Pas encore ecrit les 5 bits */
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit++; Bit++;
} }
else else
{ {
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit = 0; Bit = 0;
MMC1_reg2 = BitBuf; MMC1_reg2 = BitBuf;
VROMBankNb = (MMC1_reg2 /* & MMC1_R2_VROMB2 */ ); VROMBankNb = (MMC1_reg2 /* & MMC1_R2_VROMB2 */ );
//console_printf(Console_Default, "Want to switch VROM at 0x1000 to 4k bank %d\n", VROMBankNb); //console_printf(Console_Default, "Want to switch VROM at 0x1000 to 4k bank %d\n", VROMBankNb);
if (Cart->VROMSize == 0) if (Cart->VROMSize == 0)
{ {
//console_printf(Console_Default, ": No\n"); //console_printf(Console_Default, ": No\n");
return; return;
} }
if ( (MMC1_reg0 & MMC1_R0_VROMSW) != 0 ) if ((MMC1_reg0 & MMC1_R0_VROMSW) != 0)
{ /* 4K vram */ { /* 4K vram */
//console_printf(Console_Default, "Switching VROM at 0x1000 to 4k bank %d\n", VROMBankNb); //console_printf(Console_Default, "Switching VROM at 0x1000 to 4k bank %d\n", VROMBankNb);
set_vrom_bank_4k(0x1000,VROMBankNb); set_vrom_bank_4k(0x1000, VROMBankNb);
} }
else else
{ /* 8K vram */ { /* 8K vram */
// console_printf(Console_Default, "Switching VROM at 0x1000 to 8k bank %d\n", VROMBankNb>>1); // console_printf(Console_Default, "Switching VROM at 0x1000 to 8k bank %d\n", VROMBankNb>>1);
// set_vrom_bank_8k(0x1000,VROMBankNb>>1); // set_vrom_bank_8k(0x1000,VROMBankNb>>1);
} }
} }
} }
} }
void mmc1_MapperWriteReg3(register byte Addr, register byte Value) void mmc1_MapperWriteReg3(register uint8_t Addr, register uint8_t Value)
{ {
if (Value & 0x80) if (Value & 0x80)
{ {
MMC1_reg3 = MMC1_REG3_DEFAULT; MMC1_reg3 = MMC1_REG3_DEFAULT;
console_printf(Console_Default, "MMC1: Reg3 Reset occured !\n"); console_printf(Console_Default, "MMC1: Reg3 Reset occurred !\n");
} }
else else
{ {
@ -313,36 +313,38 @@ void mmc1_MapperWriteReg3(register byte Addr, register byte Value)
{ /* Pas encore ecrit les 5 bits */ { /* Pas encore ecrit les 5 bits */
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit++; Bit++;
} }
else else
{ {
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit = 0; Bit = 0;
MMC1_reg3 = BitBuf; MMC1_reg3 = BitBuf;
if ( ((uint32_t)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)
{ /* 16K Switch */ { /* 16K Switch */
if ( (MMC1_reg0 & MMC1_R0_PRGAREA) != 0 ) if ((MMC1_reg0 & MMC1_R0_PRGAREA) != 0)
{ /* 0x8000 switch */ { /* 0x8000 switch */
set_prom_bank_16k(0x8000,MMC1_reg3); set_prom_bank_16k(0x8000, MMC1_reg3);
//console_printf(Console_Default, "LowBank is now %d ( 0x%p )\n", MMC1_reg3, mLBank); //console_printf(Console_Default, "LowBank is now %d ( 0x%p )\n", MMC1_reg3, mLBank);
} }
else else
{ /* 0xC000 switch */ { /* 0xC000 switch */
set_prom_bank_16k(0xC000,MMC1_reg3); set_prom_bank_16k(0xC000, MMC1_reg3);
//console_printf(Console_Default, "HighBank is now %d ( 0x%p )\n", MMC1_reg3, mUBank); //console_printf(Console_Default, "HighBank is now %d ( 0x%p )\n", MMC1_reg3, mUBank);
} }
} }
else else
{ /* 32K Switch */ { /* 32K Switch */
set_prom_bank_32k(0x8000,MMC1_reg3>>1); set_prom_bank_32k(0x8000, MMC1_reg3 >> 1);
} }
if ( ( MMC1_reg3 & MMC1_R3_SAVECE ) != 0) if ((MMC1_reg3 & MMC1_R3_SAVECE) != 0)
{ {
unmap_sram(); unmap_sram();
} }
@ -352,6 +354,6 @@ void mmc1_MapperWriteReg3(register byte Addr, register byte Value)
} }
} }
} }
} }
//console_printf(Console_Default, "MMC1: Debug (Reg:%d,Val:0x%02X,reg0:0x%02X,reg1:0x%02X,reg2:0x%02X,reg3:0x%02X)\n", MMC1_GetReg(Addr), Value, MMC1_reg0, MMC1_reg1, MMC1_reg2, MMC1_reg3); //console_printf(Console_Default, "MMC1: Debug (Reg:%d,Val:0x%02X,reg0:0x%02X,reg1:0x%02X,reg2:0x%02X,reg3:0x%02X)\n", MMC1_GetReg(Addr), Value, MMC1_reg0, MMC1_reg1, MMC1_reg2, MMC1_reg3);

View File

@ -1,20 +1,16 @@
/* /*
* MMC1 Mapper - The TI-NESulator Project * MMC1 Mapper - The peTI-NESulator Project
* mmc1.h * mmc1.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#define __TINES_MAPPERS__ #define __TINES_MAPPERS__
#include <mappers/manager.h> #include <mappers/manager.h>
int mmc1_InitMapper (NesCart *cart); int mmc1_InitMapper(NesCart *cart);
int mmc1_MapperIRQ (int cycledone); int mmc1_MapperIRQ(int cycledone);
void mmc1_MapperDump (); void mmc1_MapperDump(FILE *fp);

View File

@ -1,217 +1,220 @@
/* /*
* MMC3 Mapper - The TI-NESulator Project * MMC3 Mapper - The peTI-NESulator Project
* mmc3.h * mmc3.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include "mmc3.h" #include "mmc3.h"
extern unsigned short ScanLine; extern uint16_t ScanLine;
unsigned short mmc3_command; uint16_t mmc3_command;
unsigned char mmc3_irq_counter; uint8_t mmc3_irq_counter;
unsigned char mmc3_irq_counter_reload; uint8_t mmc3_irq_counter_reload;
unsigned char mmc3_irq_enable; uint8_t mmc3_irq_enable;
unsigned short mmc3_first_prom_page; uint16_t mmc3_first_prom_page;
unsigned short mmc3_second_prom_page; uint16_t mmc3_second_prom_page;
unsigned char mmc3_use_xor; uint8_t mmc3_use_xor;
unsigned char mmc3_last_vrom[6]; uint8_t mmc3_last_vrom[6];
unsigned char mmc3_last_prom[2]; uint8_t mmc3_last_prom[2];
unsigned char mmc3_last_prom_switch; uint8_t mmc3_last_prom_switch;
unsigned short dummy; uint16_t dummy;
void mmc3_MapperWrite80Hook(byte addr, byte value); void mmc3_MapperWrite80Hook(uint8_t addr, uint8_t Value);
void mmc3_MapperWriteA0Hook(byte addr, byte value); void mmc3_MapperWriteA0Hook(uint8_t addr, uint8_t Value);
void mmc3_MapperWriteC0Hook(byte addr, byte value); void mmc3_MapperWriteC0Hook(uint8_t addr, uint8_t Value);
void mmc3_MapperWriteE0Hook(byte addr, byte value); void mmc3_MapperWriteE0Hook(uint8_t addr, uint8_t Value);
void mmc3_MapperDump(FILE *fp) void mmc3_MapperDump(FILE *fp)
{ {
fprintf(fp,"MMC3: CMD:%d IC:%d IR:%d IE:%d FPP:0x%04X SPP:0x%04X UX:%d\n",mmc3_command,mmc3_irq_counter,mmc3_irq_counter_reload,mmc3_irq_enable,mmc3_first_prom_page,mmc3_second_prom_page,mmc3_use_xor); fprintf(fp, "MMC3: CMD:%d IC:%d IR:%d IE:%d FPP:0x%04X SPP:0x%04X UX:%d\n", mmc3_command, mmc3_irq_counter,
fprintf(fp,"MMC3: LV0:%d LV1:%d LV2:%d LV3:%d LV4:%d LV5:%d\n",mmc3_last_vrom[0],mmc3_last_vrom[1],mmc3_last_vrom[2],mmc3_last_vrom[3],mmc3_last_vrom[4],mmc3_last_vrom[5]); mmc3_irq_counter_reload, mmc3_irq_enable, mmc3_first_prom_page, mmc3_second_prom_page, mmc3_use_xor);
fprintf(fp,"MMC3: LP0:%d LP1:%d LPS:%d\n",mmc3_last_prom[0],mmc3_last_prom[1],mmc3_last_prom_switch); fprintf(fp, "MMC3: LV0:%d LV1:%d LV2:%d LV3:%d LV4:%d LV5:%d\n", mmc3_last_vrom[0], mmc3_last_vrom[1],
mmc3_last_vrom[2], mmc3_last_vrom[3], mmc3_last_vrom[4], mmc3_last_vrom[5]);
fprintf(fp, "MMC3: LP0:%d LP1:%d LPS:%d\n", mmc3_last_prom[0], mmc3_last_prom[1], mmc3_last_prom_switch);
} }
int mmc3_InitMapper(NesCart * cart) int mmc3_InitMapper(NesCart *cart)
{ {
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)
{ {
set_vrom_bank_8k(0, 0x0000); set_vrom_bank_8k(0, 0x0000);
} }
mmc3_command = -1; mmc3_command = -1;
mmc3_irq_counter = -1; mmc3_irq_counter = -1;
mmc3_irq_enable = 0; mmc3_irq_enable = 0;
mmc3_irq_counter_reload = 0; mmc3_irq_counter_reload = 0;
mmc3_use_xor = 0x42; mmc3_use_xor = 0x42;
mmc3_last_prom_switch = 0x42; mmc3_last_prom_switch = 0x42;
mmc3_last_prom[0] = 0; mmc3_last_prom[0] = 0;
mmc3_last_prom[1] = 1; mmc3_last_prom[1] = 1;
mmc3_last_vrom[0] = 0; mmc3_last_vrom[0] = 0;
mmc3_last_vrom[1] = 2; mmc3_last_vrom[1] = 2;
mmc3_last_vrom[2] = 3; mmc3_last_vrom[2] = 3;
mmc3_last_vrom[3] = 4; mmc3_last_vrom[3] = 4;
mmc3_last_vrom[4] = 5; mmc3_last_vrom[4] = 5;
mmc3_last_vrom[5] = 6; mmc3_last_vrom[5] = 6;
mmc3_first_prom_page = 0x8000; mmc3_first_prom_page = 0x8000;
mmc3_second_prom_page = 0xA000; mmc3_second_prom_page = 0xA000;
/* Register mapper write hook */ /* Register mapper write hook */
set_page_wr_hook(0x80, mmc3_MapperWrite80Hook); set_page_wr_hook(0x80, mmc3_MapperWrite80Hook);
set_page_writeable(0x80, true); set_page_writeable(0x80, true);
set_page_wr_hook(0xA0, mmc3_MapperWriteA0Hook); set_page_wr_hook(0xA0, mmc3_MapperWriteA0Hook);
set_page_writeable(0xA0, true); set_page_writeable(0xA0, true);
set_page_wr_hook(0xC0, mmc3_MapperWriteC0Hook); set_page_wr_hook(0xC0, mmc3_MapperWriteC0Hook);
set_page_writeable(0xC0, true); set_page_writeable(0xC0, true);
set_page_wr_hook(0xE0, mmc3_MapperWriteE0Hook); set_page_wr_hook(0xE0, mmc3_MapperWriteE0Hook);
set_page_writeable(0xE0, true); set_page_writeable(0xE0, true);
return 0; return 0;
} }
void mmc3_MapperWrite80Hook(byte addr, byte Value) void mmc3_MapperWrite80Hook(uint8_t addr, uint8_t Value)
{ {
//console_printf(Console_Default, "%s(0x%02X, 0x%02X)\n", __func__, addr, Value); //console_printf(Console_Default, "%s(0x%02X, 0x%02X)\n", __func__, addr, Value);
if (addr > 0x01) if (addr > 0x01)
{
return; return;
}
if (!addr) if (!addr)
{ {
if ((Cart->VROMSize > 0) && ( mmc3_use_xor != (Value & 0x80) )) if ((Cart->VROMSize > 0) && (mmc3_use_xor != (Value & 0x80)))
{ {
if (Value & 0x80) if (Value & 0x80)
{ {
set_vrom_bank_1k(0x0000, mmc3_last_vrom[2]); set_vrom_bank_1k(0x0000, mmc3_last_vrom[2]);
set_vrom_bank_1k(0x0400, mmc3_last_vrom[3]); set_vrom_bank_1k(0x0400, mmc3_last_vrom[3]);
set_vrom_bank_1k(0x0800, mmc3_last_vrom[4]); set_vrom_bank_1k(0x0800, mmc3_last_vrom[4]);
set_vrom_bank_1k(0x0C00, mmc3_last_vrom[5]); set_vrom_bank_1k(0x0C00, mmc3_last_vrom[5]);
set_vrom_bank_2k(0x1000, mmc3_last_vrom[0]>>1); set_vrom_bank_2k(0x1000, mmc3_last_vrom[0] >> 1);
set_vrom_bank_2k(0x1800, mmc3_last_vrom[1]>>1); set_vrom_bank_2k(0x1800, mmc3_last_vrom[1] >> 1);
//chr4,chr5,chr6,chr7,chr01,chr01+1,chr23,chr23+1 //chr4,chr5,chr6,chr7,chr01,chr01+1,chr23,chr23+1
} }
else else
{ {
set_vrom_bank_2k(0x0000, mmc3_last_vrom[0]>>1); set_vrom_bank_2k(0x0000, mmc3_last_vrom[0] >> 1);
set_vrom_bank_2k(0x0800, mmc3_last_vrom[1]>>1); set_vrom_bank_2k(0x0800, mmc3_last_vrom[1] >> 1);
set_vrom_bank_1k(0x1000, mmc3_last_vrom[2]); set_vrom_bank_1k(0x1000, mmc3_last_vrom[2]);
set_vrom_bank_1k(0x1400, mmc3_last_vrom[3]); set_vrom_bank_1k(0x1400, mmc3_last_vrom[3]);
set_vrom_bank_1k(0x1800, mmc3_last_vrom[4]); set_vrom_bank_1k(0x1800, mmc3_last_vrom[4]);
set_vrom_bank_1k(0x1C00, mmc3_last_vrom[5]); set_vrom_bank_1k(0x1C00, mmc3_last_vrom[5]);
//chr01,chr01+1,chr23,chr23+1,chr4,chr5,chr6,chr7 //chr01,chr01+1,chr23,chr23+1,chr4,chr5,chr6,chr7
} }
mmc3_use_xor = (Value & 0x80); mmc3_use_xor = (Value & 0x80);
} }
if (mmc3_last_prom_switch != (Value & 0x40))
{
if (!(Value & 0x40))
{
console_printf(Console_Default, "MMC3: Switch -> 8/A\n");
mmc3_first_prom_page = 0x8000;
mmc3_second_prom_page = 0xA000;
set_prom_bank_8k(mmc3_first_prom_page, mmc3_last_prom[0]);
set_prom_bank_8k(mmc3_second_prom_page, mmc3_last_prom[1]);
set_prom_bank_8k(0xC000, GETLAST08KBANK(Cart)-1);
//set_prom_bank_8k(0xE000, GETLAST08KBANK(cart));
//prg_bank(prg0,prg1,max_prg-1,max_prg);
}
else
{
console_printf(Console_Default, "MMC3: Switch -> C/A\n");
mmc3_first_prom_page = 0xC000;
mmc3_second_prom_page = 0xA000;
set_prom_bank_8k(mmc3_first_prom_page, mmc3_last_prom[0]);
set_prom_bank_8k(mmc3_second_prom_page, mmc3_last_prom[1]);
set_prom_bank_8k(0x8000, GETLAST08KBANK(Cart)-1);
//prg_bank(max_prg-1,prg1,prg0,max_prg);
}
mmc3_last_prom_switch = (Value & 0x40);
}
mmc3_command = Value & 0x07;
} else { /* 8001 */
switch (mmc3_command)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
if (Cart->VROMSize == 0)
return;
mmc3_last_vrom[mmc3_command] = Value; if (mmc3_last_prom_switch != (Value & 0x40))
{
if (mmc3_use_xor) if (!(Value & 0x40))
{ {
set_vrom_bank_1k(0x0000, mmc3_last_vrom[2]); console_printf(Console_Default, "MMC3: Switch -> 8/A\n");
set_vrom_bank_1k(0x0400, mmc3_last_vrom[3]); mmc3_first_prom_page = 0x8000;
set_vrom_bank_1k(0x0800, mmc3_last_vrom[4]); mmc3_second_prom_page = 0xA000;
set_vrom_bank_1k(0x0C00, mmc3_last_vrom[5]);
set_vrom_bank_2k(0x1000, mmc3_last_vrom[0]>>1); set_prom_bank_8k(mmc3_first_prom_page, mmc3_last_prom[0]);
set_vrom_bank_2k(0x1800, mmc3_last_vrom[1]>>1); set_prom_bank_8k(mmc3_second_prom_page, mmc3_last_prom[1]);
//chr4,chr5,chr6,chr7,chr01,chr01+1,chr23,chr23+1
} set_prom_bank_8k(0xC000, GETLAST08KBANK(Cart) - 1);
else //set_prom_bank_8k(0xE000, GETLAST08KBANK(cart));
{ //prg_bank(prg0,prg1,max_prg-1,max_prg);
set_vrom_bank_2k(0x0000, mmc3_last_vrom[0]>>1); }
set_vrom_bank_2k(0x0800, mmc3_last_vrom[1]>>1); else
set_vrom_bank_1k(0x1000, mmc3_last_vrom[2]); {
set_vrom_bank_1k(0x1400, mmc3_last_vrom[3]); console_printf(Console_Default, "MMC3: Switch -> C/A\n");
set_vrom_bank_1k(0x1800, mmc3_last_vrom[4]); mmc3_first_prom_page = 0xC000;
set_vrom_bank_1k(0x1C00, mmc3_last_vrom[5]); mmc3_second_prom_page = 0xA000;
//chr01,chr01+1,chr23,chr23+1,chr4,chr5,chr6,chr7
} set_prom_bank_8k(mmc3_first_prom_page, mmc3_last_prom[0]);
set_prom_bank_8k(mmc3_second_prom_page, mmc3_last_prom[1]);
break;
set_prom_bank_8k(0x8000, GETLAST08KBANK(Cart) - 1);
case 6:
mmc3_last_prom[0] = Value;
//prg_bank(max_prg-1,prg1,prg0,max_prg);
}
mmc3_last_prom_switch = (Value & 0x40);
}
mmc3_command = Value & 0x07;
}
else
{ /* 8001 */
switch (mmc3_command)
{
default:
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
if (Cart->VROMSize == 0)
{
return;
}
mmc3_last_vrom[mmc3_command] = Value;
if (mmc3_use_xor)
{
set_vrom_bank_1k(0x0000, mmc3_last_vrom[2]);
set_vrom_bank_1k(0x0400, mmc3_last_vrom[3]);
set_vrom_bank_1k(0x0800, mmc3_last_vrom[4]);
set_vrom_bank_1k(0x0C00, mmc3_last_vrom[5]);
set_vrom_bank_2k(0x1000, mmc3_last_vrom[0] >> 1);
set_vrom_bank_2k(0x1800, mmc3_last_vrom[1] >> 1);
//chr4,chr5,chr6,chr7,chr01,chr01+1,chr23,chr23+1
}
else
{
set_vrom_bank_2k(0x0000, mmc3_last_vrom[0] >> 1);
set_vrom_bank_2k(0x0800, mmc3_last_vrom[1] >> 1);
set_vrom_bank_1k(0x1000, mmc3_last_vrom[2]);
set_vrom_bank_1k(0x1400, mmc3_last_vrom[3]);
set_vrom_bank_1k(0x1800, mmc3_last_vrom[4]);
set_vrom_bank_1k(0x1C00, mmc3_last_vrom[5]);
//chr01,chr01+1,chr23,chr23+1,chr4,chr5,chr6,chr7
}
break;
case 6:
mmc3_last_prom[0] = Value;
set_prom_bank_8k(mmc3_first_prom_page, mmc3_last_prom[0]); set_prom_bank_8k(mmc3_first_prom_page, mmc3_last_prom[0]);
break; break;
case 7: case 7:
mmc3_last_prom[1] = Value; mmc3_last_prom[1] = Value;
set_prom_bank_8k(mmc3_second_prom_page, mmc3_last_prom[1]); set_prom_bank_8k(mmc3_second_prom_page, mmc3_last_prom[1]);
break; break;
} }
/*if(mmc3_use_xor) /*if(mmc3_use_xor)
chr_bank(chr4,chr5,chr6,chr7,chr01,chr01+1,chr23,chr23+1); chr_bank(chr4,chr5,chr6,chr7,chr01,chr01+1,chr23,chr23+1);
else else
@ -221,93 +224,117 @@ void mmc3_MapperWrite80Hook(byte addr, byte Value)
} }
void mmc3_MapperWriteA0Hook(byte addr, byte Value) void mmc3_MapperWriteA0Hook(uint8_t addr, uint8_t Value)
{ {
//console_printf(Console_Default, "%s(0x%02X, 0x%02X)\n", __func__, addr, Value); //console_printf(Console_Default, "%s(0x%02X, 0x%02X)\n", __func__, addr, Value);
if (addr > 0x01) if (addr > 0x01)
{
return; return;
}
if (!addr)
{
//console_printf(Console_Default, "MMC3: Select mirroring (0xA000) : 0x%X\n",Value);
if (Value & 0x1)
ppu_setMirroring(PPU_MIRROR_HORIZTAL);
else
ppu_setMirroring(PPU_MIRROR_VERTICAL);
} if (!addr)
{
//console_printf(Console_Default, "MMC3: Select mirroring (0xA000) : 0x%X\n",Value);
if (Value & 0x1)
{
ppu_setMirroring(PPU_MIRROR_HORIZTAL);
}
else
{
ppu_setMirroring(PPU_MIRROR_VERTICAL);
}
}
else else
{ {
//console_printf(Console_Default, "MMC3: SaveRAM Toggle (0xA001) : 0x%X\n",Value); //console_printf(Console_Default, "MMC3: SaveRAM Toggle (0xA001) : 0x%X\n",Value);
if (Value) if (Value)
map_sram(); {
else map_sram();
unmap_sram(); }
else
{
unmap_sram();
}
} }
} }
void mmc3_MapperWriteC0Hook(byte addr, byte Value) void mmc3_MapperWriteC0Hook(uint8_t addr, uint8_t Value)
{ {
//console_printf(Console_Default, "%s(0x%02X, 0x%02X)\n", __func__, addr, Value); //console_printf(Console_Default, "%s(0x%02X, 0x%02X)\n", __func__, addr, Value);
if (addr > 0x01) if (addr > 0x01)
{
return; return;
}
if (!addr) if (!addr)
{ {
mmc3_irq_counter_reload = Value; mmc3_irq_counter_reload = Value;
mmc3_irq_counter = Value; mmc3_irq_counter = Value;
//console_printf(Console_Default, "MMC3 IRQ[%d]: SetIRQ reload to %d\n", ScanLine, Value); //console_printf(Console_Default, "MMC3 IRQ[%d]: SetIRQ reload to %d\n", ScanLine, Value);
}else{ /* C001 */ }
//console_printf(Console_Default, "MMC3: New tmp IRQ value (0xC001) : 0x%X\n",Value); else
//console_printf(Console_Default, "MMC3 IRQ[%d]: Reset IRQ counter to val %d [Value = %d]\n", ScanLine, mmc3_irq_counter_reload, Value); { /* C001 */
mmc3_irq_counter = Value; //console_printf(Console_Default, "MMC3: New tmp IRQ value (0xC001) : 0x%X\n",Value);
//console_printf(Console_Default, "MMC3 IRQ[%d]: Reset IRQ counter to val %d [Value = %d]\n", ScanLine, mmc3_irq_counter_reload, Value);
mmc3_irq_counter = Value;
} }
} }
void mmc3_MapperWriteE0Hook(byte addr, byte Value) void mmc3_MapperWriteE0Hook(uint8_t addr, uint8_t Value)
{ {
//console_printf(Console_Default, "%s(0x%02X, 0x%02X)\n", __func__, addr, Value); //console_printf(Console_Default, "%s(0x%02X, 0x%02X)\n", __func__, addr, Value);
if (addr > 0x01) if (addr > 0x01)
{
return; return;
}
if (!addr) if (!addr)
{ {
//console_printf(Console_Default, "MMC3: Writing to 0xE001 : 0x%X\n",Value); //console_printf(Console_Default, "MMC3: Writing to 0xE001 : 0x%X\n",Value);
//console_printf(Console_Default, "MMC3 IRQ[%d]: IRQ disabled\n", ScanLine); //console_printf(Console_Default, "MMC3 IRQ[%d]: IRQ disabled\n", ScanLine);
mmc3_irq_enable = 0; mmc3_irq_enable = 0;
//MapperWantIRQ = 1; //MapperWantIRQ = 1;
// Add a way to raise an IRQ // Add a way to raise an IRQ
}else{ /* E001 */ }
//console_printf(Console_Default, "MMC3: Writing to 0xE001 : 0x%X\n",Value); else
//console_printf(Console_Default, "MMC3: IRQ Enabled (value : %d)\n",mmc3_irq_counter); { /* E001 */
//console_printf(Console_Default, "MMC3 IRQ[%d]: Enable IRQ\nr", ScanLine); //console_printf(Console_Default, "MMC3: Writing to 0xE001 : 0x%X\n",Value);
mmc3_irq_enable = 1; //console_printf(Console_Default, "MMC3: IRQ Enabled (value : %d)\n",mmc3_irq_counter);
//console_printf(Console_Default, "MMC3 IRQ[%d]: Enable IRQ\nr", ScanLine);
mmc3_irq_enable = 1;
} }
} }
int mmc3_MapperIRQ(int cycledone) int mmc3_MapperIRQ(int cycledone)
{ {
if (((cycledone > 0) && (cycledone < 241)) /*&& if (((cycledone > 0) && (cycledone < 241)) /*&&
(ppu.ControlRegister2.b & (PPU_CR2_BGVISIBILITY | PPU_CR2_SPRTVISIBILITY)) == (PPU_CR2_BGVISIBILITY | PPU_CR2_SPRTVISIBILITY)*/) (ppu.ControlRegister2.b & (PPU_CR2_BGVISIBILITY | PPU_CR2_SPRTVISIBILITY)) == (PPU_CR2_BGVISIBILITY | PPU_CR2_SPRTVISIBILITY)*/)
{ {
if ((mmc3_irq_counter --) > 0 )return 0; if ((mmc3_irq_counter--) > 0)
{
return 0;
/* Load next counter position */ }
mmc3_irq_counter = mmc3_irq_counter_reload;
if (mmc3_irq_enable == 0) return 0; /* Load next counter position */
mmc3_irq_counter = mmc3_irq_counter_reload;
mmc3_irq_enable = 0;
if (mmc3_irq_enable == 0)
//console_printf(Console_Default, "MMC3 IRQ[%d]: Tick next at %d\n", ScanLine, mmc3_irq_counter_reload); {
return 0;
return 1; }
}
return 0; mmc3_irq_enable = 0;
//console_printf(Console_Default, "MMC3 IRQ[%d]: Tick next at %d\n", ScanLine, mmc3_irq_counter_reload);
return 1;
}
return 0;
} }

View File

@ -1,20 +1,16 @@
/* /*
* MMC3 Mapper - The TI-NESulator Project * MMC3 Mapper - The peTI-NESulator Project
* mmc3.h * mmc3.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#define __TINES_MAPPERS__ #define __TINES_MAPPERS__
#include <mappers/manager.h> #include <mappers/manager.h>
void mmc3_MapperDump(FILE *fp); void mmc3_MapperDump(FILE *fp);
int mmc3_InitMapper(NesCart * cart); int mmc3_InitMapper(NesCart *cart);
int mmc3_MapperIRQ(int cycledone); int mmc3_MapperIRQ(int cycledone);

View File

@ -1,89 +1,88 @@
/* /*
* MMC4 Mapper - The TI-NESulator Project * MMC4 Mapper - The peTI-NESulator Project
* mmc4.h * mmc4.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include "mmc4.h" #include "mmc4.h"
byte mmc4_RegA; uint8_t mmc4_RegA;
byte mmc4_RegB; uint8_t mmc4_RegB;
byte mmc4_RegC; uint8_t mmc4_RegC;
byte mmc4_RegD; uint8_t mmc4_RegD;
byte mmc4_RegE; uint8_t mmc4_RegE;
byte mmc4_RegF; uint8_t mmc4_RegF;
#ifdef DEBUG #ifdef DEBUG
#define LOG(s) printf s #define LOG(s) printf s
#else #else
#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.. */ /* 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 uint8_t Addr, register uint8_t Value)
{ {
LOG(("%s(%02X, %02X)\n", __func__, Addr, Value)); LOG(("%s(%02X, %02X)\n", __func__, Addr, Value));
mmc4_RegA = Value; mmc4_RegA = Value;
set_prom_bank_16k(0x8000, Value & 0x0F); set_prom_bank_16k(0x8000, Value & 0x0F);
} }
void mmc4_MapperWriteRegB(register byte Addr, register byte Value) void mmc4_MapperWriteRegB(register uint8_t Addr, register uint8_t Value)
{ {
LOG(("%s(%02X, %02X)\n", __func__, Addr, Value)); LOG(("%s(%02X, %02X)\n", __func__, Addr, Value));
mmc4_RegB = Value; mmc4_RegB = Value;
set_vrom_bank_4k(0x0000, Value & 0x1F); set_vrom_bank_4k(0x0000, Value & 0x1F);
} }
void mmc4_MapperWriteRegC(register byte Addr, register byte Value) void mmc4_MapperWriteRegC(register uint8_t Addr, register uint8_t Value)
{ {
LOG(("%s(%02X, %02X)\n", __func__, Addr, Value)); LOG(("%s(%02X, %02X)\n", __func__, Addr, Value));
mmc4_RegC = Value; mmc4_RegC = Value;
set_vrom_bank_4k(0x0000, Value & 0x1F); set_vrom_bank_4k(0x0000, Value & 0x1F);
} }
void mmc4_MapperWriteRegD(register byte Addr, register byte Value) void mmc4_MapperWriteRegD(register uint8_t Addr, register uint8_t Value)
{ {
LOG(("%s(%02X, %02X)\n", __func__, Addr, Value)); LOG(("%s(%02X, %02X)\n", __func__, Addr, Value));
mmc4_RegD = Value; mmc4_RegD = Value;
set_vrom_bank_4k(0x1000, Value & 0x1F); set_vrom_bank_4k(0x1000, Value & 0x1F);
} }
void mmc4_MapperWriteRegE(register byte Addr, register byte Value) void mmc4_MapperWriteRegE(register uint8_t Addr, register uint8_t Value)
{ {
LOG(("%s(%02X, %02X)\n", __func__, Addr, Value)); LOG(("%s(%02X, %02X)\n", __func__, Addr, Value));
mmc4_RegE = Value; mmc4_RegE = Value;
set_vrom_bank_4k(0x1000, Value & 0x1F); set_vrom_bank_4k(0x1000, Value & 0x1F);
} }
void mmc4_MapperWriteRegF(register byte Addr, register byte Value) void mmc4_MapperWriteRegF(register uint8_t Addr, register uint8_t Value)
{ {
LOG(("%s(%02X, %02X)\n", __func__, Addr, Value)); LOG(("%s(%02X, %02X)\n", __func__, Addr, Value));
mmc4_RegF = Value; mmc4_RegF = Value;
if (Value & 0x01) if (Value & 0x01)
{
ppu_setMirroring(PPU_MIRROR_HORIZTAL); ppu_setMirroring(PPU_MIRROR_HORIZTAL);
}
else else
{
ppu_setMirroring(PPU_MIRROR_VERTICAL); ppu_setMirroring(PPU_MIRROR_VERTICAL);
}
} }
void mmc4_MapperDump(FILE *fp) void mmc4_MapperDump(FILE *fp)
{ {
} }
int mmc4_InitMapper(NesCart * cart) int mmc4_InitMapper(NesCart *cart)
{ {
int i; int i;
@ -91,50 +90,52 @@ int mmc4_InitMapper(NesCart * cart)
set_prom_bank_16k(0xC000, GETLAST16KBANK(cart)); set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
if (cart->VROMSize > 0) if (cart->VROMSize > 0)
set_vrom_bank_8k(0x0000,0); {
set_vrom_bank_8k(0x0000, 0);
}
/* Mapper should register itself for write hook */ /* Mapper should register itself for write hook */
for (i = 0xA0; i < 0xB0 ; i++) for (i = 0xA0 ; i < 0xB0 ; i++)
{ {
set_page_wr_hook(i, mmc4_MapperWriteRegA); set_page_wr_hook(i, mmc4_MapperWriteRegA);
set_page_writeable(i, true); set_page_writeable(i, true);
}
for (i = 0xB0; i < 0xC0 ; i++)
{
set_page_wr_hook(i, mmc4_MapperWriteRegB);
set_page_writeable(i, true);
} }
for (i = 0xC0; i < 0xD0 ; i++) for (i = 0xB0 ; i < 0xC0 ; i++)
{ {
set_page_wr_hook(i, mmc4_MapperWriteRegC); set_page_wr_hook(i, mmc4_MapperWriteRegB);
set_page_writeable(i, true); set_page_writeable(i, true);
}
for (i = 0xD0; i < 0xE0 ; i++)
{
set_page_wr_hook(i, mmc4_MapperWriteRegD);
set_page_writeable(i, true);
}
for (i = 0xE0; i < 0xF0 ; i++)
{
set_page_wr_hook(i, mmc4_MapperWriteRegE);
set_page_writeable(i, true);
} }
for (i = 0xF0; i < 0x100 ; i++) for (i = 0xC0 ; i < 0xD0 ; i++)
{ {
set_page_wr_hook(i, mmc4_MapperWriteRegF); set_page_wr_hook(i, mmc4_MapperWriteRegC);
set_page_writeable(i, true); set_page_writeable(i, true);
} }
for (i = 0xD0 ; i < 0xE0 ; i++)
for (i = 0x60; i < 0x80 ; i++)
{ {
set_page_writeable(i, true); set_page_wr_hook(i, mmc4_MapperWriteRegD);
set_page_readable(i, true); set_page_writeable(i, true);
} }
for (i = 0xE0 ; i < 0xF0 ; i++)
{
set_page_wr_hook(i, mmc4_MapperWriteRegE);
set_page_writeable(i, true);
}
for (i = 0xF0 ; i < 0x100 ; i++)
{
set_page_wr_hook(i, mmc4_MapperWriteRegF);
set_page_writeable(i, true);
}
for (i = 0x60 ; i < 0x80 ; i++)
{
set_page_writeable(i, true);
set_page_readable(i, true);
}
//ppu_setScreenMode(PPU_SCMODE_NORMAL); //ppu_setScreenMode(PPU_SCMODE_NORMAL);
//ppu_setMirroring(PPU_MIRROR_HORIZTAL); //ppu_setMirroring(PPU_MIRROR_HORIZTAL);
return 0; return 0;
} }

View File

@ -1,19 +1,15 @@
/* /*
* MMC4 Mapper - The TI-NESulator Project * MMC4 Mapper - The peTI-NESulator Project
* mmc4.h * mmc4.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#define __TINES_MAPPERS__ #define __TINES_MAPPERS__
#include <mappers/manager.h> #include <mappers/manager.h>
void mmc4_MapperDump(FILE *fp); void mmc4_MapperDump(FILE *fp);
int mmc4_InitMapper(NesCart * cart); int mmc4_InitMapper(NesCart *cart);

View File

@ -1,51 +1,47 @@
/* /*
* NOROM Mapper - The TI-NESulator Project * NOROM Mapper - The peTI-NESulator Project
* norom.c * norom.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include "norom.h" #include "norom.h"
int norom_InitMapper(NesCart *cart) int norom_InitMapper(NesCart *cart)
{ {
set_page_ptr_16k(0x80, cart->PROMBanks); set_page_ptr_16k(0x80, cart->PROMBanks);
/* mUBank = 0xC000 */ /* mUBank = 0xC000 */
if (cart->PROMSize > (16*1024)) if (cart->PROMSize > (16 * 1024))
{ {
set_prom_bank_16k(0xC000, 1); set_prom_bank_16k(0xC000, 1);
} }
else else
{ {
set_prom_bank_16k(0xC000, 0); set_prom_bank_16k(0xC000, 0);
} }
if (cart->VROMSize > 0) if (cart->VROMSize > 0)
set_vrom_bank_8k(0x2000, 0); {
set_vrom_bank_8k(0x2000, 0);
return 0; }
return 0;
} }
int norom_MapperIRQ(int cycledone) int norom_MapperIRQ(int cycledone)
{ {
return 0; return 0;
} }
void norom_MapperWriteHook(register byte Addr, register byte Value) void norom_MapperWriteHook(register uint8_t Addr, register uint8_t Value)
{ {
/* Nothing to do */ /* Nothing to do */
return;
} }
void norom_MapperDump (FILE *fp) void norom_MapperDump(FILE *fp)
{ {
fprintf(fp, "norom mapper have nothing to dump"); fprintf(fp, "norom mapper have nothing to dump");
} }

View File

@ -1,20 +1,16 @@
/* /*
* NOROM Mapper - The TI-NESulator Project * NOROM Mapper - The peTI-NESulator Project
* norom.c * norom.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#define __TINES_MAPPERS__ #define __TINES_MAPPERS__
#include <mappers/manager.h> #include <mappers/manager.h>
int norom_InitMapper (NesCart *cart); int norom_InitMapper(NesCart *cart);
int norom_MapperIRQ (int cycledone); int norom_MapperIRQ(int cycledone);
void norom_MapperDump (); void norom_MapperDump(FILE *fp);

View File

@ -1,53 +1,50 @@
/* /*
* UNROM Mapper - The TI-NESulator Project * UNROM Mapper - The peTI-NESulator Project
* unrom.h * unrom.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include "unrom.h" #include "unrom.h"
unsigned char unrom_load_vbank; uint8_t unrom_load_vbank;
void unrom_MapperWriteHook(byte Addr, byte Value); void unrom_MapperWriteHook(uint8_t Addr, uint8_t Value);
int unrom_InitMapper(NesCart * cart) int unrom_InitMapper(NesCart *cart)
{ {
int i; int i;
set_prom_bank_16k(0xC000, 0); set_prom_bank_16k(0xC000, 0);
set_prom_bank_16k(0x8000, GETLAST16KBANK(cart)); /* Set the last one */ set_prom_bank_16k(0x8000, GETLAST16KBANK(cart)); /* Set the last one */
if (Cart->VROMSize > 0) if (Cart->VROMSize > 0)
set_vrom_bank_8k(0x0000,0); {
set_vrom_bank_8k(0x0000, 0);
}
unrom_load_vbank = 0; unrom_load_vbank = 0;
/* Register the write hook */ /* Register the write hook */
for (i = 0x80; i < 0x100; i++) for (i = 0x80 ; i < 0x100 ; i++)
{ {
set_page_wr_hook(i, unrom_MapperWriteHook); set_page_wr_hook(i, unrom_MapperWriteHook);
set_page_writeable(i, true); set_page_writeable(i, true);
} }
return 0; return 0;
} }
void unrom_MapperWriteHook(byte Addr, byte Value) void unrom_MapperWriteHook(uint8_t Addr, uint8_t Value)
{ {
set_vrom_bank_8k(0x0000,Value); set_vrom_bank_8k(0x0000, Value);
unrom_load_vbank = Value; unrom_load_vbank = Value;
} }
void unrom_MapperDump(FILE *fp) void unrom_MapperDump(FILE *fp)
{ {
fprintf(fp,"unrom: vbank:%d\n",unrom_load_vbank); fprintf(fp, "unrom: vbank:%d\n", unrom_load_vbank);
} }

View File

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

View File

@ -1,23 +1,27 @@
/* /*
* UNROM Mapper - The TI-NESulator Project * UNROM Mapper - The peTI-NESulator Project
* unrom.h * unrom.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include <ppu/ppu.h> #include <ppu/ppu.h>
#include "unrom512.h" #include "unrom512.h"
static byte mirroring_set; static uint8_t mirroring_set;
static byte loaded_vbank; static uint8_t loaded_vbank;
static byte loaded_pbank; static uint8_t loaded_pbank;
/*
* not great but as we currently don't support higher than 8K VRAM, allocate it here as we can have
* 32K on such a cart
*/
static uint8_t vram[32768];
void ppu_setPagePtr8k(uint8_t page, uint8_t *ptr);
static void unrom512_applyValues() static void unrom512_applyValues()
{ {
/*if (mirroring_set) /*if (mirroring_set)
@ -29,20 +33,20 @@ static void unrom512_applyValues()
ppu_setMirroring(PPU_MIRROR_VERTICAL); ppu_setMirroring(PPU_MIRROR_VERTICAL);
}*/ }*/
//set_vrom_bank_8k(0x0000, loaded_vbank); ppu_setPagePtr8k(0x00, vram + (loaded_vbank * 8 * 1024));
set_prom_bank_16k(0x8000, loaded_pbank); set_prom_bank_16k(0x8000, loaded_pbank);
} }
static void unrom512_MapperWriteHook(byte Addr, byte Value) static void unrom512_MapperWriteHook(uint8_t Addr, uint8_t Value)
{ {
mirroring_set = (Value >> 7) & 0x01; mirroring_set = (Value >> 7) & 0x01;
loaded_vbank = (Value >> 5) & 0x03; loaded_vbank = (Value >> 5) & 0x03;
loaded_pbank = (Value ) & 0x1F; loaded_pbank = (Value) & 0x1F;
unrom512_applyValues(); unrom512_applyValues();
} }
int unrom512_InitMapper(NesCart * cart) int unrom512_InitMapper(NesCart *cart)
{ {
int i; int i;
@ -51,18 +55,18 @@ int unrom512_InitMapper(NesCart * cart)
set_prom_bank_16k(0xC000, GETLAST16KBANK(cart)); set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
unrom512_applyValues(); unrom512_applyValues();
/* Register the write hook */ /* Register the write hook */
for (i = 0x80; i < 0x100; i++) for (i = 0x80 ; i < 0x100 ; i++)
{ {
set_page_wr_hook(i, unrom512_MapperWriteHook); set_page_wr_hook(i, unrom512_MapperWriteHook);
set_page_writeable(i, true); set_page_writeable(i, true);
} }
return 0; return 0;
} }
void unrom512_MapperDump(FILE *fp) void unrom512_MapperDump(FILE *fp)
{ {
fprintf(fp,"unrom512: vbank:%d pbank:%d\n", loaded_vbank, loaded_pbank); fprintf(fp, "unrom512: vbank:%d pbank:%d\n", loaded_vbank, loaded_pbank);
} }

View File

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

View File

@ -1,14 +1,9 @@
/* /*
* Mapper list - The TI-NESulator Project * Mapper list - The peTI-NESulator Project
* mappers_list.h * mappers_list.h
* *
* Created by Manoel TRAPIER on 25/10/07. * Created by Manoël Trapier on 25/10/07.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */

View File

@ -1,14 +1,9 @@
/* /*
* Generic mapper implementation - The TI-NESulator Project * Generic mapper implementation - The peTI-NESulator Project
* genericmapper.h * genericmapper.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -22,12 +17,12 @@ int _InitMapper(NesCart * cart)
} }
int _MapperWriteHook(register word Addr, register byte Value) int _MapperWriteHook(register word Addr, register uint8_t Value)
{ {
if (Addr > 0x7FFF) /* Try to write to the rom */ if (Addr > 0x7FFF) /* Try to write to the rom */
{ {
set_vrom_bank_8k(0x0000,Value) set_vrom_bank_8k(0x0000,Value);
return 1; return 1;
} }

View File

@ -1,25 +1,16 @@
/* /*
* MMC1 Mapper - The TI-NESulator Project * MMC1 Mapper - The peTI-NESulator Project
* mmc1.h * mmc1.h
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
unsigned char MMC1_reg0; uint8_t MMC1_reg0;
uint8_t MMC1_reg1;
unsigned char MMC1_reg1; uint8_t MMC1_reg2;
uint8_t MMC1_reg3;
unsigned char MMC1_reg2; uint8_t mmc1_CurrentBank;
unsigned char MMC1_reg3;
unsigned char mmc1_CurrentBank;
#define MMC1_R0_MIRROR 0x01 #define MMC1_R0_MIRROR 0x01
#define MMC1_R0_ONESCREEN 0x02 #define MMC1_R0_ONESCREEN 0x02
@ -47,98 +38,93 @@ unsigned char mmc1_CurrentBank;
#define MMC1_REG3_DEFAULT 0 #define MMC1_REG3_DEFAULT 0
void mmc1_MapperWriteReg0(register byte Addr, register byte Value); void mmc1_MapperWriteReg0(register uint8_t Addr, register uint8_t Value);
void mmc1_MapperWriteReg1(register byte Addr, register byte Value); void mmc1_MapperWriteReg1(register uint8_t Addr, register uint8_t Value);
void mmc1_MapperWriteReg2(register byte Addr, register byte Value); void mmc1_MapperWriteReg2(register uint8_t Addr, register uint8_t Value);
void mmc1_MapperWriteReg3(register byte Addr, register byte Value); void mmc1_MapperWriteReg3(register uint8_t Addr, register uint8_t Value);
void mmc1_MapperDump(FILE *fp) void mmc1_MapperDump(FILE *fp)
{ {
fprintf(fp,"MMC1: r0:0x%02X r1:0x%02X r2:0x%02X r3:0x%02X\n",MMC1_reg0,MMC1_reg1,MMC1_reg2,MMC1_reg3); fprintf(fp, "MMC1: r0:0x%02X r1:0x%02X r2:0x%02X r3:0x%02X\n", MMC1_reg0, MMC1_reg1, MMC1_reg2, MMC1_reg3);
} }
int mmc1_InitMapper(NesCart * cart) int mmc1_InitMapper(NesCart *cart)
{ {
int i; int i;
MMC1_reg0 = MMC1_REG0_DEFAULT;
MMC1_reg1 = MMC1_REG1_DEFAULT;
MMC1_reg2 = MMC1_REG2_DEFAULT;
MMC1_reg3 = MMC1_REG3_DEFAULT;
set_prom_bank_16k(0x8000,0);
set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
mmc1_CurrentBank = 0;
if (cart->VROMSize > 0)
set_vrom_bank_4k(0x0000,0);
MMC1_reg0 = MMC1_REG0_DEFAULT;
/* Mapper should register itself for write hook */ MMC1_reg1 = MMC1_REG1_DEFAULT;
for (i = 0x80; i < 0xA0 ; i++) MMC1_reg2 = MMC1_REG2_DEFAULT;
MMC1_reg3 = MMC1_REG3_DEFAULT;
set_prom_bank_16k(0x8000, 0);
set_prom_bank_16k(0xC000, GETLAST16KBANK(cart));
mmc1_CurrentBank = 0;
if (cart->VROMSize > 0)
{ {
set_page_wr_hook(i, mmc1_MapperWriteReg0); set_vrom_bank_4k(0x0000, 0);
set_page_writeable(i, true);
}
for (i = 0xA0; i < 0xC0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg1);
set_page_writeable(i, true);
}
for (i = 0xC0; i < 0xE0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg2);
set_page_writeable(i, true);
}
for (i = 0xE0; i < 0x100 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg3);
set_page_writeable(i, true);
} }
/* Mapper should register itself for write hook */
for (i = 0x80 ; i < 0xA0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg0);
set_page_writeable(i, true);
}
for (i = 0xA0 ; i < 0xC0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg1);
set_page_writeable(i, true);
}
for (i = 0xC0 ; i < 0xE0 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg2);
set_page_writeable(i, true);
}
for (i = 0xE0 ; i < 0x100 ; i++)
{
set_page_wr_hook(i, mmc1_MapperWriteReg3);
set_page_writeable(i, true);
}
return 0; return 0;
} }
/* /*
Reg 0 * Reg 0
8 : 1000 * 8 : 1000
9 : 1001 * 9 : 1001
*
Reg 1 * Reg 1
A : 1010 * A : 1010
B : 1011 * B : 1011
*
Reg 2 * Reg 2
C : 1100 * C : 1100
D : 1101 * D : 1101
*
Reg 3 * Reg 3
E : 1110 * E : 1110
F : 1111 * F : 1111
*
((Addr & 0x6000) >> 13) <- port number * ((Addr & 0x6000) >> 13) <- port number
*/ */
#define MMC1_GetReg(a) ((a & 0x6000) >> 13) #define MMC1_GetReg(a) ((a & 0x6000) >> 13)
/* (Val & 0x01) recuperation du bit */
#define MMC1_GetBit(v) (v & 0x01) #define MMC1_GetBit(v) (v & 0x01)
/* ( ( b & (1 << Bit)) | (v << Bit) ) Ajout du bit */ #define MMC1_AddBit(b, v) ( ( b & ~(1 << Bit)) | (v << Bit) )
#define MMC1_AddBit(b,v) ( ( b & ~(1 << Bit)) | (v << Bit) )
void mmc1_ApplyReg0Mod() void mmc1_ApplyReg0Mod()
{ {
static unsigned char OldSwitchArea = MMC1_R0_PRGAREA; static uint8_t OldSwitchArea = MMC1_R0_PRGAREA;
//console_printf(Console_Default, "Change to reg0 done ! (0x%x)\n\tMirror flag : %d\n\tOneScreen Flag : %d\n\tPRG Size : %d\n\tPRG Area : %d\n\tVROM Switch size : %d\n", MMC1_reg0, MMC1_reg0 & MMC1_R0_MIRROR, MMC1_reg0 & MMC1_R0_ONESCREEN, MMC1_reg0 & MMC1_R0_PRGAREA, MMC1_reg0 & MMC1_R0_PRGSIZE, MMC1_reg0 & MMC1_R0_VROMSW);
//console_printf(Console_Default, "Change to reg0 done ! (0x%x)\n\tMiror flag : %d\n\tOneScreen Flag : %d\n\tPRG Size : %d\n\tPRG Area : %d\n\tVROM Switch size : %d\n", MMC1_reg0, MMC1_reg0 & MMC1_R0_MIRROR, MMC1_reg0 & MMC1_R0_ONESCREEN, MMC1_reg0 & MMC1_R0_PRGAREA, MMC1_reg0 & MMC1_R0_PRGSIZE, MMC1_reg0 & MMC1_R0_VROMSW);
switch (MMC1_reg0 & 0x03) switch (MMC1_reg0 & 0x03)
{ {
case 0: case 0:
@ -158,189 +144,204 @@ void mmc1_ApplyReg0Mod()
ppu_setMirroring(PPU_MIRROR_HORIZTAL); ppu_setMirroring(PPU_MIRROR_HORIZTAL);
break; break;
} }
if ( (OldSwitchArea != (MMC1_reg0 & MMC1_R0_PRGAREA)) && ((MMC1_reg0 & MMC1_R0_PRGSIZE) != 0 ) )
{
if ((MMC1_reg0 & MMC1_R0_PRGAREA) != 0)
{ /* 0x8000 area */
set_prom_bank_16k(0x8000,mmc1_CurrentBank);
set_prom_bank_16k(0xC000, GETLAST16KBANK(Cart));
}
else
{ /* 0xC000 area */
set_prom_bank_16k(0x8000,0);
set_prom_bank_16k(0xC000,mmc1_CurrentBank);
} if ((OldSwitchArea != (MMC1_reg0 & MMC1_R0_PRGAREA)) && ((MMC1_reg0 & MMC1_R0_PRGSIZE) != 0))
{
if ((MMC1_reg0 & MMC1_R0_PRGAREA) != 0)
{
/* 0x8000 area */
set_prom_bank_16k(0x8000, mmc1_CurrentBank);
set_prom_bank_16k(0xC000, GETLAST16KBANK(Cart));
}
else
{
/* 0xC000 area */
set_prom_bank_16k(0x8000, 0);
set_prom_bank_16k(0xC000, mmc1_CurrentBank);
}
OldSwitchArea = (MMC1_reg0 & MMC1_R0_PRGAREA); OldSwitchArea = (MMC1_reg0 & MMC1_R0_PRGAREA);
} }
} }
int VROMBankNb; int 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 uint8_t Addr, register uint8_t Value)
{ {
if (Value & 0x80) if (Value & 0x80)
{ {
MMC1_reg0 = MMC1_REG0_DEFAULT; MMC1_reg0 = MMC1_REG0_DEFAULT;
console_printf(Console_Default, "MMC1: Reg0 Reset occured !\n"); console_printf(Console_Default, "MMC1: Reg0 Reset occurred !\n");
mmc1_ApplyReg0Mod(); mmc1_ApplyReg0Mod();
} }
else else
{ {
if (Bit < 4) if (Bit < 4)
{ /* Pas encore ecrit les 5 bits */ {
/* Haven't written the 5 bits yet */
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit++; Bit++;
} }
else else
{ {
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit = 0; Bit = 0;
MMC1_reg0 = BitBuf; MMC1_reg0 = BitBuf;
mmc1_ApplyReg0Mod(); mmc1_ApplyReg0Mod();
} }
} }
} }
void mmc1_MapperWriteReg1(register byte Addr, register byte Value) void mmc1_MapperWriteReg1(register uint8_t Addr, register uint8_t Value)
{ {
if (Value & 0x80) if (Value & 0x80)
{ {
MMC1_reg1 = MMC1_REG1_DEFAULT; MMC1_reg1 = MMC1_REG1_DEFAULT;
console_printf(Console_Default, "MMC1: Reg1 Reset occured !\n"); console_printf(Console_Default, "MMC1: Reg1 Reset occurred !\n");
} }
else else
{ {
if (Bit < 4) if (Bit < 4)
{ /* Pas encore ecrit les 5 bits */ {
/* Haven't written the 5 bits yet */
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit++; Bit++;
} }
else else
{ {
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit = 0; Bit = 0;
MMC1_reg1 = BitBuf; MMC1_reg1 = BitBuf;
VROMBankNb = (MMC1_reg1 /* & MMC1_R1_VROMB1 */ ); VROMBankNb = (MMC1_reg1 /* & MMC1_R1_VROMB1 */ );
if (Cart->VROMSize == 0) if (Cart->VROMSize == 0)
{ {
console_printf(Console_Default, "Try to change VROM but with didn't have any VROM ! [%04X]\n", VROMBankNb); console_printf(Console_Default, "Try to change VROM but with didn't have any VROM ! [%04X]\n",
VROMBankNb);
return; return;
} }
if ( (MMC1_reg0 & MMC1_R0_VROMSW) != 0 ) if ((MMC1_reg0 & MMC1_R0_VROMSW) != 0)
{ /* 4K vram */ {
/* 4K vram */
//console_printf(Console_Default, "Switching VROM at 0x0000 to 4k bank %d\n", VROMBankNb); //console_printf(Console_Default, "Switching VROM at 0x0000 to 4k bank %d\n", VROMBankNb);
set_vrom_bank_4k(0x0000,VROMBankNb); set_vrom_bank_4k(0x0000, VROMBankNb);
} }
else else
{ /* 8K vram */ {
/* 8K vram */
//console_printf(Console_Default, "Switching VROM at 0x0000 to 8k bank %d\n", VROMBankNb>>1); //console_printf(Console_Default, "Switching VROM at 0x0000 to 8k bank %d\n", VROMBankNb>>1);
set_vrom_bank_8k(0x0000,VROMBankNb>>1); set_vrom_bank_8k(0x0000, VROMBankNb >> 1);
} }
} }
} }
} }
void mmc1_MapperWriteReg2(register byte Addr, register byte Value) void mmc1_MapperWriteReg2(register uint8_t Addr, register uint8_t Value)
{ {
if (Value & 0x80) if (Value & 0x80)
{ {
MMC1_reg2 = MMC1_REG2_DEFAULT; MMC1_reg2 = MMC1_REG2_DEFAULT;
console_printf(Console_Default, "MMC1: Reg2 Reset occured !\n"); console_printf(Console_Default, "MMC1: Reg2 Reset occurred !\n");
} }
else else
{ {
if (Bit < 4) if (Bit < 4)
{ /* Pas encore ecrit les 5 bits */ {
/* Haven't written the 5 bits yet */
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit++; Bit++;
} }
else else
{ {
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit = 0; Bit = 0;
MMC1_reg2 = BitBuf; MMC1_reg2 = BitBuf;
VROMBankNb = (MMC1_reg2 /* & MMC1_R2_VROMB2 */ ); VROMBankNb = (MMC1_reg2 /* & MMC1_R2_VROMB2 */ );
//console_printf(Console_Default, "Want to switch VROM at 0x1000 to 4k bank %d\n", VROMBankNb); //console_printf(Console_Default, "Want to switch VROM at 0x1000 to 4k bank %d\n", VROMBankNb);
if (Cart->VROMSize == 0) if (Cart->VROMSize == 0)
{ {
//console_printf(Console_Default, ": No\n"); //console_printf(Console_Default, ": No\n");
return; return;
} }
if ( (MMC1_reg0 & MMC1_R0_VROMSW) != 0 ) if ((MMC1_reg0 & MMC1_R0_VROMSW) != 0)
{ /* 4K vram */ {
/* 4K vram */
//console_printf(Console_Default, "Switching VROM at 0x1000 to 4k bank %d\n", VROMBankNb); //console_printf(Console_Default, "Switching VROM at 0x1000 to 4k bank %d\n", VROMBankNb);
set_vrom_bank_4k(0x1000,VROMBankNb); set_vrom_bank_4k(0x1000, VROMBankNb);
} }
else else
{ /* 8K vram */ {
// console_printf(Console_Default, "Switching VROM at 0x1000 to 8k bank %d\n", VROMBankNb>>1); /* 8K vram */
// set_vrom_bank_8k(0x1000,VROMBankNb>>1); // console_printf(Console_Default, "Switching VROM at 0x1000 to 8k bank %d\n", VROMBankNb>>1);
// set_vrom_bank_8k(0x1000,VROMBankNb>>1);
} }
} }
} }
} }
void mmc1_MapperWriteReg3(register byte Addr, register byte Value) void mmc1_MapperWriteReg3(register uint8_t Addr, register uint8_t Value)
{ {
if (Value & 0x80) if (Value & 0x80)
{ {
MMC1_reg3 = MMC1_REG3_DEFAULT; MMC1_reg3 = MMC1_REG3_DEFAULT;
console_printf(Console_Default, "MMC1: Reg3 Reset occured !\n"); console_printf(Console_Default, "MMC1: Reg3 Reset occurred !\n");
} }
else else
{ {
if (Bit < 4) if (Bit < 4)
{ /* Pas encore ecrit les 5 bits */ {
/* Haven't written the 5 bits yet */
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit++; Bit++;
} }
else else
{ {
BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value)); BitBuf = MMC1_AddBit(BitBuf, MMC1_GetBit(Value));
Bit = 0; Bit = 0;
MMC1_reg3 = BitBuf; MMC1_reg3 = BitBuf;
if (MMC1_reg3<<14 > Cart->PROMSize) if (MMC1_reg3 << 14 > Cart->PROMSize)
{
return; return;
}
if ( (MMC1_reg0 & MMC1_R0_PRGSIZE) != 0 )
{ /* 16K Switch */ if ((MMC1_reg0 & MMC1_R0_PRGSIZE) != 0)
if ( (MMC1_reg0 & MMC1_R0_PRGAREA) != 0 ) {
{ /* 0x8000 switch */ /* 16K Switch */
set_prom_bank_16k(0x8000,MMC1_reg3); if ((MMC1_reg0 & MMC1_R0_PRGAREA) != 0)
{
/* 0x8000 switch */
set_prom_bank_16k(0x8000, MMC1_reg3);
//console_printf(Console_Default, "LowBank is now %d ( 0x%p )\n", MMC1_reg3, mLBank); //console_printf(Console_Default, "LowBank is now %d ( 0x%p )\n", MMC1_reg3, mLBank);
} }
else else
{ /* 0xC000 switch */ {
set_prom_bank_16k(0xC000,MMC1_reg3); /* 0xC000 switch */
set_prom_bank_16k(0xC000, MMC1_reg3);
//console_printf(Console_Default, "HighBank is now %d ( 0x%p )\n", MMC1_reg3, mUBank); //console_printf(Console_Default, "HighBank is now %d ( 0x%p )\n", MMC1_reg3, mUBank);
} }
} }
else else
{ /* 32K Switch */ {
set_prom_bank_32k(0x8000,MMC1_reg3>>1); /* 32K Switch */
set_prom_bank_32k(0x8000, MMC1_reg3 >> 1);
} }
if ( ( MMC1_reg3 & MMC1_R3_SAVECE ) != 0) if ((MMC1_reg3 & MMC1_R3_SAVECE) != 0)
{ {
unmap_sram(); unmap_sram();
} }
@ -350,6 +351,6 @@ void mmc1_MapperWriteReg3(register byte Addr, register byte Value)
} }
} }
} }
} }
//console_printf(Console_Default, "MMC1: Debug (Reg:%d,Val:0x%02X,reg0:0x%02X,reg1:0x%02X,reg2:0x%02X,reg3:0x%02X)\n", MMC1_GetReg(Addr), Value, MMC1_reg0, MMC1_reg1, MMC1_reg2, MMC1_reg3); //console_printf(Console_Default, "MMC1: Debug (Reg:%d,Val:0x%02X,reg0:0x%02X,reg1:0x%02X,reg2:0x%02X,reg3:0x%02X)\n", MMC1_GetReg(Addr), Value, MMC1_reg0, MMC1_reg1, MMC1_reg2, MMC1_reg3);

View File

@ -1,14 +1,9 @@
/* /*
* Mapper facilities - The TI-NESulator Project * Mapper facilities - The peTI-NESulator Project
* mappers.c * mappers.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -32,48 +27,44 @@ extern NesCart *Cart;
extern char MapperWantIRQ; extern char MapperWantIRQ;
/* /*
Here are some fonction useful for mappers * Here are some function useful for mappers
*/ */
void set_vrom_bank_1k(unsigned short addr,int slot) void set_vrom_bank_1k(uint16_t addr,int slot)
{ {
#ifdef DEBUG_VROM_BANK_SWITCH #ifdef DEBUG_VROM_BANK_SWITCH
console_printf(Console_Default, "Change vrom 1k bank 0x%X to slot %d\n",addr,slot); console_printf(Console_Default, "Change vrom 1k bank 0x%X to slot %d\n",addr,slot);
#endif #endif
ppu_setPagePtr1k((addr>>8)&0xFF, Cart->VROMBanks + (slot * 1024)); ppu_setPagePtr1k((addr>>8)&0xFF, Cart->VROMBanks + (slot * 1024));
// memcpy(ppu.Memory+addr, Cart->VROMBanks + (slot * 1024), 0x0400);
} }
void set_vrom_bank_2k(unsigned short addr,int slot) void set_vrom_bank_2k(uint16_t addr,int slot)
{ {
#ifdef DEBUG_VROM_BANK_SWITCH #ifdef DEBUG_VROM_BANK_SWITCH
console_printf(Console_Default, "Change vrom 2k bank 0x%X to slot %d\n",addr,slot); console_printf(Console_Default, "Change vrom 2k bank 0x%X to slot %d\n",addr,slot);
#endif #endif
ppu_setPagePtr2k((addr>>8)&0xFF, Cart->VROMBanks + (slot * 2 * 1024)); ppu_setPagePtr2k((addr>>8)&0xFF, Cart->VROMBanks + (slot * 2 * 1024));
// memcpy(ppu.Memory+addr, Cart->VROMBanks + (slot * 2 * 1024), 0x0800);
} }
void set_vrom_bank_4k(unsigned short addr,int slot) void set_vrom_bank_4k(uint16_t addr,int slot)
{ {
#ifdef DEBUG_VROM_BANK_SWITCH #ifdef DEBUG_VROM_BANK_SWITCH
console_printf(Console_Default, "Change vrom 4k bank 0x%X to slot %d\n",addr,slot); console_printf(Console_Default, "Change vrom 4k bank 0x%X to slot %d\n",addr,slot);
#endif #endif
ppu_setPagePtr4k((addr>>8)&0xFF, Cart->VROMBanks + (slot * 4 * 1024)); ppu_setPagePtr4k((addr>>8)&0xFF, Cart->VROMBanks + (slot * 4 * 1024));
// memcpy(ppu.Memory+addr, Cart->VROMBanks + (slot * 4 * 1024), 0x1000);
} }
void set_vrom_bank_8k(unsigned short addr, int slot) void set_vrom_bank_8k(uint16_t addr, int slot)
{ {
#ifdef DEBUG_VROM_BANK_SWITCH #ifdef DEBUG_VROM_BANK_SWITCH
console_printf(Console_Default, "Change vrom 8k bank 0x%X to slot %d\n",addr,slot); console_printf(Console_Default, "Change vrom 8k bank 0x%X to slot %d\n",addr,slot);
#endif #endif
ppu_setPagePtr8k(0x00, Cart->VROMBanks + (slot * 8 * 1024)); ppu_setPagePtr8k(0x00, Cart->VROMBanks + (slot * 8 * 1024));
// memcpy(ppu.Memory, Cart->VROMBanks + (slot * 8 * 1024) , 0x2000);
} }
/*-----------*/ /*-----------*/
void set_prom_bank_8k(unsigned short addr,int slot) void set_prom_bank_8k(uint16_t addr,int slot)
{ {
#ifdef DEBUG_PROM_BANK_SWITCH #ifdef DEBUG_PROM_BANK_SWITCH
console_printf(Console_Default, "Change prom 8k bank 0x%X to slot %d\n",addr,slot); console_printf(Console_Default, "Change prom 8k bank 0x%X to slot %d\n",addr,slot);
@ -81,7 +72,7 @@ void set_prom_bank_8k(unsigned short addr,int slot)
set_page_ptr_8k(addr >> 8, Cart->PROMBanks + (slot * 8 * 1024)); set_page_ptr_8k(addr >> 8, Cart->PROMBanks + (slot * 8 * 1024));
} }
void set_prom_bank_16k(unsigned short addr,int slot) void set_prom_bank_16k(uint16_t addr,int slot)
{ {
#ifdef DEBUG_PROM_BANK_SWITCH #ifdef DEBUG_PROM_BANK_SWITCH
console_printf(Console_Default, "Change prom 16k bank @ 0x%X [0x%X] to slot 0x%X\n",addr, addr>>8,slot); console_printf(Console_Default, "Change prom 16k bank @ 0x%X [0x%X] to slot 0x%X\n",addr, addr>>8,slot);
@ -89,15 +80,13 @@ void set_prom_bank_16k(unsigned short addr,int slot)
set_page_ptr_16k(addr >> 8, Cart->PROMBanks + (slot * 16 * 1024)); set_page_ptr_16k(addr >> 8, Cart->PROMBanks + (slot * 16 * 1024));
} }
void set_prom_bank_32k(unsigned short addr,int slot) void set_prom_bank_32k(uint16_t addr,int slot)
{ /* addr may not be different from 0x8000 !*/ { /* addr may not be different from 0x8000 !*/
/* Anyway I don't use it */ /* Anyway I don't use it */
#ifdef DEBUG_PROM_BANK_SWITCH #ifdef DEBUG_PROM_BANK_SWITCH
console_printf(Console_Default, "Change prom 32k bank 0x%X to slot %d\n",addr,slot); console_printf(Console_Default, "Change prom 32k bank 0x%X to slot %d\n",addr,slot);
#endif #endif
set_page_ptr_32k(addr >> 8, Cart->PROMBanks + (slot * 32 * 1024)); set_page_ptr_32k(addr >> 8, Cart->PROMBanks + (slot * 32 * 1024));
/* set_page_ptr_16k(0x80, Cart->PROMBanks[(slot<<1)]);
set_page_ptr_16k(0xC0, Cart->PROMBanks[(slot<<1)+1]);*/
} }

View File

@ -1,14 +1,9 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2016 986-Studio. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
if (COVERALLS) if (COVERALLS)
set(COVERAGE_SRCS src/memorymanager/memory.c ${COVERAGE_SRCS} PARENT_SCOPE) set(COVERAGE_SRCS src/memorymanager/memory.c ${COVERAGE_SRCS} PARENT_SCOPE)
endif() endif()

View File

@ -1,17 +1,12 @@
/* /*
* 6502 Memory manager - The TI-NESulator Project * 6502 Memory manager - The peTI-NESulator Project
* memory.c - Taken from the Quick6502 project * memory.c - Taken from the Quick6502 project
* *
* Created by Manoel Trapier on 18/09/06. * Created by Manoël Trapier on 18/09/06.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include <stdio.h> #include <stdio.h>
#include <types.h> #include <types.h>
@ -21,21 +16,21 @@
/* Private structures */ /* Private structures */
#define KBYTE * (1024) #define KByte * (1024)
/* /*
* What inside memory manager: * What inside memory manager:
* *
* Table of attributes * Table of attributes
* Table of original page ptr * Table of original page ptr
* Table of moded page ptr * Table of modded page ptr
* *
*/ */
/* Private data */ /* Private data */
byte *memory_pages[0x100]; uint8_t *memory_pages[0x100];
byte memory_pages_attr[0x100]; uint8_t memory_pages_attr[0x100];
func_rdhook rdh_table[0x100]; func_rdhook rdh_table[0x100];
func_wrhook wrh_table[0x100]; func_wrhook wrh_table[0x100];
@ -50,26 +45,26 @@ func_wrhook wrh_table[0x100];
#endif #endif
/* Public functions */ /* Public functions */
void set_page_ptr(byte page, byte *ptr) void set_page_ptr(uint8_t page, uint8_t *ptr)
{ {
LOG(console_printf(Console_Default, "Set page 0x%X to ptr %p\n", page, ptr)); LOG(console_printf(Console_Default, "Set page 0x%X to ptr %p\n", page, ptr));
memory_pages[page] = ptr; memory_pages[page] = ptr;
} }
void set_page_ptr_1k(byte page, byte *ptr) void set_page_ptr_1k(uint8_t page, uint8_t *ptr)
{ /* 1k = 4 * 256 */ { /* 1k = 4 * 256 */
LOG(console_printf(Console_Default, "Set page(1k) 0x%X to ptr %p\n", page, ptr)); LOG(console_printf(Console_Default, "Set page(1k) 0x%X to ptr %p\n", page, ptr));
memory_pages[page + 0] = ptr; memory_pages[page + 0] = ptr;
memory_pages[page + 1] = ptr + 0x100; memory_pages[page + 1] = ptr + 0x100;
memory_pages[page + 2] = ptr + (0x100 * 2); memory_pages[page + 2] = ptr + (0x100 * 2);
memory_pages[page + 3] = ptr + (0x100 * 3); memory_pages[page + 3] = ptr + (0x100 * 3);
} }
void set_page_ptr_2k(byte page, byte *ptr) void set_page_ptr_2k(uint8_t page, uint8_t *ptr)
{ {
LOG(console_printf(Console_Default, "Set page(2k) 0x%X to ptr %p\n", page, ptr)); LOG(console_printf(Console_Default, "Set page(2k) 0x%X to ptr %p\n", page, ptr));
memory_pages[page + 0] = ptr; memory_pages[page + 0] = ptr;
memory_pages[page + 1] = ptr + 0x100; memory_pages[page + 1] = ptr + 0x100;
memory_pages[page + 2] = ptr + (0x100 * 2); memory_pages[page + 2] = ptr + (0x100 * 2);
memory_pages[page + 3] = ptr + (0x100 * 3); memory_pages[page + 3] = ptr + (0x100 * 3);
memory_pages[page + 4] = ptr + (0x100 * 4); memory_pages[page + 4] = ptr + (0x100 * 4);
@ -78,33 +73,33 @@ void set_page_ptr_2k(byte page, byte *ptr)
memory_pages[page + 7] = ptr + (0x100 * 7); memory_pages[page + 7] = ptr + (0x100 * 7);
} }
void set_page_ptr_4k(byte page, byte *ptr) void set_page_ptr_4k(uint8_t page, uint8_t *ptr)
{ {
LOG(console_printf(Console_Default, "Set page(4k) 0x%X to ptr %p\n", page, ptr)); LOG(console_printf(Console_Default, "Set page(4k) 0x%X to ptr %p\n", page, ptr));
set_page_ptr_2k(page, ptr); set_page_ptr_2k(page, ptr);
set_page_ptr_2k(page+((4 KBYTE / 256) / 2), ptr + 2 KBYTE); set_page_ptr_2k(page + ((4 KByte / 256) / 2), ptr + 2 KByte);
} }
void set_page_ptr_8k(byte page, byte *ptr) void set_page_ptr_8k(uint8_t page, uint8_t *ptr)
{ {
LOG(console_printf(Console_Default, "Set page(8k) 0x%X to ptr %p\n", page, ptr)); LOG(console_printf(Console_Default, "Set page(8k) 0x%X to ptr %p\n", page, ptr));
set_page_ptr_4k(page, ptr); set_page_ptr_4k(page, ptr);
set_page_ptr_4k(page+((8 KBYTE / 256) / 2), ptr + 4 KBYTE); set_page_ptr_4k(page + ((8 KByte / 256) / 2), ptr + 4 KByte);
} }
void set_page_ptr_16k(byte page, byte *ptr) void set_page_ptr_16k(uint8_t page, uint8_t *ptr)
{ {
set_page_ptr_8k(page, ptr); set_page_ptr_8k(page, ptr);
set_page_ptr_8k(page+((16 KBYTE / 256) / 2), ptr + 8 KBYTE); set_page_ptr_8k(page + ((16 KByte / 256) / 2), ptr + 8 KByte);
} }
void set_page_ptr_32k(byte page, byte *ptr) void set_page_ptr_32k(uint8_t page, uint8_t *ptr)
{ {
set_page_ptr_16k(page, ptr); set_page_ptr_16k(page, ptr);
set_page_ptr_16k(page+((32 KBYTE / 256) / 2), ptr + 16 KBYTE); set_page_ptr_16k(page + ((32 KByte / 256) / 2), ptr + 16 KByte);
} }
byte *get_page_ptr(byte page) uint8_t *get_page_ptr(uint8_t page)
{ {
return memory_pages[page]; return memory_pages[page];
} }
@ -112,60 +107,76 @@ byte *get_page_ptr(byte page)
/* Functions to set pages attributes */ /* Functions to set pages attributes */
void set_page_rd_hook(byte page, func_rdhook func) void set_page_rd_hook(uint8_t page, func_rdhook func)
{ {
if (func == NULL) if (func == NULL)
{ {
memory_pages_attr[page] &= (~ATTR_PAGE_HAVE_RDHOOK); memory_pages_attr[page] &= (~ATTR_PAGE_HAVE_RDHOOK);
if (memory_pages[page] == (byte *)0x01) if (memory_pages[page] == (uint8_t *)0x01)
{
memory_pages[page] = NULL; memory_pages[page] = NULL;
}
} }
else else
{ {
memory_pages_attr[page] |= ATTR_PAGE_HAVE_RDHOOK; memory_pages_attr[page] |= ATTR_PAGE_HAVE_RDHOOK;
if (memory_pages[page] == NULL) if (memory_pages[page] == NULL)
memory_pages[page] = (byte *)0x01; {
memory_pages[page] = (uint8_t *)0x01;
}
} }
rdh_table[page] = func; rdh_table[page] = func;
} }
void set_page_wr_hook(byte page, func_wrhook func) void set_page_wr_hook(uint8_t page, func_wrhook func)
{ {
if (func == NULL) if (func == NULL)
{ {
memory_pages_attr[page] &= (~ATTR_PAGE_HAVE_WRHOOK); memory_pages_attr[page] &= (~ATTR_PAGE_HAVE_WRHOOK);
if (memory_pages[page] == (byte*)0x01) if (memory_pages[page] == (uint8_t *)0x01)
{
memory_pages[page] = NULL; memory_pages[page] = NULL;
}
} }
else else
{ {
memory_pages_attr[page] |= ATTR_PAGE_HAVE_WRHOOK; memory_pages_attr[page] |= ATTR_PAGE_HAVE_WRHOOK;
if (memory_pages[page] == NULL) if (memory_pages[page] == NULL)
memory_pages[page] = (byte *)0x01; {
memory_pages[page] = (uint8_t *)0x01;
}
} }
wrh_table[page] = func; wrh_table[page] = func;
} }
void set_page_readable(byte page, bool value) void set_page_readable(uint8_t page, uint8_t value)
{ {
if (value == true) if (value == true)
{
memory_pages_attr[page] |= ATTR_PAGE_READABLE; memory_pages_attr[page] |= ATTR_PAGE_READABLE;
}
else else
memory_pages_attr[page] &= (~ATTR_PAGE_READABLE); {
memory_pages_attr[page] &= (~ATTR_PAGE_READABLE);
}
} }
void set_page_writeable(byte page, bool value) void set_page_writeable(uint8_t page, uint8_t value)
{ {
if (value == true) if (value == true)
{
memory_pages_attr[page] |= ATTR_PAGE_WRITEABLE; memory_pages_attr[page] |= ATTR_PAGE_WRITEABLE;
}
else else
memory_pages_attr[page] &= (~ATTR_PAGE_WRITEABLE); {
memory_pages_attr[page] &= (~ATTR_PAGE_WRITEABLE);
}
} }
void set_page_ghost(byte page, bool value, byte ghost) void set_page_ghost(uint8_t page, uint8_t value, uint8_t ghost)
{ {
if (value == true) if (value == true)
{ {
@ -176,57 +187,65 @@ void set_page_ghost(byte page, bool value, byte ghost)
} }
} }
byte get_page_attributes(byte page) uint8_t get_page_attributes(uint8_t page)
{ {
return memory_pages_attr[page]; return memory_pages_attr[page];
} }
func_rdhook get_page_rdhook(byte page) func_rdhook get_page_rdhook(uint8_t page)
{ {
if (memory_pages_attr[page] & ATTR_PAGE_HAVE_RDHOOK) if (memory_pages_attr[page] & ATTR_PAGE_HAVE_RDHOOK)
{
return rdh_table[page]; return rdh_table[page];
}
return NULL; return NULL;
} }
func_wrhook get_page_wrhook(byte page) func_wrhook get_page_wrhook(uint8_t page)
{ {
if (memory_pages_attr[page] & ATTR_PAGE_HAVE_WRHOOK) if (memory_pages_attr[page] & ATTR_PAGE_HAVE_WRHOOK)
{
return wrh_table[page]; return wrh_table[page];
}
return NULL; return NULL;
} }
byte ReadMemory(byte page, byte addr) uint8_t ReadMemory(uint8_t page, uint8_t addr)
{ {
static byte LastRetByte = 0xA5; static uint8_t LastRetByte = 0xA5;
byte *page_ptr; uint8_t *page_ptr;
byte attributes; uint8_t attributes;
LOG(console_printf(Console_Default, "Read @ 0x%X-%X\n", page, addr)); LOG(console_printf(Console_Default, "Read @ 0x%X-%X\n", page, addr));
/* Est-ce que la page est mappé ? && Est-ce que la page est "readable" ? */ /* Est-ce que la page est mappé ? && Est-ce que la page est "readable" ? */
if ((page_ptr = memory_pages[page]) && if ((page_ptr = memory_pages[page]) &&
( (attributes = memory_pages_attr[page]) & ATTR_PAGE_READABLE) ) ((attributes = memory_pages_attr[page]) & ATTR_PAGE_READABLE))
{ {
LOG(console_printf(Console_Default, "Page is non null & readable\n")); LOG(console_printf(Console_Default, "Page is non null & readable\n"));
if ( attributes & ATTR_PAGE_HAVE_RDHOOK ) if (attributes & ATTR_PAGE_HAVE_RDHOOK)
return ( LastRetByte = rdh_table[page](addr) ); {
return (LastRetByte = rdh_table[page](addr));
}
else else
return ( LastRetByte = page_ptr[addr] ); {
return (LastRetByte = page_ptr[addr]);
}
} }
//console_printf(Console_Default, "Trying to read @ 0x%X-%X\n", page, addr); //console_printf(Console_Default, "Trying to read @ 0x%X-%X\n", page, addr);
return LastRetByte; return LastRetByte;
} }
void WriteMemory(byte page, byte addr, byte value) void WriteMemory(uint8_t page, uint8_t addr, uint8_t value)
{ {
byte *page_ptr; uint8_t *page_ptr;
byte attributes; uint8_t attributes;
LOG(console_printf(Console_Default, "Write 0x%x @ 0x%X-%X\n", value, page, addr)); LOG(console_printf(Console_Default, "Write 0x%x @ 0x%X-%X\n", value, page, addr));
/* Est-ce que la page est mappé ? && Est-ce que la page est "writable" ? */ /* Est-ce que la page est mappé ? && Est-ce que la page est "writable" ? */
if ( (page_ptr = memory_pages[page]) && if ((page_ptr = memory_pages[page]) &&
( (attributes = memory_pages_attr[page]) & ATTR_PAGE_WRITEABLE) ) ((attributes = memory_pages_attr[page]) & ATTR_PAGE_WRITEABLE))
{ {
if ( attributes & ATTR_PAGE_HAVE_WRHOOK ) if (attributes & ATTR_PAGE_HAVE_WRHOOK)
{ {
#ifdef DETECT_BUS_CONFLICT #ifdef DETECT_BUS_CONFLICT
if ((page >= 0x80) && (memory_pages[page][addr] != value)) if ((page >= 0x80) && (memory_pages[page][addr] != value))
@ -235,40 +254,45 @@ void WriteMemory(byte page, byte addr, byte value)
wrh_table[page](addr, value); wrh_table[page](addr, value);
} }
else else
{
page_ptr[addr] = value; page_ptr[addr] = value;
}
}
else
{
console_printf(Console_Default, "Trying to write 0x%X @ 0x%X-%X\n", value, page, addr);
} }
else { console_printf(Console_Default, "Trying to write 0x%X @ 0x%X-%X\n", value, page, addr); }
} }
void DumpMemoryState(FILE *fp) void DumpMemoryState(FILE *fp)
{ {
int i; int i;
for (i = 0x00; i < 0x100; i++) for (i = 0x00 ; i < 0x100 ; i++)
{ {
fprintf(fp, fprintf(fp,
"Page 0x%02X : [%c%c%c%c%c%c] RdH:%p WrH:%p ptr:%p\n", "Page 0x%02X : [%c%c%c%c%c%c] RdH:%p WrH:%p ptr:%p\n",
i, i,
(memory_pages_attr[i]&ATTR_PAGE_HAVE_RDHOOK)?'r':'.', (memory_pages_attr[i] & ATTR_PAGE_HAVE_RDHOOK) ? 'r' : '.',
(memory_pages_attr[i]&ATTR_PAGE_HAVE_WRHOOK)?'w':'.', (memory_pages_attr[i] & ATTR_PAGE_HAVE_WRHOOK) ? 'w' : '.',
(memory_pages_attr[i]&ATTR_PAGE_READABLE)?'R':'.', (memory_pages_attr[i] & ATTR_PAGE_READABLE) ? 'R' : '.',
(memory_pages_attr[i]&ATTR_PAGE_WRITEABLE)?'W':'.', (memory_pages_attr[i] & ATTR_PAGE_WRITEABLE) ? 'W' : '.',
(memory_pages_attr[i]&ATTR_PAGE_GHOST)?'G':'.', (memory_pages_attr[i] & ATTR_PAGE_GHOST) ? 'G' : '.',
(memory_pages_attr[i]&ATTR_PAGE_MAPPED)?'M':'.', (memory_pages_attr[i] & ATTR_PAGE_MAPPED) ? 'M' : '.',
rdh_table[i], rdh_table[i],
wrh_table[i], wrh_table[i],
memory_pages[i] memory_pages[i]
); );
} }
} }
void InitMemory() void InitMemory()
{ {
int page; int page;
for(page = 0 ; page < 0x100 ; page++) for (page = 0 ; page < 0x100 ; page++)
{ {
set_page_ptr(page,NULL); set_page_ptr(page, NULL);
memory_pages_attr[page] = 0x00; memory_pages_attr[page] = 0x00;
} }
} }

View File

@ -1,12 +1,7 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
add_library(oslib loadfile.c graphics.c sound.c io.c) add_library(oslib loadfile.c graphics.c sound.c io.c)

View File

@ -1,14 +1,9 @@
/* /*
* Graphic Manager - The TI-NESulator Project * Graphic Manager - The peTI-NESulator Project
* os/macos/graphics.c * os/macos/graphics.c
* *
* Created by Manoel TRAPIER on 08/05/08. * Created by Manoël Trapier on 08/05/08.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include <os_dependent.h> #include <os_dependent.h>

View File

@ -1,14 +1,9 @@
/* /*
* IO Manager - The TI-NESulator Project * IO Manager - The peTI-NESulator Project
* os/macos/graphics.c * os/macos/graphics.c
* *
* Created by Manoël Trapier on 04/01/09. * Created by Manoël Trapier on 04/01/09.
* Copyright (c) 2003-2009 986 Corp. All rights reserved. * Copyright (c) 2003-2009 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -40,7 +35,6 @@ int console_vprintf(const ConsoleLevel level, const char *format, va_list ap)
int console_printf(const ConsoleLevel level, const char *format, ...) int console_printf(const ConsoleLevel level, const char *format, ...)
{ {
int ret = 0;
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
@ -56,6 +50,8 @@ int console_printf_d(const char *format, ...)
va_start(ap, format); va_start(ap, format);
console_vprintf (Console_Debug, format, ap); console_vprintf (Console_Debug, format, ap);
va_end(ap);
return 0; return 0;
} }

View File

@ -1,13 +1,8 @@
/* /*
* File functions - The TI-NESulator Project * File functions - The peTI-NESulator Project
* os/macos/load.c * os/macos/load.c
* *
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -30,7 +25,7 @@
void *LoadFilePtr(char * filename) void *LoadFilePtr(char * filename)
{ {
int fd; int fd;
void *RetPtr = NULL; void *RetPtr;
struct stat FileStat; struct stat FileStat;
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);

View File

@ -1,12 +1,7 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
add_library(oslib loadfile.c) add_library(oslib loadfile.c)

View File

@ -1,14 +1,9 @@
/* /*
* TI-68k Loading external file functions - The TI-NESulator Project * TI-68k Loading external file functions - The peTI-NESulator Project
* ti68k/loadfile.c * ti68k/loadfile.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2008 986Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate:$
* $Author:$
* $HeadURL:$
* $Revision:$
* *
*/ */
@ -24,7 +19,7 @@ void *LoadFilePtr(char * filename)
if ((fp = fopen(filename,"rb")) == NULL) if ((fp = fopen(filename,"rb")) == NULL)
return -1; return -1;
/* TI Related stuff, very uggly, and need to be changed.. */ /* TI Related stuff, very ugly, and need to be changed.. */
HeapLock(fp->handle); HeapLock(fp->handle);
RetPtr = 2 + HeapDeref(fp->handle); RetPtr = 2 + HeapDeref(fp->handle);

View File

@ -1,19 +1,14 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2016 986-Studio. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
if (COVERALLS) 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) 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) add_library(oslib loadfile.c graphics_dummy.c sound.c io.c text.c)
else() else()
add_library(oslib loadfile.c graphics.c sound.c io.c) add_library(oslib loadfile.c graphics.c sound.c io.c text.c)
endif() endif()
target_link_libraries(oslib glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY}) target_link_libraries(oslib glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY})

Binary file not shown.

View File

@ -1,14 +1,9 @@
/* /*
* Graphic Manager - The TI-NESulator Project * Graphic Manager - The peTI-NESulator Project
* os/macos/graphics.c * os/macos/graphics.c
* *
* Created by Manoel TRAPIER on 08/05/08. * Created by Manoël Trapier on 08/05/08.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include <stdlib.h> #include <stdlib.h>
@ -19,420 +14,494 @@
#include <os_dependent.h> #include <os_dependent.h>
#define GLFW_INCLUDE_GLEXT #define GLFW_INCLUDE_GLEXT
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
/* "Apple" fix */
#ifndef GL_TEXTURE_RECTANGLE
#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_EXT
#endif
#include <palette.h> #include <palette.h>
typedef struct GLWindow_t GLWindow; typedef struct GLWindow_t GLWindow;
struct KeyArray struct KeyArray
{ {
unsigned char lastState; uint8_t lastState;
unsigned char curState; uint8_t curState;
unsigned char debounced; uint8_t debounced;
GLFWwindow* window; GLFWwindow *window;
}; };
struct GLWindow_t struct GLWindow_t
{ {
struct KeyArray keyArray[512]; struct KeyArray keyArray[512];
GLFWwindow* windows; GLFWwindow *windows;
unsigned char *videoMemory; uint8_t *videoMemory;
GLint videoTexture; GLuint videoTexture;
int WIDTH; int WIDTH;
int HEIGHT; int HEIGHT;
}; };
static int window_num = 0; static int window_num = 0;
void GLWindowInitEx(GLWindow *g, int w, int h) void GLWindowInitEx(GLWindow *g, int w, int h)
{ {
g->WIDTH = w; g->WIDTH = w;
g->HEIGHT = h; g->HEIGHT = h;
g->videoTexture = window_num++; g->videoTexture = window_num++;
} }
void GLWindowInit(GLWindow *g) void GLWindowInit(GLWindow *g)
{ {
GLWindowInitEx(g, 100, 100); GLWindowInitEx(g, 100, 100);
} }
void ShowScreen(GLWindow *g, int w, int h) void ShowScreen(GLWindow *g, int w, int h)
{ {
glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture); glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
// glTexSubImage2D is faster when not using a texture range // 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); glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f);
glVertex2f(-1.0f,1.0f); glVertex2f(-1.0f, 1.0f);
glTexCoord2f(0.0f, h); glTexCoord2f(0.0f, h);
glVertex2f(-1.0f, -1.0f); glVertex2f(-1.0f, -1.0f);
glTexCoord2f(w, h); glTexCoord2f(w, h);
glVertex2f(1.0f, -1.0f); glVertex2f(1.0f, -1.0f);
glTexCoord2f(w, 0.0f); glTexCoord2f(w, 0.0f);
glVertex2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f);
glEnd(); glEnd();
glFlush(); glFlush();
} }
void setupGL(GLWindow *g, int w, int h) void setupGL(GLWindow *g, int w, int h)
{ {
g->videoMemory = (unsigned char*)malloc(w*h*sizeof(unsigned int)); g->videoMemory = (uint8_t *)malloc(w * h * sizeof(uint32_t));
memset(g->videoMemory, 0,w*h*sizeof(unsigned int)); memset(g->videoMemory, 0, w * h * sizeof(uint32_t));
//Tell OpenGL how to convert from coordinates to pixel values //Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glClearColor(1.0f, 0.f, 1.0f, 1.0f); glClearColor(1.0f, 0.f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE); glEnable(GL_TEXTURE_RECTANGLE);
glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture); glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
// glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_NV_EXT, 0, NULL); // glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_NV_EXT, 0, NULL);
// glTexParameteri(GL_TEXTURE_RECTANGLE_NV_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE); // glTexParameteri(GL_TEXTURE_RECTANGLE_NV_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE);
// glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); // glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 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_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, w, glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, w,
h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory); h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
void restoreGL(GLWindow *g, int w, int h) void restoreGL(GLWindow *g, int w, int h)
{ {
//Tell OpenGL how to convert from coordinates to pixel values //Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glClearColor(1.0f, 0.f, 1.0f, 1.0f); glClearColor(1.0f, 0.f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE); glEnable(GL_TEXTURE_RECTANGLE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
void kbHandler(GLFWwindow* window, int key, int scan, int action, int mod ) void kbHandler(GLFWwindow *window, int key, int scan, int action, int mod)
{ {
struct KeyArray *keyArray; struct KeyArray *keyArray;
keyArray = (struct KeyArray*) glfwGetWindowUserPointer(window); keyArray = (struct KeyArray *)glfwGetWindowUserPointer(window);
keyArray[key].lastState=keyArray[key].curState; keyArray[key].lastState = keyArray[key].curState;
if (action==GLFW_RELEASE) if (action == GLFW_RELEASE)
{ {
keyArray[key].curState=GLFW_RELEASE; keyArray[key].curState = GLFW_RELEASE;
} }
else else
{ {
keyArray[key].curState=GLFW_PRESS; keyArray[key].curState = GLFW_PRESS;
} }
keyArray[key].debounced |= (keyArray[key].lastState==GLFW_RELEASE)&&(keyArray[key].curState==GLFW_PRESS); keyArray[key].debounced |= (keyArray[key].lastState == GLFW_RELEASE) && (keyArray[key].curState == GLFW_PRESS);
keyArray[key].window = window; keyArray[key].window = window;
/*printf("key:%d, state:%d debounce:%d, laststate:%d\n", key, keyArray[key].curState,
keyArray[key].debounced, keyArray[key].lastState);*/
} }
void sizeHandler(GLFWwindow* window,int xs,int ys) void sizeHandler(GLFWwindow *window, int xs, int ys)
{ {
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
glViewport(0, 0, xs, ys); glViewport(0, 0, xs, ys);
} }
static void error_callback(int error, const char* description) static void error_callback(int error, const char *description)
{ {
puts(description); puts(description);
} }
void initDisplay(GLWindow *g) void initDisplay(GLWindow *g)
{ {
int h = g->HEIGHT; int h = g->HEIGHT;
int w = g->WIDTH; int w = g->WIDTH;
/// Initialize GLFW /// Initialize GLFW
glfwInit(); glfwInit();
glfwSetErrorCallback(error_callback); glfwSetErrorCallback(error_callback);
// Open screen OpenGL window // Open screen OpenGL window
if( !(g->windows=glfwCreateWindow( g->WIDTH, g->HEIGHT, "Main", NULL, NULL)) ) if (!(g->windows = glfwCreateWindow(g->WIDTH, g->HEIGHT, "Main", NULL, NULL)))
{ {
glfwTerminate(); glfwTerminate();
fprintf(stderr, "Window creation error...\n"); fprintf(stderr, "Window creation error...\n");
abort(); abort();
} }
glfwMakeContextCurrent(g->windows); glfwSetWindowAspectRatio(g->windows, 4, 3);
setupGL(g, g->WIDTH, g->HEIGHT);
glfwSwapInterval(0); // Disable VSYNC glfwMakeContextCurrent(g->windows);
setupGL(g, g->WIDTH, g->HEIGHT);
glfwGetWindowSize(g->windows, &w, &h); glfwSwapInterval(1); // We need vsync
glfwSetWindowUserPointer(g->windows, g->keyArray); glfwGetWindowSize(g->windows, &w, &h);
glfwSetKeyCallback(g->windows, kbHandler); glfwSetWindowUserPointer(g->windows, g->keyArray);
glfwSetWindowSizeCallback(g->windows, sizeHandler);
glfwSetKeyCallback(g->windows, kbHandler);
glfwSetWindowSizeCallback(g->windows, sizeHandler);
} }
void drawPixel(GLWindow *gw, int x, int y, uint32_t colour) static void drawPixel(GLWindow *gw, uint32_t x, uint32_t y, uint32_t colour)
{ {
uint8_t r,g,b,a; uint8_t r, g, b, a;
uint32_t offset = (y*gw->WIDTH*4)+4*x; uint32_t offset = (y * gw->WIDTH * 4U) + 4U * x;
if ((x < 0) || (x > gw->WIDTH) || (y < 0) || (y > gw->HEIGHT)) if ((x > (uint32_t)gw->WIDTH) || (y > (uint32_t)gw->HEIGHT))
return; {
return;
}
b = colour & 0xFF; b = colour & 0xFF;
g = (colour >> 8) & 0xFF; g = (colour >> 8) & 0xFF;
r = (colour >> 16) & 0xFF; r = (colour >> 16) & 0xFF;
a = (colour >> 24) & 0xFF; a = (colour >> 24) & 0xFF;
gw->videoMemory[offset + 0] = a; gw->videoMemory[offset + 0] = a;
gw->videoMemory[offset + 1] = r; gw->videoMemory[offset + 1] = r;
gw->videoMemory[offset + 2] = g; gw->videoMemory[offset + 2] = g;
gw->videoMemory[offset + 3] = b; gw->videoMemory[offset + 3] = b;
} }
void drawLine(GLWindow *g, int x0, int y0, int x1, int y1, uint32_t colour) static void drawLine(GLWindow *g, int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t colour)
{ {
int d, dx, dy, aincr, bincr, xincr, yincr, x, y; printf("%s:%s(%p, %d, %d, %d, %d, %d) @ %d\n", __FILE__, __func__,
if (abs(x1 - x0) < abs(y1 - y0)) g, x0, y0, x1, y1, colour,
{ __LINE__);
/* parcours par l'axe vertical */ int32_t d, dx, dy, aincr, bincr, xincr, yincr;
if (y0 > y1) int32_t x, y;
{ if (abs((int32_t)x1 - x0) < abs((int32_t)y1 - y0))
drawLine(g, x1, y1, x0, y0, colour); {
goto exit; /* parcours par l'axe vertical */
} if (y0 > y1)
{
drawLine(g, x1, y1, x0, y0, colour);
goto exit;
}
xincr = x1 > x0 ? 1 : -1; xincr = x1 > x0 ? 1 : -1;
dy = y1 - y0; dy = y1 - y0;
dx = abs(x1 - x0); dx = abs((int32_t)x1 - x0);
d = 2 * dx - dy; d = 2 * dx - dy;
aincr = 2 * (dx - dy); aincr = 2 * ((int32_t)dx - dy);
bincr = 2 * dx; bincr = 2 * dx;
x = x0; x = x0;
y = y0; y = y0;
drawPixel(g, x, y, colour); drawPixel(g, x, y, colour);
for (y = y0+1; y <= y1; y++) for (y = y0 + 1 ; y <= y1 ; y++)
{ {
if (d >= 0) if (d >= 0)
{ {
x += xincr; x += xincr;
d += aincr; d += aincr;
} }
else else
{ {
d += bincr; d += bincr;
} }
drawPixel(g, x, y, colour); drawPixel(g, x, y, colour);
} }
} }
else else
{ {
/* parcours par l'axe horizontal */ /* parcours par l'axe horizontal */
if (x0 > x1) if (x0 > x1)
{ {
drawLine(g, x1, y1, x0, y0, colour); drawLine(g, x1, y1, x0, y0, colour);
goto exit; goto exit;
} }
yincr = y1 > y0 ? 1 : -1; yincr = y1 > y0 ? 1 : -1;
dx = x1 - x0; dx = x1 - x0;
dy = abs(y1 - y0); dy = abs((int32_t)y1 - y0);
d = 2 * dy - dx; d = 2 * dy - dx;
aincr = 2 * (dy - dx); aincr = 2 * (dy - dx);
bincr = 2 * dy; bincr = 2 * dy;
x = x0; x = x0;
y = y0; y = y0;
drawPixel(g, x, y, colour); drawPixel(g, x, y, colour);
for (x = x0+1; x <= x1; ++x) for (x = x0 + 1 ; x <= x1 ; ++x)
{ {
if (d >= 0) if (d >= 0)
{ {
y += yincr; y += yincr;
d += aincr; d += aincr;
} }
else else
{ {
d += bincr; d += bincr;
} }
drawPixel(g, x, y, colour); drawPixel(g, x, y, colour);
} }
} }
exit: exit:
return; return;
} }
void drawCircle(GLWindow *g, int xc, int yc, int radius, uint32_t colour) static void drawCircle(GLWindow *g, int xc, int yc, int radius, uint32_t colour)
{ {
int f = 1 - radius; int f = 1 - radius;
int ddF_x = 0; int ddF_x = 0;
int ddF_y = -2 * radius; int ddF_y = -2 * radius;
int x = 0; int x = 0;
int y = radius; int y = radius;
int pX, pY; int pX, pY;
pX = xc; pY = yc + radius; pX = xc;
drawPixel(g, pX, pY, colour); pY = yc + radius;
pY -= (2*radius); drawPixel(g, pX, pY, colour);
drawPixel(g, pX, pY, colour); pY -= (2 * radius);
pY += radius; pX += radius; drawPixel(g, pX, pY, colour);
drawPixel(g, pX, pY, colour); pY += radius;
pX -= (2*radius); pX += radius;
drawPixel(g, pX, pY, colour); drawPixel(g, pX, pY, colour);
pX -= (2 * radius);
drawPixel(g, pX, pY, colour);
while(x < y) while (x < y)
{ {
if(f >= 0) if (f >= 0)
{ {
y--; y--;
ddF_y += 2; ddF_y += 2;
f += ddF_y; f += ddF_y;
} }
x++; x++;
ddF_x += 2; ddF_x += 2;
f += ddF_x + 1; f += ddF_x + 1;
pX = xc+x ; pY = yc+y; pX = xc + x;
drawPixel(g, pX, pY, colour); pY = yc + y;
pX = xc-x ; pY = yc+y; drawPixel(g, pX, pY, colour);
drawPixel(g, pX, pY, colour); pX = xc - x;
pX = xc+x ; pY = yc-y; pY = yc + y;
drawPixel(g, pX, pY, colour); drawPixel(g, pX, pY, colour);
pX = xc-x ; pY = yc-y; pX = xc + x;
drawPixel(g, pX, pY, colour); pY = yc - y;
pX = xc+y ; pY = yc+x; drawPixel(g, pX, pY, colour);
drawPixel(g, pX, pY, colour); pX = xc - x;
pX = xc-y ; pY = yc+x; pY = yc - y;
drawPixel(g, pX, pY, colour); drawPixel(g, pX, pY, colour);
pX = xc+y ; pY = yc-x; pX = xc + y;
drawPixel(g, pX, pY, colour); pY = yc + x;
pX = xc-y ; pY = yc-x; drawPixel(g, pX, pY, colour);
drawPixel(g, pX, pY, colour); pX = xc - y;
} pY = yc + x;
drawPixel(g, pX, pY, colour);
return; pX = xc + y;
pY = yc - x;
drawPixel(g, pX, pY, colour);
pX = xc - y;
pY = yc - x;
drawPixel(g, pX, pY, colour);
}
} }
void drawRect(GLWindow *g, int x0, int y0, int w, int h, uint32_t colour) static void drawRect(GLWindow *g, uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint32_t colour)
{ {
drawLine(g, x0 , y0 , x0 + w, y0 , colour); printf("%s:%s(%p, %d, %d, %d, %d, %d) @ %d\n", __FILE__, __func__,
drawLine(g, x0 + w, y0 , x0 + w, y0 + h, colour); g, x0, y0, w, h, colour,
drawLine(g, x0 + w, y0 + h, x0 , y0 + h, colour); __LINE__);
drawLine(g, x0 , y0 + h, x0 , y0 , 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) static void drawFillrect(GLWindow *g, uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint32_t colour)
{ {
int i; printf("%s:%s(%p, %d, %d, %d, %d, %d) @ %d\n", __FILE__, __func__,
for(i = 0; i < h; i++) g, x0, y0, w, h, colour,
drawLine(g, x0, y0+i, x0+w, y0+i, colour); __LINE__);
uint32_t i;
for (i = 0 ; i < h ; i++)
{
drawLine(g, x0, y0 + i, x0 + w, y0 + i, colour);
}
} }
void clearScreen(GLWindow *g) void clearScreen(GLWindow *g)
{ {
memset(g->videoMemory, 0, sizeof(uint8_t) * g->WIDTH * g->HEIGHT * 4); memset(g->videoMemory, 0, sizeof(uint8_t) * g->WIDTH * g->HEIGHT * 4);
} }
void updateScreen(GLWindow *g) void updateScreen(GLWindow *g)
{ {
/*Update windows code */ /* Update windows code */
glfwMakeContextCurrent(g->windows); glfwMakeContextCurrent(g->windows);
ShowScreen(g, g->WIDTH, g->HEIGHT); ShowScreen(g, g->WIDTH, g->HEIGHT);
glfwSwapBuffers(g->windows); glfwSwapBuffers(g->windows);
glfwPollEvents(); glfwPollEvents();
} }
void updateScreenAndWait(GLWindow *g) void updateScreenAndWait(GLWindow *g)
{ {
while (glfwGetKey(g->windows,GLFW_KEY_ESCAPE) != GLFW_PRESS) while (glfwGetKey(g->windows, GLFW_KEY_ESCAPE) != GLFW_PRESS)
{ {
updateScreen(g); updateScreen(g);
glfwPollEvents(); glfwPollEvents();
} }
while(glfwGetKey(g->windows,GLFW_KEY_ESCAPE) != GLFW_RELEASE) while (glfwGetKey(g->windows, GLFW_KEY_ESCAPE) != GLFW_RELEASE)
{ {
glfwPollEvents(); glfwPollEvents();
} }
} }
GLWindow mainWindow; GLWindow mainWindow;
int graphics_init() int graphics_init()
{ {
GLWindowInitEx(&mainWindow, 256, 240); GLWindowInitEx(&mainWindow, 256, 240);
initDisplay(&mainWindow); initDisplay(&mainWindow);
clearScreen(&mainWindow); clearScreen(&mainWindow);
updateScreen(&mainWindow); updateScreen(&mainWindow);
return 0; return 0;
} }
static unsigned long getColour(long color) static uint32_t getColour(long color)
{ {
Palette *pal = &basicPalette[color]; Palette *pal = &basicPalette[color];
uint8_t r, g, b, a; uint8_t r, g, b, a;
r = pal->r; r = pal->r << 2;
b = pal->b; b = pal->b << 2;
g = pal->g; g = pal->g << 2;
a = 255;//pal->a; a = 255;//pal->a;
return (b << 24) | (g << 16) | (r << 8) | a; return (b << 24) | (g << 16) | (r << 8) | a;
}
int graphics_getScreenSize(int *w, int *h)
{
*w = mainWindow.WIDTH;
*h = mainWindow.HEIGHT;
return 0;
}
int graphics_drawRect(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint32_t colour)
{
printf("%s:%s(%d, %d, %d, %d, %d) @ %d\n", __FILE__, __func__,
x0, y0, w, h, colour,
__LINE__);
drawRect(&mainWindow, x0, y0, w, h, colour);
return 0;
}
int graphics_drawFillrect(int x0, int y0, int w, int h, uint32_t colour)
{
printf("%s:%s(%d, %d, %d, %d, %d) @ %d\n", __FILE__, __func__,
x0, y0, w, h, colour,
__LINE__);
drawFillrect(&mainWindow, x0, y0, w, h, colour);
return 0;
} }
int graphics_drawpixel(long x, long y, long color) int graphics_drawpixel(long x, long y, long color)
{ {
drawPixel(&mainWindow, x, y, getColour(color)); drawPixel(&mainWindow, x, y, getColour(color));
return 0; return 0;
} }
int graphics_drawline(long x, long y, long x1, long y1, long color) int graphics_drawCircle(int xc, int yc, int radius, uint32_t colour)
{ {
drawLine(&mainWindow, x, y, x1, y1, getColour(color)); drawCircle(&mainWindow, xc, yc, radius, colour);
return 0; return 0;
}
int graphics_drawline(uint32_t x, uint32_t y, uint32_t x1, uint32_t y1, uint32_t colour)
{
printf("%s:%s(%d, %d, %d, %d, %d) @ %d\n", __FILE__, __func__,
x, y, x1, y1, colour,
__LINE__);
drawLine(&mainWindow, x, y, x1, y1, getColour(colour));
return 0;
} }
int graphics_blit(long x, long y, long w, long h) int graphics_blit(long x, long y, long w, long h)
{ {
updateScreen(&mainWindow); /* Just pool for events, no graphic thing to be done ATM */
return 0; glfwPollEvents();
return 0;
} }
int getKeyStatus(int key) int getKeyStatus(int key)
{ {
return mainWindow.keyArray[key].curState; return mainWindow.keyArray[key].curState;
}
/* Sync with 60Hz (or try to) */
void vsync(void)
{
updateScreen(&mainWindow);
} }

View File

@ -1,14 +1,9 @@
/* /*
* Graphic Manager - The TI-NESulator Project * Graphic Manager - The peTI-NESulator Project
* os/macos/graphics.c * os/macos/graphics.c
* *
* Created by Manoel TRAPIER on 08/05/08. * Created by Manoël Trapier on 08/05/08.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include <stdlib.h> #include <stdlib.h>
@ -16,6 +11,10 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <sys/time.h>
#include <time.h>
#include <os_dependent.h> #include <os_dependent.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@ -27,20 +26,19 @@ typedef struct GLWindow_t GLWindow;
struct KeyArray struct KeyArray
{ {
unsigned char lastState; uint8_t lastState;
unsigned char curState; uint8_t curState;
unsigned char debounced; uint8_t debounced;
GLFWwindow* window;
}; };
struct GLWindow_t struct GLWindow_t
{ {
struct KeyArray keyArray[512]; struct KeyArray keyArray[512];
GLFWwindow* windows; GLFWwindow *windows;
unsigned char *videoMemory; uint8_t *videoMemory;
GLint videoTexture; GLint videoTexture;
int WIDTH; int WIDTH;
int HEIGHT; int HEIGHT;
}; };
#ifndef GL_TEXTURE_RECTANGLE_EXT #ifndef GL_TEXTURE_RECTANGLE_EXT
@ -67,11 +65,11 @@ void restoreGL(GLWindow *g, int w, int h)
{ {
} }
void kbHandler(GLFWwindow* window, int key, int scan, int action, int mod ) void kbHandler(GLFWwindow *window, int key, int scan, int action, int mod)
{ {
} }
void sizeHandler(GLFWwindow* window,int xs,int ys) void sizeHandler(GLFWwindow *window, int xs, int ys)
{ {
} }
@ -114,25 +112,92 @@ void updateScreenAndWait(GLWindow *g)
int graphics_init() int graphics_init()
{ {
return 0; return 0;
} }
int graphics_drawpixel(long x, long y, long color) int graphics_drawpixel(long x, long y, long color)
{ {
return 0; return 0;
} }
int graphics_drawline(long x, long y, long x1, long y1, long color) int graphics_drawline(uint32_t x, uint32_t y, uint32_t x1, uint32_t y1, uint32_t colour)
{ {
return 0; return 0;
}
int graphics_drawRect(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint32_t colour)
{
return 0;
}
int graphics_drawFillrect(int x0, int y0, int w, int h, uint32_t colour)
{
return 0;
}
int graphics_getScreenSize(int *w, int *h)
{
*w = 640;
*h = 320;
return 0;
} }
int graphics_blit(long x, long y, long w, long h) int graphics_blit(long x, long y, long w, long h)
{ {
return 0; return 0;
} }
int getKeyStatus(int key) int getKeyStatus(int key)
{ {
return 0; return 0;
} }
/* Sync with 60Hz (or try to) */
void vsync(void)
{
#if 0
/* For now don't do anything there */
long WaitTime;
static long delta = 0;
/* Try to sync at 60FPS */
/* Get current time in microseconds */
gettimeofday(&timeEnd, NULL);
WaitTime = (timeEnd.tv_sec) - (timeStart.tv_sec);
WaitTime *= 1000000;
WaitTime += (timeEnd.tv_usec - timeStart.tv_usec);
#if !ISPAL && ISNTSC
/* Calculate the waiting time, 16666 is the time of one frame in microseconds at a 60Hz rate) */
WaitTime = 16666 - WaitTime + delta;
#elif ISPAL && !ISNTSC
WaitTime = 20000 - WaitTime + delta;
#endif
#ifndef RUN_COVERAGE
if ((WaitTime >= 0) && (WaitTime < 100000))
{
usleep(WaitTime);
}
#endif
/* Now get the time after sleep */
gettimeofday(&timeStart, NULL);
/* Now calculate How many microseconds we really spend in sleep and
calculate a delta for next iteration */
delta = (timeStart.tv_sec) - (timeEnd.tv_sec);
delta *= 1000000;
delta += (timeStart.tv_usec - timeEnd.tv_usec);
delta = WaitTime - delta;
console_printf(Console_Default, "Delta:%d\n", delta);
/* To avoid strange time warp when stopping emulation or using acceleration a lot */
if ((delta > 10000) || (delta < -10000))
{
delta = 0;
}
#endif
}

View File

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

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -16,24 +16,24 @@
/* Map a file in memory */ /* Map a file in memory */
void *LoadFilePtr(char * filename) void *LoadFilePtr(char *filename)
{ {
int fd; int fd;
void *RetPtr = NULL; void *RetPtr;
struct stat FileStat; struct stat FileStat;
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
fstat(fd, &FileStat); fstat(fd, &FileStat);
RetPtr = mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); RetPtr = mmap(NULL, FileStat.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd);
if ( RetPtr == MAP_FAILED ) close(fd);
{
RetPtr = NULL;
}
return RetPtr; if (RetPtr == MAP_FAILED)
{
RetPtr = NULL;
}
return RetPtr;
} }

512
src/os/unix/text.c Normal file
View File

@ -0,0 +1,512 @@
/*
* FbLib graphic library
*
* Created by Manoël TRAPIER.
* Copyright (c) 2003-2019 986-Studio. All rights reserved.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdarg.h>
#include <os_dependent.h>
#define DEFAULT_FONT "default_font.psf"
FBLibFont *defaultFont = NULL;
/* Function will fail, if no string terminator */
static int getNextWordLen(char *str)
{
int ret = 0, i;
/* Word delimiters */
char word_lim[] = { ' ', '\t', '\n', 0 };
while (1)
{
for (i = 0 ; word_lim[i] != 0 ; i++)
{
if (*str == word_lim[i])
{
return ret;
}
}
str++;
ret++;
}
}
void graphics_text_line(int x, int y, int w, int charw, uint32_t color, int valign, void *font, char *text)
{
uint32_t len = strlen(text);
switch (valign)
{
default:
case TEXT_VALIGN_LEFT:
graphics_draw_text(x, y, color, (const FBLibFont *)font, text);
break;
case TEXT_VALIGN_CENTER:
graphics_draw_text(x + ((w - len * charw) / 2), y, color, (const FBLibFont *)font, text);
break;
case TEXT_VALIGN_RIGHT:
graphics_draw_text(x + (w - (len * charw)), y, color, (const FBLibFont *)font, text);
break;
}
}
/* Currently halign is not honored, but valign is */
int graphics_text_ex(int x, int y, int w, int h,
void *font,
uint32_t bgcolor, uint32_t fgcolor,
char valign, char halign,
uint16_t options,
void *format, ...)
{
char string[1024];
char line[300];
int charWidth, charHeight;
int textPos = 0;
int wordLen = 0;
int nextWordLen = 0;
va_list va;
uint16_t curColPos = 0, curLinePos = 0;
uint16_t maxCharPerLine, maxTextLine;
FBLibFont *userFont = font;
if (defaultFont == NULL)
{
defaultFont = load_psf(DEFAULT_FONT);
}
if (font == NULL)
{
userFont = defaultFont;
}
/* Do some usefull calculation */
/* We use fixed size font */
graphics_get_text_size(&charWidth, &charHeight, userFont, "A");
maxCharPerLine = w / charWidth;
maxTextLine = h / charHeight;
/* Now convert to a useable string */
va_start(va, format);
vsnprintf(string, 1024, format, va);
va_end(va);
/* Fill rect with bg color */
graphics_drawFillrect(x, y, w, h, bgcolor);
/* Now fill as much as possible */
memset(line, 0, 300);
while (curLinePos < maxTextLine)
{
if (options & TEXT_OPT_WORDWRAP)
{
/* Do thoses check only one time per word, not per characters */
if (wordLen <= 0)
{
/* check if next word is too large for width */
nextWordLen = getNextWordLen(&string[textPos]);
//printf("\nNextword len = %d", nextWordLen);
if (nextWordLen <= maxCharPerLine)
{
if ((curColPos + nextWordLen) > maxCharPerLine)
{
/* Go next line... */
line[curColPos] = 0;
graphics_text_line(x, y + curLinePos * charHeight, w, charWidth, fgcolor, valign, userFont,
line);
curColPos = 0;
curLinePos++;
memset(line, 0, 300);
}
}
wordLen = nextWordLen;
}
/* Now when the word is too long for a line, it will be automatically wrapped to the next line */
}
if ((string[textPos] == '\n') || (string[textPos] == '\r'))
{
textPos++;
line[curColPos] = 0;
graphics_text_line(x, y + curLinePos * charHeight, w, charWidth, fgcolor, valign, userFont, line);
curColPos = 0;
curLinePos++;
memset(line, 0, 300);
}
else if (string[textPos] == 0)
{
line[curColPos] = 0;
graphics_text_line(x, y + curLinePos * charHeight, w, charWidth, fgcolor, valign, userFont, line);
goto exit;
}
else if (curColPos >= maxCharPerLine)
{
/* display the line */
line[curColPos] = 0;
graphics_text_line(x, y + curLinePos * charHeight, w, charWidth, fgcolor, valign, userFont, line);
/* skip until a "\n" (and exit is "\0" found)) */
if (options & TEXT_OPT_WORDWRAP)
{
curColPos = 0;
curLinePos++;
memset(line, 0, 300);
}
else
{
while (1)
{
if ((string[textPos] == '\r') || (string[textPos] == '\n'))
{
curColPos = 0;
curLinePos++;
memset(line, 0, 300);
break;
}
else if (string[textPos] == 0)
{
goto exit;
}
textPos++;
}
}
}
else
{
line[curColPos++] = string[textPos++];
}
if (options & TEXT_OPT_WORDWRAP)
{
wordLen--;
}
}
exit:
return 0;
}
void *fblib_loadfont(char *filename)
{
return (void *)load_psf(filename);
}
/* PSF management */
#define PSF1_MAGIC0 0x36
#define PSF1_MAGIC1 0x04
#define PSF1_MODE512 0x01
#define PSF1_MODEHASTAB 0x02
#define PSF1_MODEHASSEQ 0x04
#define PSF1_MAXMODE 0x05
#define PSF1_SEPARATOR 0xFFFF
#define PSF1_STARTSEQ 0xFFFE
struct psf1_header
{
unsigned char magic[2]; /* Magic number */
unsigned char mode; /* PSF font mode */
unsigned char charsize; /* Character size */
};
#define PSF2_MAGIC0 0x72
#define PSF2_MAGIC1 0xb5
#define PSF2_MAGIC2 0x4a
#define PSF2_MAGIC3 0x86
/* bits used in flags */
#define PSF2_HAS_UNICODE_TABLE 0x01
/* max version recognized so far */
#define PSF2_MAXVERSION 0
/* UTF8 separators */
#define PSF2_SEPARATOR 0xFF
#define PSF2_STARTSEQ 0xFE
struct psf2_header
{
unsigned char magic[4];
unsigned int version;
unsigned int headersize; /* offset of bitmaps in file */
unsigned int flags;
unsigned int length; /* number of glyphs */
unsigned int charsize; /* number of bytes for each character */
unsigned int height, width; /* max dimensions of glyphs */
/* charsize = height * ((width + 7) / 8) */
};
static FBLibFont *load_psf1(char *filename, FILE *fp)
{
struct psf1_header head;
struct FBLibFont *font;
fread(&head, sizeof(head), 1, fp);
if ((head.magic[0] != PSF1_MAGIC0) || (head.magic[1] != PSF1_MAGIC1))
{
return NULL;
}
font = (FBLibFont *)malloc(sizeof(FBLibFont));
if (font != NULL)
{
font->height = head.charsize;
font->index_mask = 0xFF;
}
return NULL;
}
void printbin(uint32_t val, uint8_t bitlen)
{
int i;
for (i = 0 ; i < bitlen ; i++)
{
if (val & (1 << (bitlen - 1)))
{
printf("*");
}
else
{
printf("_");
}
val <<= 1;
}
}
static FBLibFont *load_psf2(char *filename, FILE *fp)
{
struct psf2_header head;
struct FBLibFont *font, *ret = NULL;
uint32_t charWidth;
uint32_t i, j, k;
uint8_t *bitmap;
fread(&head, sizeof(head), 1, fp);
if ((head.magic[0] != PSF2_MAGIC0) || (head.magic[1] != PSF2_MAGIC1) ||
(head.magic[2] != PSF2_MAGIC2) || (head.magic[3] != PSF2_MAGIC3)
)
{
goto exit;
}
font = (FBLibFont *)malloc(sizeof(FBLibFont));
assert(head.width <= 32); /* For now, do not support font with width larger than 32 pixels */
if (font != NULL)
{
font->height = head.height;
bitmap = (uint8_t *)malloc(sizeof(uint8_t) * head.charsize * head.length);
font->index_mask = 0xFF;
font->offset = (int *)malloc(sizeof(int) * head.length);
font->index = (int *)malloc(sizeof(int) * head.length * 3);
font->content = (uint32_t *)malloc(sizeof(uint32_t) * head.length * head.height);
charWidth = ((head.width + 7) / 8);
assert(bitmap != NULL);
assert(font->offset != NULL);
assert(font->index != NULL);
assert(font->content != NULL);
fread(bitmap, sizeof(uint8_t), head.charsize * head.length, fp);
for (i = 0 ; i < head.length ; i++)
{
font->offset[i] = i * 3;
font->index[(i * 3) + 0] = head.width;
font->index[(i * 3) + 1] = i * head.height;
font->index[(i * 3) + 2] = 0;
for (j = 0 ; j < head.height ; j++)
{
font->content[(i * head.height) + j] = 0;
for (k = 0 ; k < charWidth ; k++)
{
font->content[(i * head.height) + j] |=
(bitmap[(i * head.charsize) + (j * charWidth) + k]) << 8 * (3 - k);
}
}
}
ret = font;
free(bitmap);
}
exit:
fclose(fp);
return ret;
}
FBLibFont *load_psf(char *filename)
{
FILE *fp;
uint8_t byte;
console_printf(Console_Default, "Loading font '%s'\n", filename);
fp = fopen(filename, "rb");
if (fp != NULL)
{
byte = fgetc(fp);
rewind(fp);
switch (byte)
{
default:
fclose(fp);
return NULL; // Unsuported format
case PSF1_MAGIC0:
return load_psf1(filename, fp);
case PSF2_MAGIC0:
return load_psf2(filename, fp);
}
}
return NULL;
}
/* Font rendering code based on BOGL by Ben Pfaff */
static int fblib_draw_glyph(const FBLibFont *font, uint8_t wc, uint32_t **bitmap)
{
int mask = font->index_mask;
int i;
for (;;)
{
for (i = font->offset[wc & mask] ; font->index[i] ; i += 3)
{
if ((font->index[i] & ~mask) == (wc & ~mask))
{
if (bitmap != NULL)
{
*bitmap = &font->content[font->index[i + 1]];
}
return font->index[i] & mask;
}
}
}
return 0;
}
void graphics_get_text_size(int *width, int *height,
const FBLibFont *font,
const char *text)
{
uint8_t *c = (uint8_t *)text;
uint8_t wc;
int k, n, w, h, mw;
if (defaultFont == NULL)
{
defaultFont = load_psf(DEFAULT_FONT);
}
if (font == NULL)
{
font = defaultFont;
}
n = strlen(text);
mw = h = w = 0;
for (k = 0 ; k < n ; k++)
{
wc = *(c++);
if (wc == '\n')
{
if (w > mw)
{
mw = 0;
}
h += font->height;
continue;
}
w += fblib_draw_glyph(font, wc, NULL);
}
if (width != NULL)
{
*width = (w > mw) ? w : mw;
}
if (height != NULL)
{
*height = (h == 0) ? font->height : h;
}
}
void graphics_draw_text(int x, int y,
uint32_t colour,
const FBLibFont *font,
const char *text)
{
int32_t h, w, k, n, cx, cy, dx, dy;
uint8_t *c = (uint8_t *)text;
uint8_t wc;
if (defaultFont == NULL)
{
defaultFont = load_psf(DEFAULT_FONT);
}
if (font == NULL)
{
font = defaultFont;
}
n = strlen(text);
h = font->height;
dx = dy = 0;
for (k = 0 ; k < n ; k++)
{
uint32_t *glyph = NULL;
wc = *(c++);
if (wc == '\n')
{
dy += h;
dx = 0;
continue;
}
w = fblib_draw_glyph(font, wc, &glyph);
if (glyph == NULL)
{
continue;
}
for (cy = 0 ; cy < h ; cy++)
{
uint32_t g = *glyph++;
for (cx = 0 ; cx < w ; cx++)
{
if (g & 0x80000000)
{
graphics_drawpixel(x + dx + cx, y + dy + cy, colour);
}
g <<= 1;
}
}
dx += w;
}
}
/* End of PSF */

View File

@ -1,14 +1,9 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2016 986-Studio. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
add_library(oslib loadfile.c graphics.c sound.c io.c) add_library(oslib loadfile.c graphics.c sound.c io.c)
target_link_libraries(oslib glfw ${OPENGL_glu_LIBRARY}) target_link_libraries(oslib glfw ${OPENGL_glu_LIBRARY})

View File

@ -1,14 +1,9 @@
/* /*
* Graphic Manager - The TI-NESulator Project * Graphic Manager - The peTI-NESulator Project
* os/macos/graphics.c * os/macos/graphics.c
* *
* Created by Manoel TRAPIER on 08/05/08. * Created by Manoël Trapier on 08/05/08.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include <stdlib.h> #include <stdlib.h>
@ -18,8 +13,13 @@
#include <os_dependent.h> #include <os_dependent.h>
#define GLFW_INCLUDE_GLEXT
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <OpenGL/glext.h>
/* "Apple" fix */
#ifndef GL_TEXTURE_RECTANGLE
#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_EXT
#endif
#include <palette.h> #include <palette.h>
@ -27,26 +27,22 @@ typedef struct GLWindow_t GLWindow;
struct KeyArray struct KeyArray
{ {
unsigned char lastState; uint8_t lastState;
unsigned char curState; uint8_t curState;
unsigned char debounced; uint8_t debounced;
GLFWwindow* window; GLFWwindow* window;
}; };
struct GLWindow_t struct GLWindow_t
{ {
struct KeyArray keyArray[512]; struct KeyArray keyArray[512];
GLFWwindow* windows; GLFWwindow* windows;
unsigned char *videoMemory; uint8_t *videoMemory;
GLint videoTexture; GLint videoTexture;
int WIDTH; int WIDTH;
int HEIGHT; int HEIGHT;
}; };
#ifndef GL_TEXTURE_RECTANGLE_EXT
#define GL_TEXTURE_RECTANGLE_EXT GL_TEXTURE_RECTANGLE_NV
#endif
static int window_num = 0; static int window_num = 0;
void GLWindowInitEx(GLWindow *g, int w, int h) void GLWindowInitEx(GLWindow *g, int w, int h)
@ -63,10 +59,10 @@ void GLWindowInit(GLWindow *g)
void ShowScreen(GLWindow *g, int w, int h) void ShowScreen(GLWindow *g, int w, int h)
{ {
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, g->videoTexture); glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
// glTexSubImage2D is faster when not using a texture range // glTexSubImage2D is faster when not using a texture range
glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory); glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f);
@ -87,8 +83,8 @@ void ShowScreen(GLWindow *g, int w, int h)
void setupGL(GLWindow *g, int w, int h) void setupGL(GLWindow *g, int w, int h)
{ {
g->videoMemory = (unsigned char*)malloc(w*h*sizeof(unsigned int)); g->videoMemory = (uint8_t*)malloc(w*h*sizeof(uint32_t));
memset(g->videoMemory, 0,w*h*sizeof(unsigned int)); memset(g->videoMemory, 0,w*h*sizeof(uint32_t));
//Tell OpenGL how to convert from coordinates to pixel values //Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
@ -104,20 +100,20 @@ void setupGL(GLWindow *g, int w, int h)
glLoadIdentity(); glLoadIdentity();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_EXT); glEnable(GL_TEXTURE_RECTANGLE);
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, g->videoTexture); glBindTexture(GL_TEXTURE_RECTANGLE, g->videoTexture);
// glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_NV_EXT, 0, NULL); // glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_NV_EXT, 0, NULL);
// glTexParameteri(GL_TEXTURE_RECTANGLE_NV_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE); // glTexParameteri(GL_TEXTURE_RECTANGLE_NV_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE);
// glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); // glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, w, glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, w,
h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory); h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, g->videoMemory);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
@ -140,7 +136,7 @@ void restoreGL(GLWindow *g, int w, int h)
glLoadIdentity(); glLoadIdentity();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_EXT); glEnable(GL_TEXTURE_RECTANGLE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
@ -169,6 +165,10 @@ void sizeHandler(GLFWwindow* window,int xs,int ys)
glViewport(0, 0, xs, ys); glViewport(0, 0, xs, ys);
} }
static void error_callback(int error, const char* description)
{
puts(description);
}
void initDisplay(GLWindow *g) void initDisplay(GLWindow *g)
{ {
@ -178,14 +178,18 @@ void initDisplay(GLWindow *g)
/// Initialize GLFW /// Initialize GLFW
glfwInit(); glfwInit();
glfwSetErrorCallback(error_callback);
// Open screen OpenGL window // Open screen OpenGL window
if( !(g->windows=glfwCreateWindow( g->WIDTH, g->HEIGHT, "Main", NULL, NULL)) ) if( !(g->windows=glfwCreateWindow( g->WIDTH, g->HEIGHT, "Main", NULL, NULL)) )
{ {
glfwTerminate(); glfwTerminate();
fprintf(stderr, "Window creation error...\n"); fprintf(stderr, "Window creation error...\n");
return; abort();
} }
glfwSetWindowAspectRatio(g->windows, 4, 3);
glfwMakeContextCurrent(g->windows); glfwMakeContextCurrent(g->windows);
setupGL(g, g->WIDTH, g->HEIGHT); setupGL(g, g->WIDTH, g->HEIGHT);
@ -203,7 +207,7 @@ void drawPixel(GLWindow *gw, int x, int y, uint32_t colour)
{ {
uint8_t r,g,b,a; uint8_t r,g,b,a;
uint32_t offset = (y*gw->WIDTH*4)+4*x; uint32_t offset = (y*gw->WIDTH*4U)+4U*x;
if ((x < 0) || (x > gw->WIDTH) || (y < 0) || (y > gw->HEIGHT)) if ((x < 0) || (x > gw->WIDTH) || (y < 0) || (y > gw->HEIGHT))
return; return;
@ -293,7 +297,7 @@ void drawLine(GLWindow *g, int x0, int y0, int x1, int y1, uint32_t colour)
} }
} }
exit: exit:
return; return;
} }
@ -401,7 +405,7 @@ int graphics_init()
return 0; return 0;
} }
static unsigned long getColour(long color) static uint32_t getColour(long color)
{ {
Palette *pal = &basicPalette[color]; Palette *pal = &basicPalette[color];
uint8_t r, g, b, a; uint8_t r, g, b, a;

View File

@ -1,14 +1,9 @@
/* /*
* IO Manager - The TI-NESulator Project * IO Manager - The peTI-NESulator Project
* os/macos/graphics.c * os/macos/graphics.c
* *
* Created by Manoël Trapier on 04/01/09. * Created by Manoël Trapier on 04/01/09.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -40,11 +35,10 @@ int console_vprintf(const ConsoleLevel level, const char *format, va_list ap)
int console_printf(const ConsoleLevel level, const char *format, ...) int console_printf(const ConsoleLevel level, const char *format, ...)
{ {
int ret = 0;
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
ret = console_vprintf(level, format, ap); console_vprintf(level, format, ap);
va_end(ap); va_end(ap);
return 0; return 0;
@ -56,6 +50,8 @@ int console_printf_d(const char *format, ...)
va_start(ap, format); va_start(ap, format);
console_vprintf (Console_Debug, format, ap); console_vprintf (Console_Debug, format, ap);
va_end(ap);
return 0; return 0;
} }

View File

@ -1,12 +1,12 @@
/* /*
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <sys/mman.h> //#include <sys/mman.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -19,14 +19,15 @@
void *LoadFilePtr(char * filename) void *LoadFilePtr(char * filename)
{ {
int fd; int fd;
void *RetPtr = NULL; void *RetPtr;
struct stat FileStat; struct stat FileStat;
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
fstat(fd, &FileStat); fstat(fd, &FileStat);
RetPtr = mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); RetPtr = NULL;
// RetPtr = mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd); close(fd);

View File

@ -1,94 +1,99 @@
/* /*
* Paddle manager - The TI-NESulator Project * Paddle manager - The peTI-NESulator Project
* paddle.c * paddle.c
* *
* Created by Manoel TRAPIER. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include <stdio.h>
#include <os_dependent.h> #include <os_dependent.h>
#include "paddle.h" #include "paddle.h"
void InitPaddle(Paddle *pdl) void InitPaddle(Paddle *pdl)
{ {
pdl->Bit = 1; pdl->bitPos = 1;
pdl->LastWrite = 0; pdl->strobeState = 0;
} }
void WritePaddle(Paddle *pdl, unsigned char val) void WritePaddle(Paddle *pdl, uint8_t val)
{ {
if ( ( pdl->LastWrite == 1 ) && ( val == 0 ) ) pdl->strobeState = val & 1;
InitPaddle(pdl); pdl->bitPos = 1;
pdl->LastWrite = val;
} }
unsigned char ReadPaddle(Paddle *pdl) uint8_t ReadPaddle(Paddle *pdl)
{ {
switch(pdl->Bit++) uint8_t ret = 0x40;
{
case 1: switch (pdl->bitPos)
if ( getKeyStatus('O') ) {
return 0x41; case 1:
break; if (getKeyStatus('O'))
{
ret = 0x41;
}
break;
case 2: case 2:
if ( getKeyStatus('P') ) if (getKeyStatus('P'))
return 0x41; {
break; ret = 0x41;
}
break;
case 3: case 3:
if ( getKeyStatus('I') ) if (getKeyStatus('I'))
return 0x41; {
break; ret = 0x41;
}
break;
case 4: case 4:
if ( getKeyStatus('U') ) if (getKeyStatus('U'))
return 0x41; {
break; ret = 0x41;
}
break;
case 5: case 5:
if ( getKeyStatus('W') ) if (getKeyStatus('W'))
return 0x41; {
break; ret = 0x41;
}
break;
case 6: case 6:
if ( getKeyStatus('S') ) if (getKeyStatus('S'))
return 0x41; {
break; ret = 0x41;
}
break;
case 7: case 7:
if ( getKeyStatus('A') ) if (getKeyStatus('A'))
return 0x41; {
break; ret = 0x41;
}
break;
case 8: case 8:
if ( getKeyStatus('D') ) if (getKeyStatus('D'))
return 0x41; {
break; ret = 0x41;
}
break;
case 20: default:
return 0x40; ret = 0x41;
break; }
case 24: if ((pdl->strobeState == 0) && (pdl->bitPos <= 9))
pdl->Bit = 1; {
return 0x40; pdl->bitPos++;
}
default: return ret;
return 0x40;
break;
}
return 0x40;
} }

View File

@ -1,13 +1,10 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2016 986-Studio. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
file(GLOB plugins_list plugins/*.c) file(GLOB plugins_list plugins/*.c)

View File

@ -1,14 +1,9 @@
/* /*
* Plugins manager - The TI-NESulator Project * Plugins manager - The peTI-NESulator Project
* plugins.c * plugins.c
* *
* Created by Manoel TRAPIER on 02/04/07. * Created by Manoël Trapier on 02/04/07.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -20,9 +15,9 @@
#include <plugins/manager.h> #include <plugins/manager.h>
typedef struct Plugin_ typedef struct Plugin_
{ {
char *name; char *name;
PluginInit init; PluginInit init;
PluginDeinit deinit; PluginDeinit deinit;
@ -30,12 +25,12 @@ typedef struct Plugin_
typedef struct KeyHandler_ typedef struct KeyHandler_
{ {
byte key; uint8_t key;
PluginKeypress func; PluginKeypress func;
struct KeyHandler_ *next; struct KeyHandler_ *next;
} KeyHandler; } KeyHandler;
KeyHandler *keyHandlersList = NULL; KeyHandler *keyHandlersList = NULL;
@ -47,10 +42,11 @@ void plugin_list()
Plugin *ptr = &(Plugins[0]); Plugin *ptr = &(Plugins[0]);
int i = 1; int i = 1;
console_printf(Console_Default, "Available plugins:\n"); console_printf(Console_Default, "Available plugins:\n");
while(ptr->name != NULL) while (ptr->name != NULL)
{ {
console_printf(Console_Default, "%d - %s\n", i, ptr->name); console_printf(Console_Default, "%d - %s\n", i, ptr->name);
ptr++; i++; ptr++;
i++;
} }
} }
@ -58,17 +54,19 @@ int plugin_load(int id)
{ {
Plugin *ptr = &(Plugins[0]); Plugin *ptr = &(Plugins[0]);
int i = id; int i = id;
console_printf(Console_Default, "%s(%d)", __func__, id); //console_printf(Console_Default, "%s(%d)", __func__, id);
for ( ; i > 1 && ptr->name != NULL; i -- ) for (; i > 1 && ptr->name != NULL ; i--)
{ {
console_printf(Console_Default, "%d - %s\n", i, ptr->name); //console_printf(Console_Default, "%d - %s\n", i, ptr->name);
ptr ++; ptr++;
} }
if (ptr == NULL) if (ptr == NULL)
{
return -1; return -1;
}
return ptr->init(); return ptr->init();
} }
@ -76,69 +74,76 @@ int plugin_load(int id)
int plugin_unload(int id) int plugin_unload(int id)
{ {
Plugin *ptr = &(Plugins[0]); Plugin *ptr = &(Plugins[0]);
for ( ; id == 0 && ptr != NULL; id -- ) for (; id == 0 && ptr != NULL ; id--)
ptr ++; {
ptr++;
}
if (ptr == NULL) if (ptr == NULL)
{
return -1; return -1;
}
return ptr->deinit(); return ptr->deinit();
} }
/* Available functions for plugins */ /* Available functions for plugins */
int plugin_install_keypressHandler(byte key, PluginKeypress func) int plugin_install_keypressHandler(uint8_t key, PluginKeypress func)
{ {
KeyHandler *ptr; KeyHandler *ptr;
if (keyHandlersList == NULL) if (keyHandlersList == NULL)
{ {
keyHandlersList = (KeyHandler*) malloc(sizeof(KeyHandler)); keyHandlersList = (KeyHandler *)malloc(sizeof(KeyHandler));
keyHandlersList->key = key; keyHandlersList->key = key;
keyHandlersList->func = func; keyHandlersList->func = func;
keyHandlersList->next = NULL; keyHandlersList->next = NULL;
} }
else else
{ {
ptr = keyHandlersList; ptr = keyHandlersList;
while(ptr->next != NULL) while (ptr->next != NULL)
{
ptr = ptr->next; ptr = ptr->next;
}
ptr->next = (KeyHandler*) malloc(sizeof(KeyHandler));
ptr->next = (KeyHandler *)malloc(sizeof(KeyHandler));
ptr = ptr->next; ptr = ptr->next;
ptr->key = key; ptr->key = key;
ptr->func = func; ptr->func = func;
ptr->next = NULL; ptr->next = NULL;
} }
return 0; return 0;
} }
int plugin_remove_keypressHandler(byte key, PluginKeypress func) int plugin_remove_keypressHandler(uint8_t key, PluginKeypress func)
{ /* actually do nothing, we cant remove plugin online */ { /* actually do nothing, we cant remove plugin online */
return 0; return 0;
} }
/* Available functions outside of plugins */ /* Available functions outside of plugins */
int plugin_keypress(byte key) int plugin_keypress()
{ {
KeyHandler *ptr = keyHandlersList; KeyHandler *ptr = keyHandlersList;
while(ptr != NULL) while (ptr != NULL)
{ {
if (ptr->key == key) if (getKeyStatus(ptr->key))
{ {
console_printf(Console_Default, "Keyrrr [%d].....\n", ptr->key);
ptr->func(); ptr->func();
} }
ptr = ptr->next; ptr = ptr->next;
} }
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,9 @@
/* /*
* Code Breaker plugin - The TI-NESulator Project * Code Breaker plugin - The peTI-NESulator Project
* gamegenie.h * gamegenie.h
* *
* Created by Manoel Trapier. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */

View File

@ -1,14 +1,9 @@
/* /*
* Plugin Manager plugint list - The TI-NESulator Project * Plugin Manager plugint list - The peTI-NESulator Project
* plugins_list.h * plugins_list.h
* *
* Created by Manoel Trapier. * Created by Manoël Trapier.
* Copyright (c) 2003-2016 986-Studio. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
@ -17,8 +12,8 @@
#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

@ -1,14 +1,9 @@
# #
# TI-NES CMake # peTI-NESulator CMake
# #
# Created by Manoel TRAPIER. # Created by Manoël Trapier.
# Copyright (c) 2003-2008 986Corp. All rights reserved. # Copyright (c) 2002-2019 986-Studio.
# #
# $LastChangedDate$
# $Author$
# $HeadURL$
# $Revision$
file(GLOB ppu_debug_list debug/*.c) file(GLOB ppu_debug_list debug/*.c)
if (COVERALLS) if (COVERALLS)

View File

@ -1,53 +1,24 @@
/* /*
* PPU Debug utilities - The TI-NESulator Project * PPU Debug utilities - The peTI-NESulator Project
* ppu.debug.c * ppu.debug.c
* *
* Created by Manoel Trapier. * Created by Manoël Trapier.
* Copyright 2003-2008 986 Corp. All rights reserved. * Copyright (c) 2002-2019 986-Studio.
*
* $LastChangedDate$
* $Author$
* $HeadURL$
* $Revision$
* *
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#if 0 #if 0
/* Allegro includes */
#ifdef __APPLE__
#define USE_CONSOLE
#include <Allegro/allegro.h>
#else
#define USE_CONSOLE
#include <allegro.h>
#endif
#define __TINES_PPU_INTERNAL__
#include <ppu/ppu.h>
#include <ppu/ppu.memory.h>
#include <ppu/ppu.debug.h>
#include <types.h>
extern BITMAP *Buffer;
extern unsigned short ppu_spritePatternTable;
extern short PPU_Reg_S;
void DebugColor() void DebugColor()
{ {
#ifdef TO_MAKE #ifdef TO_MAKE
static unsigned short x = 128; static uint16_t x = 128;
static unsigned short y = 128; static uint16_t y = 128;
unsigned char OldDisplayPalette = ppu.DisplayPalette; uint8_t OldDisplayPalette = ppu.DisplayPalette;
byte keyb; uint8_t keyb;
unsigned int i; uint32_t i;
unsigned long Color; uint32_t Color;
NOBLIT = 1; NOBLIT = 1;
@ -125,7 +96,7 @@ void DebugColor()
void DebugSprites() void DebugSprites()
{ {
#ifdef TO_MAKE #ifdef TO_MAKE
byte keyb; uint8_t keyb;
static int SelSprite = 0; static int SelSprite = 0;
PPUSprite sprite; PPUSprite sprite;
NOBLIT = 1; NOBLIT = 1;
@ -213,10 +184,10 @@ void DebugSprites()
#define PPU_Rd(addr) ppu_readMemory((addr>>8)&0xFF, addr&0xFF) #define PPU_Rd(addr) ppu_readMemory((addr>>8)&0xFF, addr&0xFF)
void ppu_dumpOneNameTable(unsigned short nametable, int xd, int yd) void ppu_dumpOneNameTable(uint16_t nametable, int xd, int yd)
{ {
byte x,y, x1, y1, Color; uint8_t x,y, x1, y1, Color;
unsigned short TileID; uint16_t TileID;
for (x = 0; x < 32; x++) for (x = 0; x < 32; x++)
for (y = 0; y < 30; y++) for (y = 0; y < 30; y++)
@ -238,35 +209,35 @@ void ppu_dumpOneNameTable(unsigned short nametable, int xd, int yd)
} }
} }
void ppu_dumpOneAttributeTable(unsigned short nametable, int xd, int yd) void ppu_dumpOneAttributeTable(uint16_t nametable, int xd, int yd)
{ {
int x, x1, y1, Color, AttrByte; int x, x1, y1, Color, Attruint8_t;
for (x = 0; x < 0x40; x++) for (x = 0; x < 0x40; x++)
{ {
AttrByte = PPU_Rd(nametable + 0x23C0 + x); Attruint8_t = PPU_Rd(nametable + 0x23C0 + x);
x1 = x % 8; x1 = x % 8;
y1 = x / 8; y1 = x / 8;
Color = AttrByte & 0x3; // Pattern 1; Color = Attruint8_t & 0x3; // Pattern 1;
// Color = PPU_Rd(0x3F00 + (Color * 4) + 1); // Color = PPU_Rd(0x3F00 + (Color * 4) + 1);
rectfill(Buffer,xd+(x1*32),yd+(y1*32),xd+15+(x1*32),yd+15+(y1*32),Color); rectfill(Buffer,xd+(x1*32),yd+(y1*32),xd+15+(x1*32),yd+15+(y1*32),Color);
textprintf_ex(Buffer, font, 4+xd+(x1*32), 4+yd+(y1*32), ~Color, Color, "%X", Color); textprintf_ex(Buffer, font, 4+xd+(x1*32), 4+yd+(y1*32), ~Color, Color, "%X", Color);
Color = (AttrByte>>2) & 0x3; // Pattern 2; Color = (Attruint8_t>>2) & 0x3; // Pattern 2;
// Color = PPU_Rd(0x3F00 + (Color * 4) + 1); // Color = PPU_Rd(0x3F00 + (Color * 4) + 1);
rectfill(Buffer,16+xd+(x1*32),yd+(y1*32),16+xd+15+(x1*32),yd+15+(y1*32),Color); rectfill(Buffer,16+xd+(x1*32),yd+(y1*32),16+xd+15+(x1*32),yd+15+(y1*32),Color);
textprintf_ex(Buffer, font, 4+xd+(x1*32)+16, 4+yd+(y1*32), ~Color, Color, "%X", Color); textprintf_ex(Buffer, font, 4+xd+(x1*32)+16, 4+yd+(y1*32), ~Color, Color, "%X", Color);
Color = (AttrByte>>4) & 0x3; // Pattern 3; Color = (Attruint8_t>>4) & 0x3; // Pattern 3;
// Color = PPU_Rd(0x3F00 + (Color * 4) + 1); // Color = PPU_Rd(0x3F00 + (Color * 4) + 1);
rectfill(Buffer,xd+(x1*32),16+yd+(y1*32),xd+15+(x1*32),16+yd+15+(y1*32),Color); rectfill(Buffer,xd+(x1*32),16+yd+(y1*32),xd+15+(x1*32),16+yd+15+(y1*32),Color);
textprintf_ex(Buffer, font, 4+xd+(x1*32), 4+yd+(y1*32)+16, ~Color, Color, "%X", Color); textprintf_ex(Buffer, font, 4+xd+(x1*32), 4+yd+(y1*32)+16, ~Color, Color, "%X", Color);
Color = (AttrByte>>6) & 0x3; // Pattern 4; Color = (Attruint8_t>>6) & 0x3; // Pattern 4;
// Color = PPU_Rd(0x3F00 + (Color * 4) + 1); // Color = PPU_Rd(0x3F00 + (Color * 4) + 1);
rectfill(Buffer,16+xd+(x1*32),16+yd+(y1*32),16+xd+15+(x1*32),16+yd+15+(y1*32),Color); rectfill(Buffer,16+xd+(x1*32),16+yd+(y1*32),16+xd+15+(x1*32),16+yd+15+(y1*32),Color);
@ -278,7 +249,7 @@ void ppu_dumpOneAttributeTable(unsigned short nametable, int xd, int yd)
} }
} }
extern byte *ppu_mem_nameTables; extern uint8_t *ppu_mem_nameTables;
extern int ppu_screenMode; extern int ppu_screenMode;
void ppu_dumpNameTable(int xd, int yd) void ppu_dumpNameTable(int xd, int yd)
{ {
@ -368,4 +339,5 @@ 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
#endif

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More