|
|
1.1 ! root 1: /* Generator is (c) James Ponder, 1997-2001 http://www.squish.net/generator/ */ ! 2: ! 3: /* user interface for allegro (15/16 bit) */ ! 4: ! 5: #include <sys/nearptr.h> ! 6: #include <stdio.h> ! 7: ! 8: #include "generator.h" ! 9: #include <allegro.h> ! 10: ! 11: #include "uip.h" ! 12: #include "ui.h" ! 13: #include "ui-console.h" ! 14: #include "vdp.h" ! 15: #include "mem68k.h" ! 16: ! 17: /*** forward reference declarations ***/ ! 18: ! 19: /*** static variables ***/ ! 20: ! 21: static uint8 uip_vga = 0; /* flag for whether in VGA more or not */ ! 22: static uint8 uip_displaybanknum = 0; /* view this one, write to other one */ ! 23: static BITMAP *uip_bank0; /* first video bank */ ! 24: static BITMAP *uip_bank1; /* second video bank */ ! 25: static BITMAP *uip_writebank; /* current write bank */ ! 26: static uint8 uip_keypoll = 0; /* flag indicating requires polling */ ! 27: static t_uipinfo *uip_uipinfo = NULL; /* uipinfo */ ! 28: static int uip_forceredshift = -1; /* if set, forces red shift position */ ! 29: static int uip_forcegreenshift = -1; /* if set, forces green shift position */ ! 30: static int uip_forceblueshift = -1; /* if set, forces blue shift position */ ! 31: ! 32: /*** Code ***/ ! 33: ! 34: static void uip_keyboardhandler(int scancode) { ! 35: int press; ! 36: press = (scancode & 128) ? 0 : 1; ! 37: scancode = scancode & 127; ! 38: if (press) { ! 39: if (scancode == KEY_F1) { ! 40: ui_fkeys|= 1<<1; ! 41: } else if (scancode == KEY_F2) { ! 42: ui_fkeys|= 1<<2; ! 43: } else if (scancode == KEY_F3) { ! 44: ui_fkeys|= 1<<3; ! 45: } else if (scancode == KEY_F4) { ! 46: ui_fkeys|= 1<<4; ! 47: } else if (scancode == KEY_F5) { ! 48: ui_fkeys|= 1<<5; ! 49: } else if (scancode == KEY_F6) { ! 50: ui_fkeys|= 1<<6; ! 51: } else if (scancode == KEY_F7) { ! 52: ui_fkeys|= 1<<7; ! 53: } else if (scancode == KEY_F8) { ! 54: ui_fkeys|= 1<<8; ! 55: } else if (scancode == KEY_F9) { ! 56: ui_fkeys|= 1<<9; ! 57: } else if (scancode == KEY_F10) { ! 58: ui_fkeys|= 1<<10; ! 59: } else if (scancode == KEY_F11) { ! 60: ui_fkeys|= 1<<11; ! 61: } else if (scancode == KEY_F12) { ! 62: ui_fkeys|= 1<<12; ! 63: } ! 64: } ! 65: } ! 66: ! 67: END_OF_FUNCTION(uip_keyboardhandler); ! 68: ! 69: int uip_init(t_uipinfo *uipinfo) ! 70: { ! 71: uip_uipinfo = uipinfo; ! 72: check_cpu(); ! 73: printf("Initialising %s - %s (%d:%d:%d:%d:%d)\n", allegro_id, cpu_vendor, ! 74: cpu_family, cpu_model, cpu_fpu?1:0, cpu_mmx?1:0, cpu_3dnow?1:0); ! 75: printf("\nNote: Allegro can take at least 5 seconds to quit!\n"); ! 76: sleep(2); ! 77: if (allegro_init()) { ! 78: LOG_CRITICAL(("Failed to initialise allegro")); ! 79: return 1; ! 80: } ! 81: LOCK_VARIABLE(ui_info); ! 82: LOCK_VARIABLE(vdp_overseas); ! 83: LOCK_VARIABLE(ui_vdpsimple); ! 84: LOCK_VARIABLE(ui_vsync); ! 85: LOCK_VARIABLE(ui_clearnext); ! 86: LOCK_VARIABLE(ui_fullscreen); ! 87: LOCK_VARIABLE(ui_fkeys); ! 88: LOCK_FUNCTION(uip_keyboardhandler); ! 89: return 0; ! 90: } ! 91: ! 92: int uip_vgamode(void) ! 93: { ! 94: int depth, rate; ! 95: unsigned long screenbase; ! 96: ! 97: for (rate = 60; rate <= 70; rate+=10) { ! 98: for (depth = 15; depth <= 17; depth++) { ! 99: LOG_VERBOSE(("Trying mode 640x480 depth %d rate %d", depth, rate)); ! 100: set_color_depth((depth == 17 ? 32 : depth)); ! 101: request_refresh_rate(rate); ! 102: if ((set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 480*2) < 0)) { ! 103: LOG_VERBOSE(("Mode not supported")); ! 104: continue; ! 105: } ! 106: if (SCREEN_W != 640 || SCREEN_H != 480) { ! 107: LOG_CRITICAL(("Screen not approriate for depth %d rate %d", depth, ! 108: rate)); ! 109: continue; ! 110: } ! 111: goto WHEE; ! 112: } ! 113: } ! 114: LOG_CRITICAL(("Failed to find suitable mode")); ! 115: return 1; ! 116: WHEE: ! 117: uip_vga = 1; ! 118: if (uip_forceredshift != -1 && uip_forcegreenshift != -1 && ! 119: uip_forceblueshift != -1) { ! 120: uip_uipinfo->redshift = uip_forceredshift; ! 121: uip_uipinfo->greenshift = uip_forcegreenshift; ! 122: uip_uipinfo->blueshift = uip_forceblueshift; ! 123: } else { ! 124: uip_uipinfo->redshift = ui_topbit(makecol(255,0,0))-4; ! 125: uip_uipinfo->greenshift = ui_topbit(makecol(0,255,0))-4; ! 126: uip_uipinfo->blueshift = ui_topbit(makecol(0,0,255))-4; ! 127: } ! 128: if ((uip_bank0 = create_video_bitmap(640, 480)) == NULL || ! 129: (uip_bank1 = create_video_bitmap(640, 480)) == NULL) { ! 130: uip_textmode(); ! 131: LOG_CRITICAL(("Failed to allocate memory pages")); ! 132: return 1; ! 133: } ! 134: if (is_linear_bitmap(uip_bank0) == 0 || ! 135: is_linear_bitmap(uip_bank1) == 0 || ! 136: is_video_bitmap(uip_bank0) == 0 || ! 137: is_video_bitmap(uip_bank1) == 0) { ! 138: uip_textmode(); ! 139: LOG_CRITICAL(("Allocated bitmaps not suitable or linear addressing mode " ! 140: "not supported by hardware")); ! 141: return 1; ! 142: } ! 143: /* don't you just hate MS platforms? */ ! 144: __djgpp_nearptr_enable(); ! 145: __dpmi_get_segment_base_address(uip_bank0->seg, &screenbase); ! 146: uip_uipinfo->screenmem0 = (uint8 *)(screenbase + uip_bank0->line[0] - ! 147: __djgpp_base_address); ! 148: __dpmi_get_segment_base_address(uip_bank1->seg, &screenbase); ! 149: uip_uipinfo->screenmem1 = (uint8 *)(screenbase + uip_bank1->line[0] - ! 150: __djgpp_base_address); ! 151: uip_uipinfo->linewidth = 2*VIRTUAL_W; /* 16 bit */ ! 152: uip_displaybank(0); /* set current to 0th bank */ ! 153: uip_clearscreen(); /* clear bank */ ! 154: ui_setupscreen(); /* setup bank */ ! 155: uip_displaybank(-1); /* toggle bank */ ! 156: uip_clearscreen(); /* clear bank */ ! 157: ui_setupscreen(); /* setup bank */ ! 158: if (install_keyboard() == -1) { ! 159: uip_textmode(); ! 160: LOG_CRITICAL(("Unable to initialise keyboard")); ! 161: return 1; ! 162: } ! 163: if (uip_bank0->y_ofs != 0 || uip_bank1->y_ofs != 480) { ! 164: uip_textmode(); ! 165: LOG_CRITICAL(("sorry, I don't understand this video layout")); ! 166: return 1; ! 167: } ! 168: keyboard_lowlevel_callback = uip_keyboardhandler; ! 169: uip_keypoll = keyboard_needs_poll() ? 1 : 0; ! 170: return 0; ! 171: } ! 172: ! 173: int uip_setcolourbits(int red, int green, int blue) ! 174: { ! 175: uip_forceredshift = red; ! 176: uip_forcegreenshift = green; ! 177: uip_forceblueshift = blue; ! 178: return 0; ! 179: } ! 180: ! 181: void uip_displaybank(int bank) { ! 182: if (bank == -1) ! 183: bank = uip_displaybanknum ^ 1; ! 184: uip_writebank = bank ? uip_bank0 : uip_bank1; ! 185: if (show_video_bitmap(bank ? uip_bank1 : uip_bank0)) ! 186: ui_err("Failed to page flip"); ! 187: uip_uipinfo->screenmem_w = bank ? uip_uipinfo->screenmem0 : ! 188: uip_uipinfo->screenmem1; ! 189: uip_displaybanknum = bank; ! 190: } ! 191: ! 192: void uip_clearscreen(void) { ! 193: int y; ! 194: ! 195: for (y = 0; y < 480; y++) { ! 196: memset(uip_uipinfo->screenmem_w+uip_uipinfo->linewidth*y, 0, 640*2); ! 197: } ! 198: } ! 199: ! 200: void uip_clearmiddle(void) { ! 201: int i; ! 202: ! 203: for (i = 0; i < 240; i++) { ! 204: memset(uip_uipinfo->screenmem_w+(uip_uipinfo->linewidth)*(120+i)+ ! 205: 160*2, 0, 2*320); ! 206: } ! 207: } ! 208: ! 209: /* uip_singlebank sets write address to the current display screen */ ! 210: ! 211: void uip_singlebank(void) { ! 212: uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem1 : ! 213: uip_uipinfo->screenmem0; ! 214: } ! 215: ! 216: /* uip_doublebank sets write address to hidden display screen */ ! 217: ! 218: void uip_doublebank(void) { ! 219: uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem0 : ! 220: uip_uipinfo->screenmem1; ! 221: } ! 222: ! 223: void uip_textmode(void) ! 224: { ! 225: if (uip_vga) { ! 226: remove_keyboard(); ! 227: set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); ! 228: } ! 229: uip_vga = 0; ! 230: } ! 231: ! 232: int uip_checkkeyboard(void) ! 233: { ! 234: if (uip_keypoll) ! 235: poll_keyboard(); ! 236: mem68k_cont1_a = key[KEY_A] ? 1 : 0; ! 237: mem68k_cont1_b = (key[KEY_B] || ! 238: key[KEY_S]) ? 1 : 0; ! 239: mem68k_cont1_c = (key[KEY_C] || ! 240: key[KEY_D]) ? 1 : 0; ! 241: mem68k_cont1_left = key[KEY_LEFT] ? 1 : 0; ! 242: mem68k_cont1_up = key[KEY_UP] ? 1 : 0; ! 243: mem68k_cont1_right = key[KEY_RIGHT] ? 1 : 0; ! 244: mem68k_cont1_down = key[KEY_DOWN] ? 1 : 0; ! 245: mem68k_cont1_start = key[KEY_ENTER] ? 1 : 0; ! 246: return (key[KEY_ESC] ? 1 : 0); ! 247: } ! 248: ! 249: unsigned int uip_whichbank(void) ! 250: { ! 251: /* returns 0 or 1 - the bank being VIEWED */ ! 252: return uip_displaybanknum; ! 253: } ! 254: ! 255: void uip_vsync(void) ! 256: { ! 257: vsync(); ! 258: } ! 259: ! 260: uint8 uip_getchar(void) ! 261: { ! 262: char c; ! 263: ! 264: keyboard_lowlevel_callback = NULL; ! 265: c = readkey() & 0xff; ! 266: keyboard_lowlevel_callback = uip_keyboardhandler; ! 267: return c; ! 268: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.