Skip to content

Commit

Permalink
Merge pull request "GCW0 port, numerous fixes" from gameblabla/merge
Browse files Browse the repository at this point in the history
GCW0 port, numerous fixes
  • Loading branch information
gameblabla authored Dec 11, 2019
2 parents eb71d43 + 3140a6a commit 0842d8d
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 111 deletions.
69 changes: 69 additions & 0 deletions Makefile.gcw0
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
PRGNAME = ngpcemu
CC = /opt/gcw0-toolchain-static/bin/mipsel-linux-gcc
CXX = /opt/gcw0-toolchain-static/bin/mipsel-linux-g++

#### Configuration

# Possible values : retrostone, rs97, rs90
PORT = gcw0
# Possible values : alsa, oss, portaudio
SOUND_ENGINE = sdl
# Possible values : generic, rs90
MENU = generic
# Possible values : 0, YES, APPLY
PROFILE = 0

#### End of Configuration

GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"

INCLUDES = -Imednafen/include -I./ -I./mednafen -I./mednafen/hw_cpu/z80-fuse -I./mednafen/ngp -I./mednafen/ngp/TLCS-900h -I./mednafen/sound
INCLUDES += -Ishell/headers -Ishell/video/$(PORT) -Ishell/audio -Ishell/scalers -Ishell/input/sdl -Ishell/fonts -Ishell/menu/$(MENU)

DEFINES = -DLSB_FIRST -DWANT_16BPP -DFRONTEND_SUPPORTS_RGB565 -DINLINE="inline" -DWANT_STEREO_SOUND
DEFINES += -DSIZEOF_DOUBLE=8 $(WARNINGS) -DMEDNAFEN_VERSION=\"0.9.31\" -DPACKAGE=\"mednafen\" -DMEDNAFEN_VERSION_NUMERIC=931 -DPSS_STYLE=1 -DMPC_FIXED_POINT -DSTDC_HEADERS -D__STDC_LIMIT_MACROS -D_LOW_ACCURACY_
DEFINES += -DGIT_VERSION=\"$(GIT_VERSION)\" -DNOAVERAGING -DNDEBUG -DGCW0 -DIPU_SCALE

#-fdata-sections -ffunction-sections
CFLAGS = -Ofast -funroll-loops -mno-fp-exceptions -mno-check-zero-division -mframe-header-opt -fsingle-precision-constant -fno-common -mips32r2 -fno-PIC -mno-abicalls -flto
CFLAGS += $(INCLUDES) $(DEFINES)
ifeq ($(PROFILE), YES)
CFLAGS += -fprofile-generate=/media/data/local/home/
else ifeq ($(PROFILE), APPLY)
CFLAGS += -fprofile-use
endif

CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++03
LDFLAGS =-nodefaultlibs -lc -lgcc -lSDL -lasound -no-pie -Wl,--as-needed -Wl,--gc-sections -flto -s

ifeq ($(PROFILE), YES)
LDFLAGS += -lgcov
endif

ifeq ($(SOUND_ENGINE), alsa)
LDFLAGS += -lasound
endif
ifeq ($(SOUND_ENGINE), portaudio)
LDFLAGS += -lportaudio
endif

# Files to be compiled
SRCDIR = ./mednafen ./mednafen/hw_cpu/z80-fuse ./mednafen/ngp ./mednafen/ngp/TLCS-900h ./mednafen/sound
SRCDIR += ./shell/input/sdl ./shell/audio/$(SOUND_ENGINE) ./shell/emu ./shell/scalers ./shell/video/$(PORT) ./shell/menu/$(MENU) ./shell/fonts

VPATH = $(SRCDIR)
SRC_C = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.c))
SRC_CPP = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.cpp))
OBJ_C = $(notdir $(patsubst %.c, %.o, $(SRC_C)))
OBJ_CPP = $(notdir $(patsubst %.cpp, %.o, $(SRC_CPP)))
OBJS = $(OBJ_C) $(OBJ_CPP)

# Rules to make executable
$(PRGNAME): $(OBJS)
$(CC) $(CFLAGS) -std=gnu99 -o $(PRGNAME) $^ $(LDFLAGS)

$(OBJ_CPP) : %.o : %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

clean:
rm -f $(PRGNAME)$(EXESUFFIX) *.o *.gcda
2 changes: 1 addition & 1 deletion mednafen/ngp/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void do_flash_read(uint8_t *flashdata)

