From 00f99074bf49f4d52d17a534dd3d4e451f4bbc59 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 23 Jul 2009 02:36:56 +0000 Subject: [PATCH] Added config file key bindings, general code cleanup --- Makefile | 6 +- src/log.cpp | 5 +- src/log.h | 2 - src/sdlemu_config.cpp | 2 +- src/settings.cpp | 68 +++++------- src/settings.h | 16 +-- src/sound.cpp | 69 ++++-------- src/stargem2.cpp | 56 ++++------ src/timing.cpp | 1 + src/timing.h | 22 +--- src/types.h | 30 ++---- src/v6809.h | 2 +- src/video.cpp | 238 +----------------------------------------- src/video.h | 26 ----- stargem2.cfg | 64 ++++-------- 15 files changed, 117 insertions(+), 490 deletions(-) diff --git a/Makefile b/Makefile index 52955a6..65dc220 100755 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # # by James L. Hammons # (C) 2005 Underground Software -# This software is licensed under the GPL v2 +# This software is licensed under the GPL v3 or later # ifeq "$(OSTYPE)" "msys" # Win32 @@ -42,8 +42,8 @@ CC = gcc LD = gcc TARGET = stargem2 -CFLAGS = -MMD -Wall -Wno-switch -Wno-uninitialized -O2 -D$(SYSTYPE) -fomit-frame-pointer `sdl-config --cflags` -CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -Wno-uninitialized -O2 -D$(SYSTYPE) \ +CFLAGS = -MMD -Wall -Wno-switch -Wno-uninitialized -Wno-unused -O2 -D$(SYSTYPE) -fomit-frame-pointer `sdl-config --cflags` +CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -Wno-uninitialized -Wno-unused -O2 -D$(SYSTYPE) \ -fomit-frame-pointer `sdl-config --cflags` \ -g # -DLOG_UNMAPPED_MEMORY_ACCESSES diff --git a/src/log.cpp b/src/log.cpp index 7c4e9bd..b5fcf4d 100755 --- a/src/log.cpp +++ b/src/log.cpp @@ -4,9 +4,12 @@ // by James L. Hammons // -#include "types.h" #include "log.h" +#include +#include +#include "types.h" + #define MAX_LOG_SIZE 10000000 // Maximum size of log file (10 MB) static FILE * log_stream = NULL; diff --git a/src/log.h b/src/log.h index 3367c34..0663051 100755 --- a/src/log.h +++ b/src/log.h @@ -5,8 +5,6 @@ #ifndef __LOG_H__ #define __LOG_H__ -#include -#include #include #ifdef __cplusplus diff --git a/src/sdlemu_config.cpp b/src/sdlemu_config.cpp index 5b063ea..d70db65 100755 --- a/src/sdlemu_config.cpp +++ b/src/sdlemu_config.cpp @@ -84,7 +84,7 @@ int sdlemu_init_config(const char *filename) fseek(f, 0, SEEK_SET); char *s = new char[len]; - fread(s, 1, len, f); + size_t unused = fread(s, 1, len, f); string str(s); const string delim = "\n\r"; // "\r" needed for Win32 compatibility... diff --git a/src/settings.cpp b/src/settings.cpp index 888c083..f1c2cc2 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -50,50 +50,30 @@ void LoadSettings(void) settings.renderType = sdlemu_getval_int("renderType", 0); settings.autoStateSaving = sdlemu_getval_bool("autoSaveState", true); - // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, * - settings.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP); - settings.p1KeyBindings[1] = sdlemu_getval_int("p1k_down", SDLK_DOWN); - settings.p1KeyBindings[2] = sdlemu_getval_int("p1k_left", SDLK_LEFT); - settings.p1KeyBindings[3] = sdlemu_getval_int("p1k_right", SDLK_RIGHT); - settings.p1KeyBindings[4] = sdlemu_getval_int("p1k_c", SDLK_z); - settings.p1KeyBindings[5] = sdlemu_getval_int("p1k_b", SDLK_x); - settings.p1KeyBindings[6] = sdlemu_getval_int("p1k_a", SDLK_c); - settings.p1KeyBindings[7] = sdlemu_getval_int("p1k_option", SDLK_QUOTE); - settings.p1KeyBindings[8] = sdlemu_getval_int("p1k_pause", SDLK_RETURN); - settings.p1KeyBindings[9] = sdlemu_getval_int("p1k_0", SDLK_KP0); - settings.p1KeyBindings[10] = sdlemu_getval_int("p1k_1", SDLK_KP1); - settings.p1KeyBindings[11] = sdlemu_getval_int("p1k_2", SDLK_KP2); - settings.p1KeyBindings[12] = sdlemu_getval_int("p1k_3", SDLK_KP3); - settings.p1KeyBindings[13] = sdlemu_getval_int("p1k_4", SDLK_KP4); - settings.p1KeyBindings[14] = sdlemu_getval_int("p1k_5", SDLK_KP5); - settings.p1KeyBindings[15] = sdlemu_getval_int("p1k_6", SDLK_KP6); - settings.p1KeyBindings[16] = sdlemu_getval_int("p1k_7", SDLK_KP7); - settings.p1KeyBindings[17] = sdlemu_getval_int("p1k_8", SDLK_KP8); - settings.p1KeyBindings[18] = sdlemu_getval_int("p1k_9", SDLK_KP9); - settings.p1KeyBindings[19] = sdlemu_getval_int("p1k_pound", SDLK_KP_DIVIDE); - settings.p1KeyBindings[20] = sdlemu_getval_int("p1k_star", SDLK_KP_MULTIPLY); - - settings.p2KeyBindings[0] = sdlemu_getval_int("p2k_up", SDLK_UP); - settings.p2KeyBindings[1] = sdlemu_getval_int("p2k_down", SDLK_DOWN); - settings.p2KeyBindings[2] = sdlemu_getval_int("p2k_left", SDLK_LEFT); - settings.p2KeyBindings[3] = sdlemu_getval_int("p2k_right", SDLK_RIGHT); - settings.p2KeyBindings[4] = sdlemu_getval_int("p2k_c", SDLK_z); - settings.p2KeyBindings[5] = sdlemu_getval_int("p2k_b", SDLK_x); - settings.p2KeyBindings[6] = sdlemu_getval_int("p2k_a", SDLK_c); - settings.p2KeyBindings[7] = sdlemu_getval_int("p2k_option", SDLK_QUOTE); - settings.p2KeyBindings[8] = sdlemu_getval_int("p2k_pause", SDLK_RETURN); - settings.p2KeyBindings[9] = sdlemu_getval_int("p2k_0", SDLK_KP0); - settings.p2KeyBindings[10] = sdlemu_getval_int("p2k_1", SDLK_KP1); - settings.p2KeyBindings[11] = sdlemu_getval_int("p2k_2", SDLK_KP2); - settings.p2KeyBindings[12] = sdlemu_getval_int("p2k_3", SDLK_KP3); - settings.p2KeyBindings[13] = sdlemu_getval_int("p2k_4", SDLK_KP4); - settings.p2KeyBindings[14] = sdlemu_getval_int("p2k_5", SDLK_KP5); - settings.p2KeyBindings[15] = sdlemu_getval_int("p2k_6", SDLK_KP6); - settings.p2KeyBindings[16] = sdlemu_getval_int("p2k_7", SDLK_KP7); - settings.p2KeyBindings[17] = sdlemu_getval_int("p2k_8", SDLK_KP8); - settings.p2KeyBindings[18] = sdlemu_getval_int("p2k_9", SDLK_KP9); - settings.p2KeyBindings[19] = sdlemu_getval_int("p2k_pound", SDLK_KP_DIVIDE); - settings.p2KeyBindings[20] = sdlemu_getval_int("p2k_star", SDLK_KP_MULTIPLY); + // Keybindings in order of fire, thrust, smartbomb, hyperspace, reverse, up, down, inviso, + // 1 player start, 2 player start, left coin, center coin, right coin, auto up, advance, + // high score reset, slam switch + settings.keyBindings[S_KEY_FIRE] = sdlemu_getval_int("k_fire", SDLK_SEMICOLON); + settings.keyBindings[S_KEY_THRUST] = sdlemu_getval_int("k_thrust", SDLK_l); + settings.keyBindings[S_KEY_SMARTBOMB] = sdlemu_getval_int("k_smartbomb", SDLK_SPACE); + settings.keyBindings[S_KEY_HYPERSPACE] = sdlemu_getval_int("k_hyperspace", SDLK_BACKSPACE); + settings.keyBindings[S_KEY_REVERSE] = sdlemu_getval_int("k_reverse", SDLK_RETURN); + settings.keyBindings[S_KEY_UP] = sdlemu_getval_int("k_up", SDLK_r); + settings.keyBindings[S_KEY_DOWN] = sdlemu_getval_int("k_down", SDLK_f); + settings.keyBindings[S_KEY_INVISO] = sdlemu_getval_int("k_inviso", SDLK_a); + settings.keyBindings[S_KEY_1P_START] = sdlemu_getval_int("k_1p_start", SDLK_1); + settings.keyBindings[S_KEY_2P_START] = sdlemu_getval_int("k_2p_start", SDLK_2); + settings.keyBindings[S_KEY_LEFT_COIN] = sdlemu_getval_int("k_left_coin", SDLK_3); + settings.keyBindings[S_KEY_CENTER_COIN] = sdlemu_getval_int("k_center_coin", SDLK_4); + settings.keyBindings[S_KEY_RIGHT_COIN] = sdlemu_getval_int("k_right_coin", SDLK_5); + settings.keyBindings[S_KEY_AUTO_UP] = sdlemu_getval_int("k_auto_up", SDLK_F1); + settings.keyBindings[S_KEY_ADVANCE] = sdlemu_getval_int("k_advance", SDLK_F2); + settings.keyBindings[S_KEY_HS_RESET] = sdlemu_getval_int("k_high_score_reset", SDLK_F3); + settings.keyBindings[S_KEY_SLAM_SWITCH] = sdlemu_getval_int("k_slam_switch", SDLK_F4); +// settings.keyBindings[17] = sdlemu_getval_int("k_8", SDLK_KP8); +// settings.keyBindings[18] = sdlemu_getval_int("k_9", SDLK_KP9); +// settings.keyBindings[19] = sdlemu_getval_int("k_pound", SDLK_KP_DIVIDE); +// settings.keyBindings[20] = sdlemu_getval_int("k_star", SDLK_KP_MULTIPLY); strcpy(settings.BIOSPath, sdlemu_getval_string("BIOSROM", "./ROMs/")); strcpy(settings.disksPath, sdlemu_getval_string("disks", "./disks/")); diff --git a/src/settings.h b/src/settings.h index 1fcca61..a768a75 100755 --- a/src/settings.h +++ b/src/settings.h @@ -14,6 +14,11 @@ #endif #include "types.h" +enum { S_KEY_FIRE = 0, S_KEY_THRUST, S_KEY_SMARTBOMB, S_KEY_HYPERSPACE, S_KEY_REVERSE, + S_KEY_UP, S_KEY_DOWN, S_KEY_INVISO, S_KEY_1P_START, S_KEY_2P_START, S_KEY_LEFT_COIN, + S_KEY_CENTER_COIN, S_KEY_RIGHT_COIN, S_KEY_AUTO_UP, S_KEY_ADVANCE, S_KEY_HS_RESET, + S_KEY_SLAM_SWITCH }; + // Settings struct struct Settings @@ -27,11 +32,12 @@ struct Settings uint32 frameSkip; uint32 renderType; bool autoStateSaving; // Auto-state loading/saving on entry/exit - - // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, * - uint16 p1KeyBindings[21]; - uint16 p2KeyBindings[21]; + // Keybindings in order of fire, thrust, smartbomb, hyperspace, reverse, up, down, inviso, + // 1 player start, 2 player start, left coin, center coin, right coin, auto up, advance, + // high score reset, slam switch + + uint16 keyBindings[21]; // Paths @@ -40,8 +46,6 @@ struct Settings char diskImagePath1[MAX_PATH]; char diskImagePath2[MAX_PATH]; char autoStatePath[MAX_PATH]; -// char CDBootPath[MAX_PATH]; -// char EEPROMPath[MAX_PATH]; }; // Render types diff --git a/src/sound.cpp b/src/sound.cpp index 2f75220..4191928 100755 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -12,6 +12,7 @@ // JLH 06/15/2006 Scrubbed all BYTE, WORD & DWORD references from the code // JLH 02/10/2009 Fixed sound IRQ callback so that CPU samples are taken at // cycle exact boundaries +// JLH 07/21/2009 Moved numeric constants into macros for sanity's sake // // Notes: // The sound CPU (6808) runs at 894,750 (3,579,000 / 4) Hz. @@ -30,12 +31,16 @@ //using namespace std; -#define AUDIO_SAMPLE_RATE 44100 +//#define AUDIO_SAMPLE_RATE 44100.0 +#define AUDIO_SAMPLE_RATE 48000.0 +#define CYCLES_TO_EXECUTE (M6808_CLOCK_SPEED_IN_HZ / AUDIO_SAMPLE_RATE) // Local variables -SDL_AudioSpec desired; -bool soundInitialized = false; +static SDL_AudioSpec desired; +static bool soundInitialized = false; +static uint32 cyclesToExecuteWholePart; +static double cyclesToExecuteFractionalPart; // Private function prototypes @@ -58,10 +63,16 @@ void SoundInit(void) if (SDL_OpenAudio(&desired, NULL) < 0) // NULL means SDL guarantees what we want { WriteLog("Sound: Failed to initialize SDL sound.\n"); -// exit(1); return; } + // Setup clock cycles & etc. + cyclesToExecuteWholePart = (uint32)CYCLES_TO_EXECUTE; + cyclesToExecuteFractionalPart = CYCLES_TO_EXECUTE - (double)cyclesToExecuteWholePart; +#if 0 +printf("Cycles to execute: %lf; cycles W: %u; cycles F: %lf\n", CYCLES_TO_EXECUTE, cyclesToExecuteWholePart, cyclesToExecuteFractionalPart); +#endif + SDL_PauseAudio(false); // Start playback! soundInitialized = true; WriteLog("Sound: Successfully initialized.\n"); @@ -80,15 +91,6 @@ void SoundDone(void) } } -/* -The way to determine the # of cycles for each sample is to take the CPU clock frequency -and divide by the sample rate. - -Like so: -double cycles = M6808_CLOCK_SPEED_IN_HZ / AUDIO_SAMPLE_RATE; -Then we need to separate out the fractional part from the integer part. -*/ - // // Sound card callback handler // @@ -98,54 +100,21 @@ void SDLSoundCallback(void * userdata, Uint8 * buffer, int length) extern uint8 sram[]; int cnt = 0; -#define CYCLE_EXACT_SOUND -#ifdef CYCLE_EXACT_SOUND static float overflow = 0.0; - static uint32 time = 20; -#endif + static uint32 time = cyclesToExecuteWholePart; while (cnt != length) { - // This is close, but not cycle exact (exact would be 20.289115646...) - -//Need to figure out how to get that fraction to execute... !!! FIX !!! [DONE] -/* -One way would be to use a fractional accumulator, then subtract 1 every -time it overflows. Like so: - -double overflow = 0; -uint32 time = 20; -while (!done) -{ - Execute6808(&soundCPU, time); - overflow += 0.289115646; - if (overflow > 1.0) - { - overflow -= 1.0; - time = 21; - } - else - time = 20; -} -*/ -#ifdef CYCLE_EXACT_SOUND Execute6808(&soundCPU, time); soundCPU.clock -= time; -#else - Execute6808(&soundCPU, 20); - soundCPU.clock -= 20; -#endif buffer[cnt++] = sram[0x0400]; // Fill the buffer with the PIA output value -#ifdef CYCLE_EXACT_SOUND - overflow += 0.289115646; // Fractional part of CPU cycles... + time = cyclesToExecuteWholePart; + overflow += cyclesToExecuteFractionalPart; if (overflow > 1.0) { overflow -= 1.0; - time = 21; + time++; } - else - time = 20; -#endif } } diff --git a/src/stargem2.cpp b/src/stargem2.cpp index 8ad9c36..d1b7431 100755 --- a/src/stargem2.cpp +++ b/src/stargem2.cpp @@ -447,43 +447,25 @@ static void FrameCallback(void) if (keys[SDLK_ESCAPE]) running = false; // ESC to exit... -//Convert this stuff to use the settings module... !!! FIX !!! - if (keys[SDLK_SEMICOLON]) - gram[0xC804] |= 0x01; // Fire (;) - if (keys[SDLK_l]) - gram[0xC804] |= 0x02; // Thrust (L) - if (keys[SDLK_SPACE]) - gram[0xC804] |= 0x04; // Smart Bomb (space) - if (keys[SDLK_BACKSPACE]) - gram[0xC804] |= 0x08; // Hyperspace (BkSp) - if (keys[SDLK_2]) - gram[0xC804] |= 0x10; // Two Player Start (2) - if (keys[SDLK_1]) - gram[0xC804] |= 0x20; // One Player Start (1) - if (keys[SDLK_RETURN]) - gram[0xC804] |= 0x40; // Reverse (Enter) - if (keys[SDLK_f]) - gram[0xC804] |= 0x80; // Down (F) - - if (keys[SDLK_r]) - gram[0xC806] |= 0x01; // Up (R) - if (keys[SDLK_a]) - gram[0xC806] |= 0x02; // Inviso (A) - - if (keys[SDLK_F1]) - gram[0xC80C] |= 0x01; // Auto up (F1) - if (keys[SDLK_F2]) - gram[0xC80C] |= 0x02; // Advance (F2) - if (keys[SDLK_5]) - gram[0xC80C] |= 0x04; // Right Coin (5) - if (keys[SDLK_F3]) - gram[0xC80C] |= 0x08; // High Score Reset (F3) - if (keys[SDLK_3]) - gram[0xC80C] |= 0x10; // Left Coin (3) - if (keys[SDLK_4]) - gram[0xC80C] |= 0x20; // Center Coin (4) - if (keys[SDLK_F4]) - gram[0xC80C] |= 0x40; // Slam Switch (F4) + if (keys[settings.keyBindings[S_KEY_FIRE]]) gram[0xC804] |= 0x01; + if (keys[settings.keyBindings[S_KEY_THRUST]]) gram[0xC804] |= 0x02; + if (keys[settings.keyBindings[S_KEY_SMARTBOMB]]) gram[0xC804] |= 0x04; + if (keys[settings.keyBindings[S_KEY_HYPERSPACE]]) gram[0xC804] |= 0x08; + if (keys[settings.keyBindings[S_KEY_2P_START]]) gram[0xC804] |= 0x10; + if (keys[settings.keyBindings[S_KEY_1P_START]]) gram[0xC804] |= 0x20; + if (keys[settings.keyBindings[S_KEY_REVERSE]]) gram[0xC804] |= 0x40; + if (keys[settings.keyBindings[S_KEY_DOWN]]) gram[0xC804] |= 0x80; + + if (keys[settings.keyBindings[S_KEY_UP]]) gram[0xC806] |= 0x01; + if (keys[settings.keyBindings[S_KEY_INVISO]]) gram[0xC806] |= 0x02; + + if (keys[settings.keyBindings[S_KEY_AUTO_UP]]) gram[0xC80C] |= 0x01; + if (keys[settings.keyBindings[S_KEY_ADVANCE]]) gram[0xC80C] |= 0x02; + if (keys[settings.keyBindings[S_KEY_RIGHT_COIN]]) gram[0xC80C] |= 0x04; + if (keys[settings.keyBindings[S_KEY_HS_RESET]]) gram[0xC80C] |= 0x08; + if (keys[settings.keyBindings[S_KEY_LEFT_COIN]]) gram[0xC80C] |= 0x10; + if (keys[settings.keyBindings[S_KEY_CENTER_COIN]]) gram[0xC80C] |= 0x20; + if (keys[settings.keyBindings[S_KEY_SLAM_SWITCH]]) gram[0xC80C] |= 0x40; if (keys[SDLK_F5]) // Sound CPU self-test (F5) soundCPU.cpuFlags |= V6808_ASSERT_LINE_NMI; diff --git a/src/timing.cpp b/src/timing.cpp index 331e342..ebca2bf 100755 --- a/src/timing.cpp +++ b/src/timing.cpp @@ -18,6 +18,7 @@ #include "timing.h" +#include "types.h" #include "log.h" #define EVENT_LIST_SIZE 512 diff --git a/src/timing.h b/src/timing.h index 28f906e..360ce31 100755 --- a/src/timing.h +++ b/src/timing.h @@ -8,33 +8,13 @@ #ifndef __TIMING_H__ #define __TIMING_H__ -#include "types.h" - -// Note that these are NTSC timings: - -//#define RISC_CYCLE_IN_USEC 0.03760684198 -//#define M68K_CYCLE_IN_USEC (RISC_CYCLE_IN_USEC * 2) -//#define HORIZ_PERIOD_IN_USEC 63.5555 -//#define M6502_CYCLE_IN_USEC 0.9765625 - -//#define MASTER_CLOCK (12000000) -//#define SOUND_CLOCK (3579000) -// MDRV_CPU_ADD("maincpu", M6809, MASTER_CLOCK/3/4) -// MDRV_CPU_PROGRAM_MAP(defender_map) -// MDRV_CPU_ADD("soundcpu", M6808, SOUND_CLOCK) -// MDRV_CPU_PROGRAM_MAP(defender_sound_map) - +// Even though it's driven at 4 MHz, internally it runs at 1/4 that speed #define M6808_CLOCK_SPEED_IN_HZ (3579000.0 / 4.0) #define M6809_CLOCK_SPEED_IN_HZ (1000000.0) -// Actually, it's 1.1176306230790722 usec -//#define M6808_CYCLE_IN_USEC (0.9765625) #define M6808_CYCLE_IN_USEC (1000000.0 / M6808_CLOCK_SPEEK_IN_HZ) #define M6809_CYCLE_IN_USEC (1000000.0 / M6809_CLOCK_SPEED_IN_HZ) -//#define USEC_TO_RISC_CYCLES(u) (uint32)(((u) / RISC_CYCLE_IN_USEC) + 0.5) -//#define USEC_TO_M68K_CYCLES(u) (uint32)(((u) / M68K_CYCLE_IN_USEC) + 0.5) -//#define USEC_TO_M6502_CYCLES(u) (uint32)(((u) / M6502_CYCLE_IN_USEC) + 0.5) #define USEC_TO_M6808_CYCLES(u) (uint32)(((u) / M6808_CYCLE_IN_USEC) + 0.5) #define USEC_TO_M6809_CYCLES(u) (uint32)(((u) / M6809_CYCLE_IN_USEC) + 0.5) diff --git a/src/types.h b/src/types.h index a1b9d09..faa8684 100755 --- a/src/types.h +++ b/src/types.h @@ -4,30 +4,22 @@ // // Why these aren't a part of the C/C++ standard is beyond me. It seems to me that // basic types where you know the width should be a no-brainer. +// I guess enough people were pissed off by it, so they included it finally. We +// still alias them because we don't like typing _t after our type identifiers. ;-) // #ifndef __TYPES_H__ #define __TYPES_H__ -// This is only good on certain intel 32-bit platforms... -// You may need to tweak to suit your specific platform. +#include -typedef unsigned char uint8; -typedef signed char int8; -typedef unsigned short uint16; -typedef signed short int16; -typedef unsigned uint32; -typedef signed int32; -typedef unsigned long long uint64; -typedef signed long long int64; - -typedef uint8 UINT8; -typedef int8 INT8; -typedef uint16 UINT16; -typedef int16 INT16; -typedef uint32 UINT32; -typedef int32 INT32; -typedef uint64 UINT64; -typedef int64 INT64; +typedef uint8_t uint8; +typedef int8_t int8; +typedef uint16_t uint16; +typedef int16_t int16; +typedef uint32_t uint32; +typedef int32_t int32; +typedef uint64_t uint64; +typedef int64_t int64; #endif // __TYPES_H__ diff --git a/src/v6809.h b/src/v6809.h index 4655ef5..9511654 100755 --- a/src/v6809.h +++ b/src/v6809.h @@ -3,7 +3,7 @@ // // by James L. Hammons // -// (c) 1997, 2004 Underground Software +// (C) 1997, 2004 Underground Software // #ifndef __V6809_H__ diff --git a/src/video.cpp b/src/video.cpp index 363896a..da960c8 100755 --- a/src/video.cpp +++ b/src/video.cpp @@ -152,6 +152,9 @@ WriteLog("\n");//*/ //needed? Dunno. Mebbe an SDL function instead? // memset(scrBuffer, 0x00, VIRTUAL_SCREEN_WIDTH * VIRTUAL_SCREEN_HEIGHT * sizeof(uint32)); + if (settings.fullscreen) + SDL_ShowCursor(SDL_DISABLE); + #ifdef TEST_ALPHA_BLENDING //Here's some code to test alpha blending... //Well whaddya know, it works. :-) @@ -184,172 +187,9 @@ void VideoDone(void) // SDL_JoystickClose(joystick); SDL_FreeSurface(surface); -// SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER); SDL_Quit(); } - - -#if 0 -/// - -#include "SDL.h" -#include // Why??? (for memset, etc... Lazy!) Dunno why, but this just strikes me as wrong... -#include -#include "sdlemu_opengl.h" -#include "types.h" -#include "log.h" -#include "settings.h" -#include "video.h" - -// External global variables - -SDL_Surface * surface, * mainSurface; -Uint32 mainSurfaceFlags; -uint8 * backbuffer; -SDL_Joystick * joystick; -uint8 color[16]; -uint32 palette[256]; - -// -// Prime SDL and create surfaces -// -bool InitVideo(void) -{ - // Set up SDL library - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) < 0) - { - WriteLog("Video: Could not initialize the SDL library: %s\n", SDL_GetError()); - return false; - } - - // Get proper info about the platform we're running on... - const SDL_VideoInfo * info = SDL_GetVideoInfo(); - - if (!info) - { - WriteLog("Video: SDL is unable to get the video info: %s\n", SDL_GetError()); - return false; - } - - if (1)//(vjs.useOpenGL) - { - mainSurfaceFlags = SDL_HWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF | SDL_OPENGL; - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - } - else - { - if (info->hw_available) - { - mainSurfaceFlags = SDL_HWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF; - WriteLog("Video: Hardware available...\n"); - } - - if (info->blit_hw) - { - mainSurfaceFlags |= SDL_HWACCEL; - WriteLog("Video: Hardware blit available...\n"); - } - } - -// if (vjs.fullscreen) -// mainSurfaceFlags |= SDL_FULLSCREEN; - - if (0)//(!vjs.useOpenGL) - mainSurface = SDL_SetVideoMode(VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT, 32, mainSurfaceFlags); - else - mainSurface = SDL_SetVideoMode(VIRTUAL_SCREEN_WIDTH * 2, VIRTUAL_SCREEN_HEIGHT * 2, 32, mainSurfaceFlags); - - if (mainSurface == NULL) - { - WriteLog("Video: SDL is unable to set the video mode: %s\n", SDL_GetError()); - return false; - } - - SDL_WM_SetCaption("StarGem2", "StarGem2"); - - // Create the primary SDL display (8 BPP, palettized) -// surface = SDL_CreateRGBSurface(SDL_SWSURFACE, VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT, -// 8, 0, 0, 0, 0); - // Create the primary SDL display (32 BPP) - surface = SDL_CreateRGBSurface(SDL_SWSURFACE, VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT, 32, -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF -#else - 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 -#endif - ); -/*WriteLog("Video: Created secondary surface with attributes:\n\n"); -WriteLog("\tWidth, height: %u x %u\n", surface->w, surface->h); -WriteLog("\t Pitch: %u\n", surface->pitch); -WriteLog("\t Palette: %08X\n", surface->format->palette); -WriteLog("\t BPP: %u\n", surface->format->BitsPerPixel); -WriteLog("\t BytesPP: %u\n", surface->format->BytesPerPixel); -WriteLog("\t RMask: %08X\n", surface->format->Rmask); -WriteLog("\t GMask: %08X\n", surface->format->Gmask); -WriteLog("\t BMask: %08X\n", surface->format->Bmask); -WriteLog("\t AMask: %08X\n", surface->format->Amask); -WriteLog("\n");//*/ - - if (surface == NULL) - { - WriteLog("Video: Could not create primary SDL surface: %s\n", SDL_GetError()); - return false; - } - - // Initialize Williams' palette (RGB coded as: 3 bits red, 3 bits green, 2 bits blue) - for(uint32 i=0; i<256; i++) -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - palette[i] = (((i & 0x01) * 33 + ((i & 0x02) >> 1) * 71 + ((i & 0x04) >> 2) * 151) << 24) - | ((((i & 0x08) >> 3) * 33 + ((i & 0x10) >> 4) * 71 + ((i & 0x20) >> 5) * 151) << 16) - | ((((i & 0x40) >> 6) * 71 + ((i & 0x80) >> 7) * 151) << 8) | 0xFF;//*/ -#else - palette[i] = ((i & 0x01) * 33 + ((i & 0x02) >> 1) * 71 + ((i & 0x04) >> 2) * 151) - | ((((i & 0x08) >> 3) * 33 + ((i & 0x10) >> 4) * 71 + ((i & 0x20) >> 5) * 151) << 8) - | ((((i & 0x40) >> 6) * 71 + ((i & 0x80) >> 7) * 151) << 16) | 0xFF000000;//*/ -#endif - -// if (vjs.useOpenGL) - if (1) -//Should make another setting here, for either linear or nearest (instead of just picking one) -//And we have! ;-) Not... ;-( -// sdlemu_init_opengl(surface, 1/*method*/, 2/*size*/, 0);//vjs.glFilter/*texture type (linear, nearest)*/); - sdlemu_init_opengl(surface, mainSurface, 1 /*method*/, - 0 /*vjs.glFilter /texture type (linear, nearest)*/, - 0 /* Automatic bpp selection based upon src */); - - // Initialize Joystick support under SDL -/* if (1)//(vjs.useJoystick) - { - if (SDL_NumJoysticks() <= 0) - { - vjs.useJoystick = false; - WriteLog("Video: No joystick(s) or joypad(s) detected on your system. Using keyboard...\n"); - } - else - { - if ((joystick = SDL_JoystickOpen(vjs.joyport)) == 0) - { - vjs.useJoystick = false; - WriteLog("Video: Unable to open a Joystick on port: %d\n", (int)vjs.joyport); - } - else - WriteLog("Video: Using: %s\n", SDL_JoystickName(vjs.joyport)); - } - }*/ - - // Set up the backbuffer - backbuffer = (uint8 *)malloc(320 * 240 * sizeof(uint8)); - memset(backbuffer, 0x00, VIRTUAL_SCREEN_WIDTH * VIRTUAL_SCREEN_HEIGHT * sizeof(uint8)); - - WriteLog("Video: Successfully initialized.\n"); - return true; -} - -#endif - - - // // Render the backbuffer to the primary screen surface // @@ -380,77 +220,7 @@ SDL_BlitSurface(someAlphaSurface, NULL, surface, &dstRect); } } -// -// Render the backbuffer to the primary screen surface -// -void RenderScreenBuffer2(void) -{ #if 0 -//WriteLog("Video: Blitting a %u x %u surface to the main surface...", surface->w, surface->h); - if (SDL_MUSTLOCK(surface)) - while (SDL_LockSurface(surface) < 0) - SDL_Delay(10); - -//This *does* ignore the screen's actual pitch... !!! FIX !!! - uint32 * screen = (uint32 *)surface->pixels; - for(int i=0; i<320*240; i++) - screen[i] = palette[color[scrBuffer[i]]]; -//WriteLog("[blitted backbuffer]..."); - - if (SDL_MUSTLOCK(surface)) - SDL_UnlockSurface(surface); -#endif - - if (settings.useOpenGL) - sdlemu_draw_texture(mainSurface, surface, 1/*1=GL_QUADS*/); - else - { - SDL_BlitSurface(surface, NULL, mainSurface, NULL); - SDL_Flip(mainSurface); - } -//WriteLog("done.\n"); -} - -/* -// -// Resize the main SDL screen & backbuffer -// -void ResizeScreen(uint32 width, uint32 height) -{ - char window_title[256]; - - SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 16, - 0x7C00, 0x03E0, 0x001F, 0); - - if (surface == NULL) - { - WriteLog("Video: Could not create primary SDL surface: %s", SDL_GetError()); - exit(1); - } - - if (vjs.useOpenGL) - // This seems to work well for resizing (i.e., changes in the pixel width)... - sdlemu_resize_texture(surface, mainSurface, vjs.glFilter); - else - { - mainSurface = SDL_SetVideoMode(width, height, 16, mainSurfaceFlags); - - if (mainSurface == NULL) - { - WriteLog("Video: SDL is unable to set the video mode: %s\n", SDL_GetError()); - exit(1); - } - } - - sWriteLog(window_title, "Virtual Jaguar (%i x %i)", (int)width, (int)height); - SDL_WM_SetCaption(window_title, window_title); - - // This seems to work well for resizing (i.e., changes in the pixel width)... -// if (vjs.useOpenGL) -// sdlemu_resize_texture(surface, mainSurface); -} - // // Fullscreen <-> window switching // @@ -473,4 +243,4 @@ void ToggleFullscreen(void) SDL_WM_SetCaption("Virtual Jaguar", "Virtual Jaguar"); } -*/ +#endif diff --git a/src/video.h b/src/video.h index 4a355f2..56f8e23 100755 --- a/src/video.h +++ b/src/video.h @@ -5,29 +5,6 @@ #ifndef __VIDEO_H__ #define __VIDEO_H__ - -#if 0 - -#define VIRTUAL_SCREEN_WIDTH 320 -#define VIRTUAL_SCREEN_HEIGHT 240 - -bool InitVideo(void); -void VideoDone(void); -void RenderBackbuffer(void); -void ResizeScreen(uint32 width, uint32 height); -uint32 GetSDLScreenPitch(void); -void ToggleFullscreen(void); -void RenderBackbuffer2(void); - -// Exported crap - -extern uint8 * backbuffer; -extern uint8 color[16]; -//extern uint32 palette[256]; - -#endif - - #include "SDL.h" // For SDL_Surface #include "types.h" // For uint32 @@ -37,9 +14,6 @@ extern uint8 color[16]; bool InitVideo(void); void VideoDone(void); void RenderScreenBuffer(void); -void RenderScreenBuffer2(void); -//void ResizeScreen(uint32 width, uint32 height); -//uint32 GetSDLScreenPitch(void); //void ToggleFullscreen(void); // Exported crap diff --git a/stargem2.cfg b/stargem2.cfg index 9b04a0d..53b7d02 100755 --- a/stargem2.cfg +++ b/stargem2.cfg @@ -26,7 +26,7 @@ glFilterType = 0 # Display options: 1 - fullscreen, 0 - windowed -fullscreen = 0 +fullscreen = 1 # Backend renderer (OpenGL dependent): 0 - regular, 1 - "TV" style @@ -50,50 +50,24 @@ useJoystick = 0 joyport = 0 -# Jaguar joypad key assignments +# Stargate key assignments # Note: It would be nicer to be able to have a single left side to store all this in... # E.g. p1keys = 34, 32, 22, etc. instead of what we have here... -p1k_up = 273 # SDLK_UP -p1k_down = 274 # SDLK_DOWN -p1k_left = 276 # SDLK_LEFT -p1k_right = 275 # SDLK_RIGHT -p1k_c = 122 # SDLK_z -p1k_b = 120 # SDLK_x -p1k_a = 99 # SDLK_c -p1k_option = 39 # SDLK_QUOTE -p1k_pause = 13 # SDLK_RETURN -p1k_0 = 256 # SDLK_KP0 -p1k_1 = 257 # SDLK_KP1 -p1k_2 = 258 # SDLK_KP2 -p1k_3 = 259 # SDLK_KP3 -p1k_4 = 260 # SDLK_KP4 -p1k_5 = 261 # SDLK_KP5 -p1k_6 = 262 # SDLK_KP6 -p1k_7 = 263 # SDLK_KP7 -p1k_8 = 264 # SDLK_KP8 -p1k_9 = 265 # SDLK_KP9 -p1k_pound = 267 # SDLK_KP_DIVIDE -p1k_star = 268 # SDLK_KP_MULTIPLY - -p2k_up = 273 # SDLK_UP -p2k_down = 274 # SDLK_DOWN -p2k_left = 276 # SDLK_LEFT -p2k_right = 275 # SDLK_RIGHT -p2k_c = 122 # SDLK_z -p2k_b = 120 # SDLK_x -p2k_a = 99 # SDLK_c -p2k_option = 39 # SDLK_QUOTE -p2k_pause = 13 # SDLK_RETURN -p2k_0 = 256 # SDLK_KP0 -p2k_1 = 257 # SDLK_KP1 -p2k_2 = 258 # SDLK_KP2 -p2k_3 = 259 # SDLK_KP3 -p2k_4 = 260 # SDLK_KP4 -p2k_5 = 261 # SDLK_KP5 -p2k_6 = 262 # SDLK_KP6 -p2k_7 = 263 # SDLK_KP7 -p2k_8 = 264 # SDLK_KP8 -p2k_9 = 265 # SDLK_KP9 -p2k_pound = 267 # SDLK_KP_DIVIDE -p2k_star = 268 # SDLK_KP_MULTIPLY +#k_fire = 273 # SDLK_UP +#k_thrust = 274 # SDLK_DOWN +#k_smartbomb = 276 # SDLK_LEFT +#k_hyperspace = 275 # SDLK_RIGHT +#k_reverse = 122 # SDLK_z +#k_up = 120 # SDLK_x +#k_down = 99 # SDLK_c +#k_inviso = 39 # SDLK_QUOTE +#k_1p_start = 13 # SDLK_RETURN +#k_2p_start = 256 # SDLK_KP0 +#k_left_coin = 257 # SDLK_KP1 +#k_center_coin = 259 # SDLK_KP3 +#k_right_coin = 258 # SDLK_KP2 +#k_auto_up = 260 # SDLK_KP4 +#k_advance = 261 # SDLK_KP5 +#k_high_score_reset = 262 # SDLK_KP6 +#k_slam_switch = 263 # SDLK_KP7 -- 2.37.2