Updated build

This commit is contained in:
Themaister 2010-06-27 15:46:23 +02:00
parent 13c503160f
commit f471b4a8da
4 changed files with 62 additions and 27 deletions

View File

@ -2,37 +2,42 @@ include config.mk
TARGET = ssnes TARGET = ssnes
SOURCE = ssnes.c OBJ = ssnes.o
LIBS = -lsamplerate -lsnes LIBS = -lsamplerate -lsnes
ifeq ($(BUILD_RSOUND), 1) ifeq ($(BUILD_RSOUND), 1)
SOURCE += rsound.c OBJ += rsound.o
LIBS += -lrsound LIBS += -lrsound
endif endif
ifeq ($(BUILD_OSS), 1) ifeq ($(BUILD_OSS), 1)
SOURCE += oss.c OBJ += oss.o
endif endif
ifeq ($(BUILD_ALSA), 1) ifeq ($(BUILD_ALSA), 1)
SOURCE += alsa.c OBJ += alsa.o
LIBS += -lasound LIBS += -lasound
endif endif
ifeq ($(BUILD_OPENGL), 1) ifeq ($(BUILD_OPENGL), 1)
SOURCE += gl.c OBJ += gl.o
LIBS += -lglfw LIBS += -lglfw
endif endif
ifeq ($(BUILD_FILTER), 1) ifeq ($(BUILD_FILTER), 1)
SOURCE += hqflt/hq.c OBJ += hqflt/hq.o
endif endif
CFLAGS = -Wall -O3 -march=native -std=c99 CFLAGS = -Wall -O3 -march=native -std=c99
OBJ = ssnes.o
all: $(TARGET)
all: ssnes: $(OBJ)
$(CC) $(CFLAGS) -o $(TARGET) $(SOURCE) $(LIBS) @$(CC) -o $@ $(OBJ) $(LIBS)
@echo "LD $@"
%.o: %.c config.h config.mk
@$(CC) $(CFLAGS) -c -o $@ $<
@echo "CC $<"
install: $(TARGET) install: $(TARGET)
install -m755 $(TARGET) $(PREFIX)/bin install -m755 $(TARGET) $(PREFIX)/bin
@ -43,3 +48,5 @@ uninstall: $(TARGET)
clean: clean:
rm -rf $(OBJ) rm -rf $(OBJ)
rm -rf $(TARGET) rm -rf $(TARGET)
.PHONY: all install uninstall clean

View File

