--- generator/src/uip-svgalib.c 2020/03/04 04:46:28 1.1.1.1 +++ generator/src/uip-svgalib.c 2020/03/04 04:46:35 1.1.1.2 @@ -1,10 +1,6 @@ -/*****************************************************************************/ -/* Generator - Sega Genesis emulation - (c) James Ponder 1997-2000 */ -/*****************************************************************************/ -/* */ -/* uip-svgalib - User interface for svgalib (15 bit) */ -/* */ -/*****************************************************************************/ +/* Generator is (c) James Ponder, 1997-2001 http://www.squish.net/generator/ */ + +/* user interface for svgalib (15/16 bit) */ #include #include @@ -23,12 +19,17 @@ /*** forward reference declarations ***/ +static int uip_getshifts(t_uipinfo *uipinfo); + /*** static variables ***/ static uint8 uip_vga = 0; /* flag for whether in VGA more or not */ static uint8 uip_displaybanknum = 0; /* view this one, write to other one */ static t_uipinfo *uip_uipinfo = NULL; /* uipinfo */ static uint8 uip_key[256]; /* keyboard state */ +static int uip_forceredshift = -1; /* if set, forces red shift position */ +static int uip_forcegreenshift = -1; /* if set, forces green shift position */ +static int uip_forceblueshift = -1; /* if set, forces blue shift position */ /*** Code ***/ @@ -39,63 +40,31 @@ static void uip_keyboardhandler(int scan return; uip_key[scancode] = press; if (press) { - if (scancode == SCANCODE_F5) { - ui_info^= 1; - ui_clearnext = 2; + if (scancode == SCANCODE_F1) { + ui_fkeys|= 1<<1; + } else if (scancode == SCANCODE_F2) { + ui_fkeys|= 1<<2; + } else if (scancode == SCANCODE_F3) { + ui_fkeys|= 1<<3; + } else if (scancode == SCANCODE_F4) { + ui_fkeys|= 1<<4; + } else if (scancode == SCANCODE_F5) { + ui_fkeys|= 1<<5; } else if (scancode == SCANCODE_F6) { - vdp_pal^= 1; - vdp_setupvideo(); - ui_clearnext = 2; + ui_fkeys|= 1<<6; } else if (scancode == SCANCODE_F7) { - vdp_overseas^= 1; - ui_clearnext = 2; + ui_fkeys|= 1<<7; } else if (scancode == SCANCODE_F8) { - ui_vdpsimple^= 1; - ui_clearnext = 2; + ui_fkeys|= 1<<8; } else if (scancode == SCANCODE_F9) { - ui_vsync^= 1; - ui_clearnext = 2; - } else if (scancode == SCANCODE_1) { - vdp_layerB^= 1; - ui_clearnext = 2; - } else if (scancode == SCANCODE_2) { - vdp_layerBp^= 1; - ui_clearnext = 2; - } else if (scancode == SCANCODE_3) { - vdp_layerA^= 1; - ui_clearnext = 2; - } else if (scancode == SCANCODE_4) { - vdp_layerAp^= 1; - ui_clearnext = 2; - } else if (scancode == SCANCODE_5) { - vdp_layerW^= 1; - ui_clearnext = 2; - } else if (scancode == SCANCODE_6) { - vdp_layerWp^= 1; - ui_clearnext = 2; - } else if (scancode == SCANCODE_7) { - vdp_layerH^= 1; - ui_clearnext = 2; - } else if (scancode == SCANCODE_8) { - vdp_layerS^= 1; - ui_clearnext = 2; - } else if (scancode == SCANCODE_9) { - vdp_layerSp^= 1; - ui_clearnext = 2; + ui_fkeys|= 1<<9; + } else if (scancode == SCANCODE_F10) { + ui_fkeys|= 1<<10; + } else if (scancode == SCANCODE_F11) { + ui_fkeys|= 1<<11; + } else if (scancode == SCANCODE_F12) { + ui_fkeys|= 1<<12; } - /* - { - FILE *moo; - int i; - moo = fopen("/tmp/screenshot.raw", "w"); - for (i = 0; i < 640*480; i++) { - fputc(((((uint16 *)uip_uipinfo.screenmem)[i]>>10) & 0x1f)<<3, moo); - fputc(((((uint16 *)uip_uipinfo.screenmem)[i]>>5) & 0x1f)<<3, moo); - fputc(((((uint16 *)uip_uipinfo.screenmem)[i]>>0) & 0x1f)<<3, moo); - } - fclose(moo); - } - */ } } @@ -118,12 +87,17 @@ int uip_vgamode(void) uip_vga = 1; if (vga_setmode(G640x480x32K) == -1) { - uip_textmode(); - LOG_CRITICAL(("Unable to change SVGA mode, mode not supported by " - "hardware?")); - LOG_CRITICAL(("Check /etc/vga/libvga.config to ensure your card " - "is not commented out")); - return 1; + LOG_CRITICAL(("640x480 @ 32K colours not supported by hardware")); + LOG_CRITICAL(("Trying 640x480 @ 64K colours...")); + if (vga_setmode(G640x480x64K) == -1) { + LOG_CRITICAL(("640x480 @ 64K colours not supported by hardware")); + uip_textmode(); + LOG_CRITICAL(("Unable to change SVGA mode, mode not supported by " + "hardware?")); + LOG_CRITICAL(("Check /etc/vga/libvga.config to ensure your card " + "is not commented out")); + return 1; + } } if (vga_claimvideomemory(2*BANKSIZE) == -1) { uip_textmode(); @@ -147,9 +121,6 @@ int uip_vgamode(void) return 1; } uip_uipinfo->linewidth = modeinfo->linewidth; - uip_uipinfo->redshift = 0; - uip_uipinfo->greenshift = 5; - uip_uipinfo->redshift = 10; if (vga_setlinearaddressing() == -1) { uip_textmode(); LOG_CRITICAL(("Linear addressing mode not supported by hardware")); @@ -161,6 +132,30 @@ int uip_vgamode(void) return 1; } uip_uipinfo->screenmem1 = uip_uipinfo->screenmem0+BANKSIZE; + if (uip_forceredshift != -1 && uip_forcegreenshift != -1 && + uip_forceblueshift != -1) { + uip_uipinfo->redshift = uip_forceredshift; + uip_uipinfo->greenshift = uip_forcegreenshift; + uip_uipinfo->blueshift = uip_forceblueshift; + } else { + switch (modeinfo->colors) { + case 32768: + LOG_VERBOSE(("Assuming colour bit positions 10,5,0 for 32k colour mode")); + uip_uipinfo->blueshift = 0; + uip_uipinfo->greenshift = 5; + uip_uipinfo->redshift = 10; + break; + case 65536: + LOG_VERBOSE(("Assuming colour bit positions 11,6,0 for 64k colour mode")); + uip_uipinfo->blueshift = 0; + uip_uipinfo->greenshift = 6; + uip_uipinfo->redshift = 11; + break; + default: + LOG_CRITICAL(("Unknown mode - %d colours?? use -c", modeinfo->colors)); + return 1; + } + } uip_displaybank(0); /* set current to 0th bank */ uip_clearscreen(); /* clear bank */ ui_setupscreen(); /* setup bank */ @@ -177,6 +172,14 @@ int uip_vgamode(void) return 0; } +int uip_setcolourbits(int red, int green, int blue) +{ + uip_forceredshift = red; + uip_forcegreenshift = green; + uip_forceblueshift = blue; + return 0; +} + void uip_displaybank(int bank) { if (bank == -1) bank = uip_displaybanknum ^ 1; @@ -190,6 +193,29 @@ void uip_clearscreen(void) { memset(uip_uipinfo->screenmem_w, 0, BANKSIZE); } +void uip_clearmiddle(void) { + int i; + + for (i = 0; i < 240; i++) { + memset(uip_uipinfo->screenmem_w+(uip_uipinfo->linewidth)*(120+i)+ + 160*2, 0, 2*320); + } +} + +/* uip_singlebank sets write address to the current display screen */ + +void uip_singlebank(void) { + uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem1 : + uip_uipinfo->screenmem0; +} + +/* uip_doublebank sets write address to hidden display screen */ + +void uip_doublebank(void) { + uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem0 : + uip_uipinfo->screenmem1; +} + void uip_textmode(void) { if (uip_vga) { @@ -212,8 +238,6 @@ int uip_checkkeyboard(void) mem68k_cont1_right = uip_key[SCANCODE_CURSORBLOCKRIGHT] ? 1 : 0; mem68k_cont1_down = uip_key[SCANCODE_CURSORBLOCKDOWN] ? 1 : 0; mem68k_cont1_start = uip_key[SCANCODE_ENTER] ? 1 : 0; - if (uip_key[SCANCODE_F12]) - gen_reset(); return (uip_key[SCANCODE_ESCAPE] ? 1 : 0); } @@ -221,3 +245,22 @@ void uip_vsync(void) { vga_waitretrace(); } + +unsigned int uip_whichbank(void) +{ + /* returns 0 or 1 - the bank being VIEWED */ + return uip_displaybanknum; +} + +uint8 uip_getchar(void) +{ + char c; + + keyboard_setdefaulteventhandler(); + keyboard_close(); + c = getchar(); + keyboard_init(); + memset(uip_key, 0, sizeof(uip_key)); + keyboard_seteventhandler(uip_keyboardhandler); + return c; +}