--- uae/src/svga.c 2018/04/24 16:38:39 1.1 +++ uae/src/svga.c 2018/04/24 16:39:09 1.1.1.2 @@ -20,6 +20,7 @@ #include "options.h" #include "memory.h" #include "custom.h" +#include "readcpu.h" #include "newcpu.h" #include "keyboard.h" #include "xwin.h" @@ -121,9 +122,9 @@ #define SCODE_NEXT 81 #define SCODE_PRIOR 73 #define SCODE_BS 14 -/* -#define SCODE_asciicircum 1 -*/ + +#define SCODE_asciicircum 41 + #define SCODE_bracketleft 26 #define SCODE_bracketright 27 #define SCODE_comma 51 @@ -145,24 +146,26 @@ void setup_brkhandler(void) { } -static int vsize, bitdepth, bit_unit, using_linear; +static int bitdepth, bit_unit, using_linear; static vga_modeinfo modeinfo; static char *linear_mem = NULL; static int need_dither; -static int x_size = 0, vidmode_linewidth; static UBYTE dither_buf[1000]; /* I hate having to think about array bounds */ xcolnr xcolors[4096]; struct vidbuf_description gfxvidinfo; +#define MAX_SCREEN_MODES 6 -static int x_size_table[MAX_SCREEN_MODES+1] = { 320, 320, 320, 640, 800 }; +static int x_size_table[MAX_SCREEN_MODES] = { 320, 320, 320, 640, 640, 800 }; +static int y_size_table[MAX_SCREEN_MODES] = { 200, 240, 400, 350, 480, 600 }; -static int vga_mode_table[MAX_SCREEN_MODES+1][MAX_COLOR_MODES+1] = +static int vga_mode_table[MAX_SCREEN_MODES][MAX_COLOR_MODES+1] = { { G320x200x256, G320x200x32K, G320x200x64K, G320x200x256, G320x200x16, G320x200x16M32 }, { G320x240x256, -1, -1, G320x240x256, -1, -1 }, { G320x400x256, -1, -1, G320x400x256, -1, -1 }, + { -1, -1, -1, -1, G640x350x16, -1 }, { G640x480x256, G640x480x32K, G640x480x64K, G640x480x256, G640x480x16, G640x480x16M32 }, { G800x600x256, G800x600x32K, G800x600x64K, G800x600x256, G800x600x16, G800x600x16M32 } }; @@ -173,13 +176,11 @@ void flush_line(int y) { int target_y = y; - if (screen_res < 2) - target_y -= 8; if (linear_mem == NULL) { char *addr = gfxvidinfo.bufmem + y*gfxvidinfo.rowbytes; if (target_y < modeinfo.height && target_y >= 0) { if (need_dither) { - DitherLine(dither_buf, (UWORD *)addr, 0, y, x_size, bit_unit); + DitherLine(dither_buf, (UWORD *)addr, 0, y, gfxvidinfo.maxlinetoscr, bit_unit); addr = dither_buf; } vga_drawscanline(target_y, addr); @@ -187,7 +188,8 @@ void flush_line(int y) } else { if (need_dither && target_y >= 0) { char *addr = gfxvidinfo.bufmem + y*gfxvidinfo.rowbytes; - DitherLine(linear_mem + vidmode_linewidth * target_y, (UWORD *)addr, 0, y, x_size, bit_unit); + DitherLine(linear_mem + modeinfo.linewidth * target_y, (UWORD *)addr, 0, y, + gfxvidinfo.maxlinetoscr, bit_unit); } } } @@ -201,22 +203,6 @@ void flush_screen(int a, int b) { } -void calc_adjustment(void) -{ - switch (screen_res) { - case 0: case 1: case 2: /* LoRes, 320xfoo */ - gfxvidinfo.x_adjust = prev_max_diwstop - 320; - break; - - case 3: /* 640xbar */ - gfxvidinfo.x_adjust = prev_max_diwstop - 640; - break; - default: - gfxvidinfo.x_adjust = 0; - break; - } -} - static int colors_allocated; static int get_color(int r, int g, int b, xcolnr *cnp) @@ -346,9 +332,7 @@ static int scancode2amiga(int scancode) case SCODE_CURSORBLOCKRIGHT: return AK_RT; case SCODE_F11: return AK_BACKSLASH; -/* case SCODE_asciicircum: return AK_00; - */ case SCODE_bracketleft: return AK_LBRACKET; case SCODE_bracketright: return AK_RBRACKET; case SCODE_comma: return AK_COMMA; @@ -407,35 +391,56 @@ int graphics_init(void) { int i; int vgamode; - + int mode_nr0, mode_nr; need_dither = 0; using_linear = 0; - if (screen_res < 3) - correct_aspect = 0; - - vgamode = vga_mode_table[screen_res][color_mode]; - if (vgamode == -1) { + fprintf (stderr, "Initializing SVGAlib.\n"); + mode_nr0 = 0; + for (i = 1; i < MAX_SCREEN_MODES; i++) { + if (x_size_table[mode_nr0] >= gfx_requested_width) + break; + if (x_size_table[i-1] != x_size_table[i]) + mode_nr0 = i; + } + mode_nr = -1; + for (i = mode_nr0; i < MAX_SCREEN_MODES && x_size_table[i] == x_size_table[mode_nr0]; i++) { + if ((y_size_table[i] >= gfx_requested_height + || i + 1 == MAX_SCREEN_MODES + || x_size_table[i+1] != x_size_table[mode_nr0]) + && vga_mode_table[i][color_mode] != -1) + { + mode_nr = i; + break; + } + } + if (mode_nr == -1) { fprintf(stderr, "Sorry, this combination of color and video mode is not supported.\n"); return 0; } + vgamode = vga_mode_table[mode_nr][color_mode]; + if (vgamode == -1) { + fprintf(stderr, "Bug!\n"); + abort(); + } + fprintf(stderr, "Desired resolution: %dx%d, using: %dx%d\n", + gfx_requested_width, gfx_requested_height, + x_size_table[mode_nr], y_size_table[mode_nr]); + gfx_requested_width = x_size_table[mode_nr]; + gfx_requested_height = y_size_table[mode_nr]; + bitdepth = mode_bitdepth[color_mode][0]; bit_unit = mode_bitdepth[color_mode][1]; need_dither = mode_bitdepth[color_mode][2]; - x_size = x_size_table[screen_res]; vga_init(); modeinfo = *vga_getmodeinfo (vgamode); - vidmode_linewidth = modeinfo.linewidth; gfxvidinfo.pixbytes = modeinfo.bytesperpixel; if (!need_dither) { if (modeinfo.bytesperpixel == 0) { - printf("Got a bogus value from SVGAlib... %s.\n", - screen_res == 1 || screen_res == 2 ? "trying to fix it" : "giving up"); - if (screen_res != 1 && screen_res != 2) - return 0; + printf("Got a bogus value from SVGAlib...\n"); gfxvidinfo.pixbytes = 1; } } else { @@ -456,26 +461,24 @@ int graphics_init(void) using_linear = !need_dither; } } - - vsize = correct_aspect ? 2*numscrlines : numscrlines; + gfxvidinfo.maxblocklines = 0; + gfxvidinfo.maxlinetoscr = modeinfo.width; + gfxvidinfo.maxline = modeinfo.height; + if (using_linear) { gfxvidinfo.bufmem = linear_mem; gfxvidinfo.rowbytes = modeinfo.linewidth; } else { - gfxvidinfo.rowbytes = x_size * gfxvidinfo.pixbytes; - gfxvidinfo.bufmem = malloc(gfxvidinfo.rowbytes * vsize); - memset(gfxvidinfo.bufmem, 0, gfxvidinfo.rowbytes * vsize); + gfxvidinfo.rowbytes = (modeinfo.width * gfxvidinfo.pixbytes + 3) & ~3; + gfxvidinfo.bufmem = malloc(gfxvidinfo.rowbytes * modeinfo.height); + memset(gfxvidinfo.bufmem, 0, gfxvidinfo.rowbytes * modeinfo.height); } - - gfxvidinfo.maxlinetoscr = x_size < 800 ? x_size : 0; - gfxvidinfo.x_adjust = 0; - gfxvidinfo.maxline = modeinfo.height; init_colors(); vga_setmousesupport(1); - mouse_init("/dev/mouse",vga_getmousetype(),10); + mouse_init("/dev/mouse", vga_getmousetype(), 10); if (keyboard_init() != 0) abort(); keyboard_seteventhandler(my_kbd_handler); @@ -534,14 +537,14 @@ void LED(int on) void target_specific_usage(void) { - printf(" -S n : Sound emulation accuracy (n = 0, 1, 2 or 3)\n" - " For sound emulation, n = 2 is recommended\n"); - printf(" -b n : Use n bits for sound output (8 or 16)\n"); - printf(" -R n : Use n Hz to output sound. Common values are\n" - " 22050 Hz or 44100 Hz\n"); - printf(" -B n : Use a sound buffer of n bytes (use small\n" - " values on fast machines)\n"); - printf(" -x : Don't use SVGAlib linear framebuffer, even if available.\n"); - printf(" -p command : Use command to pipe printer output to.\n"); - printf(" -I device : Name of the used serial device (i.e. /dev/ttyS1\n"); + printf(" -S n : Sound emulation accuracy (n = 0, 1, 2 or 3)\n" + " For sound emulation, n = 2 is recommended\n"); + printf(" -b n : Use n bits for sound output (8 or 16)\n"); + printf(" -R n : Use n Hz to output sound. Common values are\n" + " 22050 Hz or 44100 Hz\n"); + printf(" -B n : Use a sound buffer of n bytes (use small\n" + " values on fast machines)\n"); + printf(" -x : Don't use SVGAlib linear framebuffer, even if available.\n"); + printf(" -p command : Use command to pipe printer output to.\n"); + printf(" -I device : Name of the used serial device (i.e. /dev/ttyS1\n"); }