@ -261,7 +261,7 @@ uint8_t lastLineDiffs[__PAST_LIBRARY_WIDTH];
#define RotatePattern(x) ((((x) & 0x777) << 1) | (((x) & 0x888) >> 3)) #define RotatePattern(x) ((((x) & 0x777) << 1) | (((x) & 0x888) >> 3))
void ProcessHQ2x(const pixel *in, pixel *out) { void ProcessHQ2x(const pixel * restrict in, pixel * restrict out) {
signed int y, x; signed int y, x;
unsigned int pattern, newpattern; unsigned int pattern, newpattern;
uint32_t pixels[9]; uint32_t pixels[9];
@ -377,7 +377,7 @@ void ProcessHQ2x(const pixel *in, pixel *out) {
} while (y >= 0); } while (y >= 0);
} }
void ProcessHQ4x(const pixel *in, pixel *out) { void ProcessHQ4x(const pixel * restrict in, pixel * restrict out) {
signed int y, x; signed int y, x;
unsigned int pattern, newpattern; unsigned int pattern, newpattern;
uint32_t pixels[9]; uint32_t pixels[9];

View File

@ -36,19 +36,19 @@ typedef uint16_t pixel;
* guard-bits and masking. * guard-bits and masking.
*/ */
static __inline__ uint32_t RGBUnpack(pixel i) { static inline uint32_t RGBUnpack(pixel i) {
uint32_t o = i; uint32_t o = i;
o = (o * 0x10001); o = (o * 0x10001);
o = o & 0x03E07C1F; o = o & 0x03E07C1F;
return o; return o;
} }
static __inline__ pixel RGBPack(uint32_t x) { static inline pixel RGBPack(uint32_t x) {
x &= 0x03E07C1F; x &= 0x03E07C1F;
x |= (x >> 16); x |= (x >> 16);
return x; return x;
} }
void ProcessHQ2x(const pixel *inbuffer, pixel *outbuffer); void ProcessHQ2x(const pixel * restrict inbuffer, pixel * restrict outbuffer);
void ProcessHQ4x(const pixel *inbuffer, pixel *outbuffer); void ProcessHQ4x(const pixel * restrict inbuffer, pixel * restrict outbuffer);
#endif /* __PAST_LIBRARY_H */ #endif /* __PAST_LIBRARY_H */

52
ssnes.c
View File

@ -150,6 +150,27 @@ static void uninit_video_input(void)
driver.input->free(driver.input_data); driver.input->free(driver.input_data);
} }
// Temporary hack. Needs to do some color space switching for some unknown reason. Worked in 0.064 without hack at least.
#define USE_HACK 0
static inline void process_frame (uint16_t * restrict out, const uint16_t * restrict in, unsigned width, unsigned height)
{
for ( int y = 0; y < height; y++ )
{
const uint16_t *src = in + y * 1024;
uint16_t *dst = out + y * width;
#if USE_HACK
for ( int x = 0; x < width; x++ )
{
uint16_t color = src[x];
*dst++ = ((color >> 10) & 0x1f) | (color & 0x3e0) | ((color & 0x1f) << 10);
}
#else
memcpy(dst, src, width * sizeof(uint16_t));
#endif
}
}
static void video_frame(const uint16_t *data, unsigned width, unsigned height) static void video_frame(const uint16_t *data, unsigned width, unsigned height)
{ {
if ( !video_active ) if ( !video_active )
@ -159,17 +180,10 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height)
uint16_t outputHQ2x[width * height * 2 * 2]; uint16_t outputHQ2x[width * height * 2 * 2];
#elif VIDEO_FILTER == FILTER_HQ4X #elif VIDEO_FILTER == FILTER_HQ4X
uint16_t outputHQ4x[width * height * 4 * 4]; uint16_t outputHQ4x[width * height * 4 * 4];
#else
uint16_t output[width * height];
#endif #endif
uint16_t output[width * height];
for ( int y = 0; y < height; y++ ) process_frame(output, data, width, height);
{
const uint16_t *src = data + y * 1024;
uint16_t *dst = output + y * width;
memcpy(dst, src, width * sizeof(uint16_t));
}
#if VIDEO_FILTER == FILTER_NONE #if VIDEO_FILTER == FILTER_NONE
if ( !driver.video->frame(driver.video_data, output, width, height) ) if ( !driver.video->frame(driver.video_data, output, width, height) )
@ -278,13 +292,13 @@ int main(int argc, char *argv[])
if ( rom_buf == NULL ) if ( rom_buf == NULL )
{ {
fprintf(stderr, "SSNES [ERROR] :: Couldn't allocate memory!\n"); fprintf(stderr, "SSNES [ERROR] :: Couldn't allocate memory!\n");
exit(1); goto error;
} }
if ( fread(rom_buf, 1, length, file) < length ) if ( fread(rom_buf, 1, length, file) < length )
{ {
fprintf(stderr, "SSNES [ERROR] :: Didn't read whole file.\n"); fprintf(stderr, "SSNES [ERROR] :: Didn't read whole file.\n");
exit(1); goto error;
} }
fclose(file); fclose(file);
@ -295,6 +309,14 @@ int main(int argc, char *argv[])
unsigned serial_size = snes_serialize_size(); unsigned serial_size = snes_serialize_size();
uint8_t *serial_data = malloc(serial_size); uint8_t *serial_data = malloc(serial_size);
if ( serial_size > (unsigned)length )
{
fprintf(stderr, "SSNES [ERROR] :: Length of save file does match size given by libsnes.\n");
fprintf(stderr, "\tserial_size = %u, length = %u\n", serial_size, (unsigned)length);
goto error;
}
snes_serialize(serial_data, serial_size); snes_serialize(serial_data, serial_size);
load_state(savefile_name, serial_data, serial_size); load_state(savefile_name, serial_data, serial_size);
@ -330,10 +352,16 @@ int main(int argc, char *argv[])
snes_unload_cartridge(); snes_unload_cartridge();
snes_term(); snes_term();
uninit_drivers(); uninit_drivers();
return 0; return 0;
error:
snes_unload_cartridge();
snes_term();
uninit_drivers();
return 1;
} }
static void write_state(const char* path, uint8_t* data, size_t size) static void write_state(const char* path, uint8_t* data, size_t size)