void flash_read(void)
{
FlashFileHeader header;
FlashFileHeader header = {0, 0, 0};
uint8_t* flashdata;

//Initialise the internal flash configuration
Expand Down
3 changes: 2 additions & 1 deletion shell/audio/alsa/sound_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ void Audio_Close()
{
if (handle)
{
snd_pcm_drain(handle);
snd_pcm_drop(handle);
snd_pcm_close(handle);
snd_config_update_free_global();
}
}
6 changes: 5 additions & 1 deletion shell/audio/sdl/sound_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,9 @@ void Audio_Close()
SDL_PauseAudio(1);
SDL_CloseAudio();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
buffer = NULL;
if (buffer)
{
free(buffer);
buffer = NULL;
}
}
20 changes: 7 additions & 13 deletions shell/emu/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,24 @@ void NGP_CPUSaveState(uint_fast8_t load, FILE* fp)
if (load == 1)
{
fread(&z80_runtime, sizeof(uint8_t), sizeof(z80_runtime), fp);
fread(&CPUExRAM, sizeof(uint8_t), 16384, fp);
fread(&CPUExRAM, sizeof(uint8_t), sizeof(CPUExRAM), fp);
fread(&FlashStatusEnable, sizeof(uint8_t), sizeof(FlashStatusEnable), fp);
fread(&pc, sizeof(uint8_t), sizeof(pc), fp);
fread(&sr, sizeof(uint8_t), sizeof(sr), fp);
fread(&f_dash, sizeof(uint8_t), sizeof(f_dash), fp);
fread(&gpr, sizeof(uint8_t), sizeof(gpr), fp);
fread(&gprBank[0], sizeof(uint8_t), sizeof(gprBank[0]), fp);
fread(&gprBank[1], sizeof(uint8_t), sizeof(gprBank[1]), fp);
fread(&gprBank[2], sizeof(uint8_t), sizeof(gprBank[2]), fp);
fread(&gprBank[3], sizeof(uint8_t), sizeof(gprBank[3]), fp);
fread(&gprBank, sizeof(uint8_t), sizeof(gprBank), fp);
}
else
{
fwrite(&z80_runtime, sizeof(uint8_t), sizeof(z80_runtime), fp);
fwrite(&CPUExRAM, sizeof(uint8_t), 16384, fp);
fwrite(&CPUExRAM, sizeof(uint8_t), sizeof(CPUExRAM), fp);
fwrite(&FlashStatusEnable, sizeof(uint8_t), sizeof(FlashStatusEnable), fp);
fwrite(&pc, sizeof(uint8_t), sizeof(pc), fp);
fwrite(&sr, sizeof(uint8_t), sizeof(sr), fp);
fwrite(&f_dash, sizeof(uint8_t), sizeof(f_dash), fp);
fwrite(&gpr, sizeof(uint8_t), sizeof(gpr), fp);
fwrite(&gprBank[0], sizeof(uint8_t), sizeof(gprBank[0]), fp);
fwrite(&gprBank[1], sizeof(uint8_t), sizeof(gprBank[1]), fp);
fwrite(&gprBank[2], sizeof(uint8_t), sizeof(gprBank[2]), fp);
fwrite(&gprBank[3], sizeof(uint8_t), sizeof(gprBank[3]), fp);
fwrite(&gprBank, sizeof(uint8_t), sizeof(gprBank), fp);
}
}

Expand Down Expand Up @@ -363,12 +357,12 @@ int main(int argc, char* argv[])
}
snprintf(GameName_emu, sizeof(GameName_emu), "%s", basename(argv[1]));

Init_Configuration();

Init_Video();

Audio_Init();

Init_Configuration();

Load_Game(argv[1]);

while(!done)
Expand All @@ -385,7 +379,7 @@ int main(int argc, char* argv[])
}

}
Close_Video();
Audio_Close();
Close_Video();
MDFNI_CloseGame();
}
10 changes: 10 additions & 0 deletions shell/headers/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@
#if defined(BITTBOY)
#define SOUND_OUTPUT_FREQUENCY 22050
#define SOUND_SAMPLES_SIZE 1024
#define DEADZONE_AXIS 8192
#elif defined(RS97)
#define SOUND_OUTPUT_FREQUENCY 22050
#define SOUND_SAMPLES_SIZE 1024
#define DEADZONE_AXIS 8192
#elif defined(ARCADEMINI)
#define SOUND_OUTPUT_FREQUENCY 22050
#define SOUND_SAMPLES_SIZE 1024
#define DEADZONE_AXIS 8192
#elif defined(RETROSTONE_1)
#define SOUND_OUTPUT_FREQUENCY 48000
#define SOUND_SAMPLES_SIZE 2048
#define DEADZONE_AXIS 8192
#elif defined(RETROSTONE_2)
#define SOUND_OUTPUT_FREQUENCY 48000
#define SOUND_SAMPLES_SIZE 2048
#define DEADZONE_AXIS 8192
#elif defined(GCW0)
#define SOUND_OUTPUT_FREQUENCY 44100
#define SOUND_SAMPLES_SIZE 1024
#define DEADZONE_AXIS 8192
#else
#define SOUND_OUTPUT_FREQUENCY 48000
#define SOUND_SAMPLES_SIZE 2048
#define DEADZONE_AXIS 8192
#endif

#endif
27 changes: 23 additions & 4 deletions shell/input/sdl/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
#include <stdio.h>

#include "menu.h"
#include "shared.h"
#include "config.h"

int32_t axis_joypad[2] = {0, 0};

