--- generator/src/uip-allegro.c 2020/03/04 04:46:28 1.1 +++ generator/src/uip-allegro.c 2020/03/04 04:46:34 1.1.1.2 @@ -1,10 +1,6 @@ -/*****************************************************************************/ -/* Generator - Sega Genesis emulation - (c) James Ponder 1997-2000 */ -/*****************************************************************************/ -/* */ -/* uip-allegro - User interface for allegro (15/16 bit) */ -/* */ -/*****************************************************************************/ +/* Generator is (c) James Ponder, 1997-2001 http://www.squish.net/generator/ */ + +/* user interface for allegro (15/16 bit) */ #include #include @@ -29,6 +25,9 @@ static BITMAP *uip_bank1; /* static BITMAP *uip_writebank; /* current write bank */ static uint8 uip_keypoll = 0; /* flag indicating requires polling */ static t_uipinfo *uip_uipinfo = NULL; /* uipinfo */ +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 ***/ @@ -37,63 +36,31 @@ static void uip_keyboardhandler(int scan press = (scancode & 128) ? 0 : 1; scancode = scancode & 127; if (press) { - if (scancode == KEY_F5) { - ui_info^= 1; - ui_clearnext = 2; + if (scancode == KEY_F1) { + ui_fkeys|= 1<<1; + } else if (scancode == KEY_F2) { + ui_fkeys|= 1<<2; + } else if (scancode == KEY_F3) { + ui_fkeys|= 1<<3; + } else if (scancode == KEY_F4) { + ui_fkeys|= 1<<4; + } else if (scancode == KEY_F5) { + ui_fkeys|= 1<<5; } else if (scancode == KEY_F6) { - vdp_pal^= 1; - vdp_setupvideo(); - ui_clearnext = 2; + ui_fkeys|= 1<<6; } else if (scancode == KEY_F7) { - vdp_overseas^= 1; - ui_clearnext = 2; + ui_fkeys|= 1<<7; } else if (scancode == KEY_F8) { - ui_vdpsimple^= 1; - ui_clearnext = 2; + ui_fkeys|= 1<<8; } else if (scancode == KEY_F9) { - ui_vsync^= 1; - ui_clearnext = 2; - } else if (scancode == KEY_1) { - vdp_layerB^= 1; - ui_clearnext = 2; - } else if (scancode == KEY_2) { - vdp_layerBp^= 1; - ui_clearnext = 2; - } else if (scancode == KEY_3) { - vdp_layerA^= 1; - ui_clearnext = 2; - } else if (scancode == KEY_4) { - vdp_layerAp^= 1; - ui_clearnext = 2; - } else if (scancode == KEY_5) { - vdp_layerW^= 1; - ui_clearnext = 2; - } else if (scancode == KEY_6) { - vdp_layerWp^= 1; - ui_clearnext = 2; - } else if (scancode == KEY_7) { - vdp_layerH^= 1; - ui_clearnext = 2; - } else if (scancode == KEY_8) { - vdp_layerS^= 1; - ui_clearnext = 2; - } else if (scancode == KEY_9) { - vdp_layerSp^= 1; - ui_clearnext = 2; + ui_fkeys|= 1<<9; + } else if (scancode == KEY_F10) { + ui_fkeys|= 1<<10; + } else if (scancode == KEY_F11) { + ui_fkeys|= 1<<11; + } else if (scancode == KEY_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); - } - */ } } @@ -104,7 +71,7 @@ int uip_init(t_uipinfo *uipinfo) uip_uipinfo = uipinfo; check_cpu(); printf("Initialising %s - %s (%d:%d:%d:%d:%d)\n", allegro_id, cpu_vendor, - cpu_family, cpu_model, cpu_fpu?1:0, cpu_mmx?1:0, cpu_3dnow?1:0); + cpu_family, cpu_model, cpu_fpu?1:0, cpu_mmx?1:0, cpu_3dnow?1:0); printf("\nNote: Allegro can take at least 5 seconds to quit!\n"); sleep(2); if (allegro_init()) { @@ -112,20 +79,12 @@ int uip_init(t_uipinfo *uipinfo) return 1; } LOCK_VARIABLE(ui_info); - LOCK_VARIABLE(vdp_pal); LOCK_VARIABLE(vdp_overseas); LOCK_VARIABLE(ui_vdpsimple); LOCK_VARIABLE(ui_vsync); LOCK_VARIABLE(ui_clearnext); - LOCK_VARIABLE(vdp_layerB); - LOCK_VARIABLE(vdp_layerBp); - LOCK_VARIABLE(vdp_layerA); - LOCK_VARIABLE(vdp_layerAp); - LOCK_VARIABLE(vdp_layerW); - LOCK_VARIABLE(vdp_layerWp); - LOCK_VARIABLE(vdp_layerH); - LOCK_VARIABLE(vdp_layerS); - LOCK_VARIABLE(vdp_layerSp); + LOCK_VARIABLE(ui_fullscreen); + LOCK_VARIABLE(ui_fkeys); LOCK_FUNCTION(uip_keyboardhandler); return 0; } @@ -141,13 +100,13 @@ int uip_vgamode(void) set_color_depth((depth == 17 ? 32 : depth)); request_refresh_rate(rate); if ((set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 480*2) < 0)) { - LOG_VERBOSE(("Mode not supported")); - continue; + LOG_VERBOSE(("Mode not supported")); + continue; } if (SCREEN_W != 640 || SCREEN_H != 480) { - LOG_CRITICAL(("Screen not approriate for depth %d rate %d", depth, - rate)); - continue; + LOG_CRITICAL(("Screen not approriate for depth %d rate %d", depth, + rate)); + continue; } goto WHEE; } @@ -156,9 +115,16 @@ int uip_vgamode(void) return 1; WHEE: uip_vga = 1; - uip_uipinfo->redshift = ui_topbit(makecol(255,0,0))-4; - uip_uipinfo->greenshift = ui_topbit(makecol(0,255,0))-4; - uip_uipinfo->blueshift = ui_topbit(makecol(0,0,255))-4; + 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 { + uip_uipinfo->redshift = ui_topbit(makecol(255,0,0))-4; + uip_uipinfo->greenshift = ui_topbit(makecol(0,255,0))-4; + uip_uipinfo->blueshift = ui_topbit(makecol(0,0,255))-4; + } if ((uip_bank0 = create_video_bitmap(640, 480)) == NULL || (uip_bank1 = create_video_bitmap(640, 480)) == NULL) { uip_textmode(); @@ -171,17 +137,17 @@ int uip_vgamode(void) is_video_bitmap(uip_bank1) == 0) { uip_textmode(); LOG_CRITICAL(("Allocated bitmaps not suitable or linear addressing mode " - "not supported by hardware")); + "not supported by hardware")); return 1; } /* don't you just hate MS platforms? */ __djgpp_nearptr_enable(); __dpmi_get_segment_base_address(uip_bank0->seg, &screenbase); uip_uipinfo->screenmem0 = (uint8 *)(screenbase + uip_bank0->line[0] - - __djgpp_base_address); + __djgpp_base_address); __dpmi_get_segment_base_address(uip_bank1->seg, &screenbase); uip_uipinfo->screenmem1 = (uint8 *)(screenbase + uip_bank1->line[0] - - __djgpp_base_address); + __djgpp_base_address); uip_uipinfo->linewidth = 2*VIRTUAL_W; /* 16 bit */ uip_displaybank(0); /* set current to 0th bank */ uip_clearscreen(); /* clear bank */ @@ -204,6 +170,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; @@ -216,7 +190,34 @@ void uip_displaybank(int bank) { } void uip_clearscreen(void) { - clear(uip_writebank); + int y; + + for (y = 0; y < 480; y++) { + memset(uip_uipinfo->screenmem_w+uip_uipinfo->linewidth*y, 0, 640*2); + } +} + +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) @@ -234,20 +235,34 @@ int uip_checkkeyboard(void) poll_keyboard(); mem68k_cont1_a = key[KEY_A] ? 1 : 0; mem68k_cont1_b = (key[KEY_B] || - key[KEY_S]) ? 1 : 0; + key[KEY_S]) ? 1 : 0; mem68k_cont1_c = (key[KEY_C] || - key[KEY_D]) ? 1 : 0; + key[KEY_D]) ? 1 : 0; mem68k_cont1_left = key[KEY_LEFT] ? 1 : 0; mem68k_cont1_up = key[KEY_UP] ? 1 : 0; mem68k_cont1_right = key[KEY_RIGHT] ? 1 : 0; mem68k_cont1_down = key[KEY_DOWN] ? 1 : 0; mem68k_cont1_start = key[KEY_ENTER] ? 1 : 0; - if (key[KEY_F12]) - gen_reset(); return (key[KEY_ESC] ? 1 : 0); } +unsigned int uip_whichbank(void) +{ + /* returns 0 or 1 - the bank being VIEWED */ + return uip_displaybanknum; +} + void uip_vsync(void) { vsync(); } + +uint8 uip_getchar(void) +{ + char c; + + keyboard_lowlevel_callback = NULL; + c = readkey() & 0xff; + keyboard_lowlevel_callback = uip_keyboardhandler; + return c; +}