-corrected small mistake in input code

-made the libretro port work a bit smoother
This commit is contained in:
FIX94 2018-03-06 20:51:40 +01:00
parent c6af2eeee3
commit e5004bf4a7
No known key found for this signature in database
GPG Key ID: CE39016A19D8EADA
7 changed files with 69 additions and 12 deletions

14
apu.c
View File

@ -134,7 +134,8 @@ void apuInitBufs()
//convert to 32bit int for calcs later
hpVal = (int32_t)((rc / (rc + dt))*32768.0);
#endif
apuBufSize = apuFrequency/60*2;
//keep exactly 1 frame buffer
apuBufSize = 70224/16*2;
#if AUDIO_FLOAT
apuBufSizeBytes = apuBufSize*sizeof(float);
apuOutBuf = (float*)malloc(apuBufSizeBytes);
@ -213,6 +214,7 @@ bool apuCycle()
{
if(curBufPos == apuBufSize)
{
#ifndef __LIBRETRO__
int updateRes = audioUpdate();
if(updateRes == 0)
{
@ -233,6 +235,7 @@ bool apuCycle()
else
emuSkipVsync = false;
}
#endif
curBufPos = 0;
}
uint8_t p1OutLeft = lastP1OutLeft, p2OutLeft = lastP2OutLeft,
@ -375,6 +378,15 @@ bool apuCycle()
return true;
}
#ifdef __LIBRETRO__
void audioFrameEnd(int samples);
void apuFrameEnd()
{
audioFrameEnd(curBufPos>>1);
curBufPos = 0;
}
#endif
void doEnvelopeLogic(envelope_t *env)
{
if(env->divider == 0)

View File

@ -20,10 +20,14 @@ uint8_t modeSelect = 3;
void inputInit()
{
memset(inValReads, 0, 8);
modeSelect = 3;
}
void inputClear()
{
memset(inValReads, 0, 8);
}
void inputSet8(uint16_t addr, uint8_t in)
{
(void)addr;

View File

@ -18,6 +18,7 @@
#define BUTTON_RIGHT 7
void inputInit();
void inputClear();
uint8_t inputGet8(uint16_t addr);
void inputSet8(uint16_t addr, uint8_t in);
bool inputAny();

View File

@ -2,6 +2,7 @@
TARGET_NAME := fixgb
DEBUG = 0
AUDIO_FLOAT = 0
DO_LTO = 0
ifeq ($(platform),)
platform = unix
@ -216,7 +217,7 @@ else ifeq ($(platform), ngc)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-gcc-ar$(EXE_EXT)
PLATFORM_DEFINES += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float
PLATFORM_DEFINES += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
STATIC_LINKING = 1
@ -226,17 +227,18 @@ else ifeq ($(platform), wii)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-gcc-ar$(EXE_EXT)
PLATFORM_DEFINES += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float
PLATFORM_DEFINES += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
STATIC_LINKING = 1
DO_LTO = 1
# Nintendo WiiU
else ifeq ($(platform), wiiu)
TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-gcc-ar$(EXE_EXT)
PLATFORM_DEFINES += -DGEKKO -DWIIU -DHW_RVL -mwup -mcpu=750 -meabi -mhard-float
PLATFORM_DEFINES += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
STATIC_LINKING = 1
@ -295,6 +297,11 @@ ifeq ($(AUDIO_FLOAT),1)
CFLAGS += -DAUDIO_FLOAT=1
endif
ifeq ($(DO_LTO),1)
CFLAGS += -flto
CXXFLAGS += -flto
endif
ifeq ($(DEBUG), 1)
CFLAGS += -O0 -g

View File

@ -7,5 +7,5 @@ categories = "Emulator"
systemname = "Game Boy/Game Boy Color"
license = "MIT"
permissions = ""
display_version = "Alpha v0.4"
display_version = "Alpha v0.8.1"
supports_no_game = "false"

View File

@ -28,7 +28,7 @@ int gbEmuLoadGame(const char *filename);
void gbEmuMainLoop(void);
void gbEmuDeinit(void);
extern uint8_t inValReads[8];
extern uint32_t textureImage[0x9A00];
extern uint32_t textureImage[0x5A00];
extern volatile bool emuRenderFrame;
extern const char *VERSION_STRING;
@ -69,7 +69,7 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
info->geometry.max_width = VISIBLE_DOTS;
info->geometry.max_height = VISIBLE_LINES;
info->geometry.aspect_ratio = 0.0f;
info->timing.fps = 60;
info->timing.fps = 4194304.0 / 70224.0;
info->timing.sample_rate = (float)apuGetFrequency();
}
@ -218,6 +218,7 @@ size_t retro_get_memory_size(unsigned id)
int audioUpdate()
{
#if 0
#if AUDIO_FLOAT
static int16_t buffer[512 * 2];
float* buffer_in = (float*)apuGetBuf();
@ -248,10 +249,28 @@ int audioUpdate()
samples -= 512;
}
audio_batch_cb(buffer_in, samples);
#endif
#endif
return 1;
}
void apuFrameEnd();
void audioFrameEnd(int samples)
{
#if AUDIO_FLOAT
#else
uint16_t* buffer_in = (uint16_t*)apuGetBuf();
while (samples > 512)
{
audio_batch_cb(buffer_in, 512);
buffer_in += 1024;
samples -= 512;
}
if(samples)
audio_batch_cb(buffer_in, samples);
#endif
}
void retro_run()
{
input_poll_cb();
@ -265,10 +284,10 @@ void retro_run()
inValReads[BUTTON_UP] = !!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP);
inValReads[BUTTON_DOWN] = !!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN);
while(!emuRenderFrame)
gbEmuMainLoop();
gbEmuMainLoop();
video_cb(textureImage, VISIBLE_DOTS, VISIBLE_LINES, VISIBLE_DOTS * sizeof(uint32_t));
apuFrameEnd();
emuRenderFrame = false;
}