uint8_t update_input(void)
{
SDL_Event event;
Expand All @@ -29,29 +32,45 @@ uint8_t update_input(void)
break;
}
break;
case SDL_KEYUP:
switch(event.key.keysym.sym)
{
case SDLK_HOME:
emulator_state = 1;
break;
default:
break;
}
break;
case SDL_JOYAXISMOTION:
if (event.jaxis.axis == 0) axis_joypad[0] = event.jaxis.value;
else if (event.jaxis.axis == 1) axis_joypad[1] = event.jaxis.value;
break;
}
}

if (axis_joypad[0] > DEADZONE_AXIS)

// UP -> DPAD UP
if (keys[option.config_buttons[0]])
if (keys[option.config_buttons[0]] == SDL_PRESSED || axis_joypad[1] < -DEADZONE_AXIS)
{
button |= 0x01;
}

// DOWN -> DPAD DOWN
if (keys[option.config_buttons[1]])
if (keys[option.config_buttons[1]] == SDL_PRESSED || axis_joypad[1] > DEADZONE_AXIS)
{
button |= 0x02;
}

// LEFT -> DPAD LEFT
if (keys[option.config_buttons[2] ] == SDL_PRESSED)
if (keys[option.config_buttons[2] ] == SDL_PRESSED || axis_joypad[0] < -DEADZONE_AXIS)
{
button |= 0x04;
}

// RIGHT -> DPAD RIGHT
if (keys[option.config_buttons[3] ] == SDL_PRESSED)
if (keys[option.config_buttons[3] ] == SDL_PRESSED || axis_joypad[0] > DEADZONE_AXIS)
{
button |= 0x08;
}
Expand Down
17 changes: 11 additions & 6 deletions shell/menu/generic/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ static uint32_t controls_chosen = 0;
char EEPROM_filepath[512];

static uint8_t save_slot = 0;

#ifdef IPU_SCALE
static const int8_t upscalers_available = 1
#else
static const int8_t upscalers_available = 2
#endif
#ifdef SCALE2X_UPSCALER
+1
#endif
Expand Down Expand Up @@ -326,13 +331,13 @@ void Menu()
switch(option.fullscreen)
{
case 0:
print_string("Scaling : Native", TextRed, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Stretched", TextRed, 0, 5, 105, backbuffer->pixels);
break;
case 1:
print_string("Scaling : Stretched", TextRed, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Keep scaled", TextRed, 0, 5, 105, backbuffer->pixels);
break;
case 2:
print_string("Scaling : Keep scaled", TextRed, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Native", TextRed, 0, 5, 105, backbuffer->pixels);
break;
case 3:
print_string("Scaling : EPX/Scale2x", TextRed, 0, 5, 105, backbuffer->pixels);
Expand All @@ -344,13 +349,13 @@ void Menu()
switch(option.fullscreen)
{
case 0:
print_string("Scaling : Native", TextWhite, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Stretched", TextWhite, 0, 5, 105, backbuffer->pixels);
break;
case 1:
print_string("Scaling : Stretched", TextWhite, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Keep scaled", TextWhite, 0, 5, 105, backbuffer->pixels);
break;
case 2:
print_string("Scaling : Keep scaled", TextWhite, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Native", TextWhite, 0, 5, 105, backbuffer->pixels);
break;
case 3:
print_string("Scaling : EPX/Scale2x", TextWhite, 0, 5, 105, backbuffer->pixels);
Expand Down
12 changes: 6 additions & 6 deletions shell/menu/rs90/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ void Menu()
switch(option.fullscreen)
{
case 0:
print_string("Scaling : Native", TextRed, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Stretched", TextRed, 0, 5, 105, backbuffer->pixels);
break;
case 1:
print_string("Scaling : Stretched", TextRed, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Keep scaled", TextRed, 0, 5, 105, backbuffer->pixels);
break;
case 2:
print_string("Scaling : Keep scaled", TextRed, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Native", TextRed, 0, 5, 105, backbuffer->pixels);
break;
case 3:
print_string("Scaling : EPX/Scale2x", TextRed, 0, 5, 105, backbuffer->pixels);
Expand All @@ -343,13 +343,13 @@ void Menu()
switch(option.fullscreen)
{
case 0:
print_string("Scaling : Native", TextWhite, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Stretched", TextWhite, 0, 5, 105, backbuffer->pixels);
break;
case 1:
print_string("Scaling : Stretched", TextWhite, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Keep scaled", TextWhite, 0, 5, 105, backbuffer->pixels);
break;
case 2:
print_string("Scaling : Keep scaled", TextWhite, 0, 5, 105, backbuffer->pixels);
print_string("Scaling : Native", TextWhite, 0, 5, 105, backbuffer->pixels);
break;
case 3:
print_string("Scaling : EPX/Scale2x", TextWhite, 0, 5, 105, backbuffer->pixels);
Expand Down
Loading

0 comments on commit 0842d8d

Please sign in to comment.