Annotation of generator/src/uip-allegro.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.