X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=mercenary-reloaded.git;a=blobdiff_plain;f=src%2Fmercenary%2Fmain.c;h=45d87e4bca4637f5df95041260555dcbe51d4981;hp=4057676b11edfbfeefa50aa12bd896dbfcd4fc78;hb=3c70467233fef462f9bc9a132019800386978cc8;hpb=1b9fcb60552f1ac701dbf815d46cc32066f979d7 diff --git a/src/mercenary/main.c b/src/mercenary/main.c index 4057676..45d87e4 100644 --- a/src/mercenary/main.c +++ b/src/mercenary/main.c @@ -20,24 +20,71 @@ #include #include #include -#include +#include +#include #include #include +#include "../../include/keycodes.h" #include "../libsdl/sdl.h" -#include "../libsdl/opengl.h" +#ifdef HAVE_OVR +#include "../libovr/ovr.h" +#include "../libovr/keyboard.h" +#endif +#include "../libopengl/opengl.h" +#include "../libsdl/print.h" #include "../libcpu/m68k.h" #include "../libcpu/execute.h" +#include "../libframerate/framerate.h" #include "../libvideo/video.h" #include "../libsound/sound.h" #include "../libjoystick/joystick.h" #include "../libkeyboard/keyboard.h" #include "../libdisk/disk.h" +#include "../libtext/text.h" #include "mercenary.h" +#include "render.h" + +#define FOV_MIN 10.0 +#define FOV_NOVAGEN 64.0 +#define FOV_JOLLY 80.0 +#define FOV_MAX 170.0 -static int config_amiga_speed = 1; +#define STICK_WALK_THRESHOLD 0.3 /* move the stick until the player moves */ +#define STICK_ROTATE_THRESHOLD 0.3 /* move the stick until the player rotates */ +#define STICK_THRUST_THRESHOLD 0.1 /* move the stick until the craft moves */ + +static int config_ctrl_c = 0; +static int config_amiga_speed = 0; /* fast speed */ +static double config_fps = 10.0; +#if !defined(_WIN32) static const char *config_gamesave_dir = ".mercenary"; -static int config_video_filter = 0; +#endif +static int config_video_filter = 1; static int config_audio_filter = 1; +static int config_render = 1; /* opengl render */ +static int config_skip_intro = 0; +static int config_multisampling = 8; +static int config_joystick = -1, config_joystick_x = -1, config_joystick_y = -1, config_joystick_fire = -1; +#ifdef HAVE_OVR +static double config_benson_size = 0.7; +static double config_fov = FOV_JOLLY; +#else +static double config_benson_size = 1.0; +static double config_fov = FOV_NOVAGEN; +#endif +static double config_monitor_distance = 41.5; /* inch */ +#ifdef HAVE_OVR +static double config_keyboard_distance = 38.5; /* inch */ +static double config_keyboard_height = -26.0; /* inch */ +#endif +static int config_debug_transparent = 0; +static int config_debug_opengl = 0; +/* render improvements */ +static int config_improve_extend_roads = 1; /* set to 1 to extend roads */ +static int config_improve_smooth_planets = 1; /* set to 1 to rotate planets smoothly */ +static int config_improve_stars_rotation = 1; /* set to 1 to improve star rendering */ +static int config_improve_fix_sky_rotation = 0; /* set to 1 to fix sky rotation */ +static int config_improve_round_planets = 0; /* set to 1 to make planets exactly round */ #define CPU_SPEED 7093790.0; @@ -60,409 +107,893 @@ static int config_audio_filter = 1; #define IOSIZE 0x1000 /* bytes in io space */ #define MEMORY_SIZE 0x80000 static uint8_t *memory = NULL; +static uint8_t *stop_event = NULL; static uint8_t *image = NULL; +static uint8_t *help_osd[3] = { NULL, NULL, NULL }; +static uint8_t *info_osd = NULL; +static int help_view = 1; +static int help_views = 0; +static int32_t osd_timer = 0, border_timer = 0; #define SCREEN_WIDTH (320*3) #define SCREEN_HEIGHT (200*3) #define IMAGE_WIDTH 320 #define IMAGE_HEIGHT 200 #define BENSON_AT_LINE 136 #define IMAGE_DIWSTART 0x2c +#define HELP_ALPHA 0xd0 +#define OSD_WIDTH 320 +#define OSD_HEIGHT 16 static uint16_t *chipreg = NULL; -static float *sound_buffer = NULL; /* sound buffer memory */ +static stereo_t *sound_buffer = NULL; /* sound buffer memory */ static int sound_buffer_size; /* buffer sample size */ static int sound_buffer_writep; /* write pointer at buffer */ static int sound_buffer_readp; /* read pointer at buffer */ +static int double_pixel_size = 1; /* render in double size, so each pixle is 2*2 pixles wide */ +static double benson_size; /* render size of benson */ +static int render_legacy = 0; /* render original amiga screen, if set */ +static int render_improved = 0; /* render improved image, if set */ +static int debug_opengl = 0; /* render both, amiga screen and improved image, if set */ +static int intro_skipped = 0; /* indicated if we already have landed */ +static int window_width, window_height; +static int mission_disk = 0; static const char *home_dir; static int quit = 0; -static void main_loop(void) +int parse_args(int argc, char *argv[]) { - int had_first_irq = 0; - static uint32_t current_time, last_time = 0, diff; - int i, rc; - int space, length; - int cycle_count; - double render_delay = 0.0; - uint32_t palette_address; - uint16_t palette[16]; - - last_time = SDL_GetTicks(); - - /* render result on window */ - while (!quit) { - /* STEP 1: let the CPU render/process the game */ - /* don't render if we still delay */ - if (!render_delay) { - /* execute until the rendered image is ready */ - cycle_count = execute_cpu(0, mercenary_stop_at); - /* copy palette */ - palette_address = mercenary_palette(); - for (i = 0; i < 16; i++) - palette[i] = m68k_read_memory_16(palette_address + i*2); - /* for amiga speed: set delay by the number of cycles */ - if (config_amiga_speed) - render_delay = (double)cycle_count / CPU_SPEED; - } - - /* STEP 2: render image in memory via OpenGL */ - if (had_first_irq) { - /* render game view without benson - * because benson is not updated before VBL IRQ, we don't want old image from double buffer - */ - emul_video(image, memory, palette, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_DIWSTART, chipreg, 0, BENSON_AT_LINE); - } - rc = event_sdl(); - if (rc) - break; - render_opengl(image, config_video_filter); - swap_sdl(); + int i = 1; - /* STEP 3: execute interrupt at rate of 50Hz, render sound */ - current_time = SDL_GetTicks(); - diff = current_time - last_time; - /* in case of timer glitch, execute IRQ only by maximum number of SOUND_CHUNKS */ - if (diff > 1000 * SOUND_CHUNKS / IRQ_RATE) { - diff = 1000 * SOUND_CHUNKS / IRQ_RATE; - last_time = current_time - 1000 * SOUND_CHUNKS / IRQ_RATE; - } - while (diff > 1000 / IRQ_RATE) { - execute_cpu(3, NULL); - execute_cpu(4, NULL); - had_first_irq = 1; - /* render benson without game view - * because we only got benson refreshed during VBL IRQ - */ - emul_video(image, memory, palette, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_DIWSTART, chipreg, BENSON_AT_LINE, IMAGE_HEIGHT); - /* render sound to sound buffer - * buffer pointer read and write is atomic, so no locking required! - */ - space = (sound_buffer_readp - sound_buffer_writep - 1 + sound_buffer_size) % sound_buffer_size; - if (space < SOUND_SAMPLERATE / IRQ_RATE) { -#ifdef DEBUG_SOUND_BUFFERING - fprintf(stderr, "sound buffer overflow\n"); -#endif - length = space; - } else - length = SOUND_SAMPLERATE / IRQ_RATE; -#ifdef DEBUG_SOUND_BUFFERING - printf("can write %d, write %d\n", space, length); - static int cnt = 0; - int s; - for (s = 0; s < length; s++) { - sound_buffer[(sound_buffer_writep + s) % sound_buffer_size] - = sin(2 * M_PI * 999 * cnt / SOUND_SAMPLERATE) - * sin(2 * M_PI * 21 * cnt / SOUND_SAMPLERATE) - * sin(2 * M_PI * 0.5 * cnt / SOUND_SAMPLERATE); - cnt++; + while (argc > i) { + if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + /* | | */ + print_info("Usage: %s\n", argv[0]); + print_info(" -s --render-speed original | fast\n"); + print_info(" Set speed of rendering to original Amiga or fast speed.\n"); + print_info(" --fps \n"); + print_info(" Set frames per second for fast rate (default = %.1f).\n", config_fps); + print_info(" -v --video-filter on | off\n"); + print_info(" Set video filter.\n"); + print_info(" -a --audio-filter on | off\n"); + print_info(" Set audio filter.\n"); + print_info(" -r --render original | opengl\n"); + print_info(" Set speed of rendering to original Amiga or OpenGL.\n"); + print_info(" -b --benson normal | half\n"); + print_info(" Size of 'Benson' (control panel).\n"); + print_info(" -m --multisampling \n"); + print_info(" Use multisampling (default = %d) to render the scene.\n", config_multisampling); + print_info(" -f --fov <%.0f..%.0f..%.0f>\n", FOV_MIN, FOV_NOVAGEN, FOV_MAX); + print_info(" Set field-of-view. Default is %.0f.\n", FOV_NOVAGEN); + print_info(" -i --skip-intro\n"); + print_info(" Skip intro sequence approaching to Eris space port.\n"); + print_info(" -j --joystick | list\n"); + print_info(" Select given joystick number or show list. (default = 0, if available)\n"); + print_info(" --joystick-x \n"); + print_info(" --joystick-y \n"); + print_info(" --joystick-fire