Update glfw, and make TI-NESulator great again (and add Mapper #30 support)

This commit is contained in:
Godzil 2018-01-30 16:12:53 +00:00
parent d26bd788cf
commit 6e179a5866
12 changed files with 126 additions and 21 deletions

View File

@ -9,7 +9,9 @@
# $HeadURL$
# $Revision$
cmake_minimum_required (VERSION 3.6)
cmake_minimum_required (VERSION 2.8)
project (TINES)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
@ -18,7 +20,6 @@ add_subdirectory("external/glfw")
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
project (TINES)
link_libraries(${OPENGL_gl_LIBRARY})
add_subdirectory (src)

2
external/glfw vendored

@ -1 +1 @@
Subproject commit 0f488ac2865d766155344fb356acb40007421ec8
Subproject commit 525ad7bfb8884b7cf497bc8e6ebf743df0dada8c

View File

@ -80,4 +80,5 @@ endif (TARGET_TI68k)
find_library(PTHREADLIB pthread)
add_executable(tines main.c paddle.c NESCarts.c)
target_link_libraries(tines apu corecpu mappermanager memorymanager pluginsmanager ppu oslib ${PTHREADLIB})
target_compile_options(tines PRIVATE -pthread)
target_link_libraries(tines apu corecpu mappermanager memorymanager pluginsmanager ppu oslib) #${PTHREADLIB}

View File

@ -29,6 +29,7 @@
#include <NESCarts.h>
#include <os_dependent.h>
#include <mappers/manager.h>
#include <sys/mman.h>
void DumpCartProperties(FILE *out, NesCart * cart)
{
@ -57,7 +58,7 @@ int LoadCart(const char *filename, NesCart * cart)
cart->File = (byte *)LoadFilePtr((char *)filename);
if ((cart->File == NULL) || ((int)cart->File == -1))
if ((cart->File == NULL) || (cart->File == MAP_FAILED))
return -1;
sprintf(buffer, "%c%c%c%c", 0x4E, 0x45, 0x53, 0x1A);

View File

@ -150,7 +150,7 @@ void SaveSaveRam(char *name)
FILE *fp;
int i;
char fname[512];
int ret;
strcpy(fname, name);
strcat(fname, ".svt");
if ((fp = fopen(fname, "wb")))
@ -158,7 +158,7 @@ void SaveSaveRam(char *name)
console_printf(Console_Default, "Saving savestate '%s'\n", fname);
for( i = 0x60; i < 0x80; i++)
{
ret = fwrite(get_page_ptr(i), 1, 0x100, fp);
fwrite(get_page_ptr(i), 1, 0x100, fp);
}
fclose(fp);
@ -170,7 +170,7 @@ void LoadSaveRam(char *name)
FILE *fp;
int i;
char fname[512];
int ret;
strcpy(fname, name);
strcat(fname, ".svt");
if ((fp = fopen(fname, "rb")))
@ -178,7 +178,7 @@ void LoadSaveRam(char *name)
console_printf(Console_Default, "Loading savestate '%s'\n", fname);
for( i = 0x60; i < 0x80; i++)
{
ret = fread(get_page_ptr(i), 1, 0x0100, fp);
fread(get_page_ptr(i), 1, 0x0100, fp);
}
fclose(fp);
@ -189,7 +189,6 @@ void LoadSaveRam(char *name)
void LoadPalette(char *filename, Palette *pal)
{
FILE *fp;
int ret;
unsigned char r, v, b, i;
console_printf(Console_Default, "%s: try to load pallette file '%s'", __func__, filename);
if ((fp = fopen(filename, "rb")) != NULL)
@ -198,9 +197,9 @@ void LoadPalette(char *filename, Palette *pal)
for (i = 0; i < 64; i++)
{
ret = fread(&r, 1, 1, fp);
ret = fread(&v, 1, 1, fp);
ret = fread(&b, 1, 1, fp);
fread(&r, 1, 1, fp);
fread(&v, 1, 1, fp);
fread(&b, 1, 1, fp);
/* r = (r * 64) / 255;
v = (v * 64) / 255;

View File

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

View File

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

View File

@ -18,6 +18,8 @@
#include "mappers/unrom.h"
#include "mappers/cnrom.h"
#include "mappers/unrom512.h"
#include "mappers/iremh3001.h"
#include "mappers/mmc1.h"
@ -32,7 +34,9 @@ Mapper Mappers[] = {
{ 1 , "MMC1", mmc1_InitMapper, norom_MapperIRQ, mmc1_MapperDump },
{ 4 , "MMC3", mmc3_InitMapper, mmc3_MapperIRQ, mmc3_MapperDump },
{ 10, "MMC4", mmc4_InitMapper, norom_MapperIRQ, mmc4_MapperDump },
{ 10, "MMC4", mmc4_InitMapper, norom_MapperIRQ, mmc4_MapperDump },
{ 30, "UNROM512", unrom512_InitMapper, norom_MapperIRQ, unrom512_MapperDump },
{ 65, "Irem H3001", iremh3001_InitMapper, iremh3001_MapperIRQ, iremh3001_MapperDump },

View File

@ -19,7 +19,11 @@
#include <os_dependent.h>
#include <GLFW/glfw3.h>
#ifdef __MACOSX__
#include <OpenGL/glext.h>
#else
#include <GL/glext.h>
#endif
#include <palette.h>
@ -169,6 +173,10 @@ void sizeHandler(GLFWwindow* window,int xs,int ys)
glViewport(0, 0, xs, ys);
}
static void error_callback(int error, const char* description)
{
puts(description);
}
void initDisplay(GLWindow *g)
{
@ -178,12 +186,14 @@ void initDisplay(GLWindow *g)
/// Initialize GLFW
glfwInit();
glfwSetErrorCallback(error_callback);
// Open screen OpenGL window
if( !(g->windows=glfwCreateWindow( g->WIDTH, g->HEIGHT, "Main", NULL, NULL)) )
{
glfwTerminate();
fprintf(stderr, "Window creation error...\n");
return;
abort();
}
glfwMakeContextCurrent(g->windows);
@ -213,6 +223,7 @@ void drawPixel(GLWindow *gw, int x, int y, uint32_t colour)
r = (colour >> 16) & 0xFF;
a = (colour >> 24) & 0xFF;
gw->videoMemory[offset + 0] = a;
gw->videoMemory[offset + 1] = r;
gw->videoMemory[offset + 2] = g;

View File

@ -47,7 +47,7 @@ int console_printf(const ConsoleLevel level, const char *format, ...)
ret = console_vprintf(level, format, ap);
va_end(ap);
return 0;
return ret;
}
int console_printf_d(const char *format, ...)

View File

@ -14,14 +14,14 @@
#include <stdio.h>
#include <stdlib.h>
#if 0
/* Allegro includes */
#ifdef __APPLE__
#define USE_CONSOLE
#include <Allegro/allegro.h>
#else
#define USE_CONSOLE
#include <allegro.h>
//#include <allegro.h>
#endif
#define __TINES_PPU_INTERNAL__
@ -367,3 +367,4 @@ void ppu_dumpPalette(int x, int y)
rectfill(Buffer, x + 91 + (i % 4) * 20, y + 21 +(i / 4) * 20, x + 91 + (i % 4) * 20 + 20, y + 21 +(i / 4) * 20 + 20, ppu_readMemory(0x3F, i+0x10));
}
}
#endif

View File

@ -36,8 +36,8 @@
extern int VBLANK_TIME;
volatile extern int frame;
volatile extern unsigned long IPS, FPS;
extern volatile int frame;
extern volatile unsigned long IPS, FPS;
extern unsigned long ColorPalette[9 * 63];
extern short IRQScanHit;