18
main.c
View File

@ -32,7 +32,7 @@
#define DEBUG_KEY 0
#define DEBUG_LOAD_INFO 1
const char *VERSION_STRING = "fixGB Alpha v0.8";
const char *VERSION_STRING = "fixGB Alpha v0.8.1";
static char window_title[256];
static char window_title_pause[256];
@ -107,8 +107,10 @@ static DWORD emuMainTotalElapsed = 0;
static uint32_t linesToDraw = VISIBLE_LINES;
static const uint32_t visibleImg = VISIBLE_DOTS*VISIBLE_LINES*4;
static uint8_t scaleFactor = 3;
#ifndef __LIBRETRO__
static uint32_t mainLoopRuns;
static uint16_t mainLoopPos;
#endif
//from input.c
extern uint8_t inValReads[8];
@ -182,6 +184,7 @@ int main(int argc, char** argv)
ppuInit();
apuInit();
inputInit();
inputClear();
if(emuGBROM[0x134] != 0)
{
if(gbCgbMode)
@ -252,6 +255,7 @@ int main(int argc, char** argv)
}
free(tmpROM);
apuInitBufs();
inputClear();
//does all inits for us
memStartGBS();
gbEmuGBSPlayback = true;
@ -278,10 +282,10 @@ int main(int argc, char** argv)
emuMainFrameStart = GetTickCount();
#endif
#endif
#ifndef __LIBRETRO__
//do one scanline per idle loop
mainLoopRuns = 70224;
mainLoopPos = mainLoopRuns;
#ifndef __LIBRETRO__
glutInit(&argc, argv);
glutInitWindowSize(VISIBLE_DOTS*scaleFactor, linesToDraw*scaleFactor);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
@ -510,6 +514,7 @@ void gbEmuMainLoop(void)
//do one scanline loop
do
{
#ifndef __LIBRETRO__
if((!emuSkipVsync && emuRenderFrame) || gbPause)
{
#if (WINDOWS_BUILD && DEBUG_MAIN_CALLS)
@ -527,6 +532,11 @@ void gbEmuMainLoop(void)
audioSleep();
return;
}
#else
//run APU first to make sure its synced
if(!(mainClock&15))
apuCycle();
#endif
//channel timer updates
apuClockTimers();
//run possible DMA next
@ -569,8 +579,12 @@ void gbEmuMainLoop(void)
}
mainClock++;
}
#ifndef __LIBRETRO__
while(mainLoopPos--);
mainLoopPos = mainLoopRuns;
#else
while(emuRenderFrame == false) ;
#endif
//update console stats if requested
#if (WINDOWS_BUILD && DEBUG_MAIN_CALLS)
emuMainTimesCalled++;