⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui.c

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************//*                                                                            *//*                  RAINE GUI: Based on allegro GUI routines                  *//*                                                                            *//******************************************************************************/#include <stdio.h>#include <ctype.h>#include <string.h>#include "raine.h"#include "emumain.h"#include "gui.h"#include "gui2.h"#include "default.h"#include "dsw.h"#include "ingame.h"#include "arpro.h"#include "control.h"#include "sasound.h"#include "config.h"#include "games.h"#include "tilemod.h"#include "palette.h"#include "hiscore.h"#include "loadroms.h"#include "newmem.h"#include "dlg_sound.h"#include "debug.h"#include "savegame.h"#ifndef RAINE_WIN32#include "arcmon.h"#endifPALETTE gui_pal;static   BITMAP *snapshot=NULL;static int snapshot_cols;#ifdef RAINE_UNIX#ifndef ALLEGRO_LINUX // These are not defined by freebsd, but they could...static inline unsigned char inportb(unsigned short port){   unsigned char value;   __asm__ volatile ("inb %1, %0" : "=a" (value) : "d" (port));   return value;}static inline void outportb(unsigned short port, unsigned char value){   __asm__ volatile ("outb %0, %1" : : "a" (value), "d" (port));}static inline void outportw(unsigned short port, unsigned short value){   __asm__ volatile ("outw %0, %1" : : "a" (value), "d" (port));}#endif#define outp(a,b)	outportb(a,b)#define inp(a)	        inportb(a)/* #define strcasecmp	_stricmp */#endif#define enable()        asm(" sti")#define disable()       asm(" cli")#if defined( RAINE_WIN32 )#define strcasecmp stricmp#endif// Size of the game list box#define GLIST_SIZE 12extern int bestw, besth,bestbpp; // rgui.c to switch modeint screen_valid;	// 1 if screen contains a valid imageint wants_switch_res = 0;static int WantScreen;static int WantQuit;static int WantPlay;#if 0#define MAX_NAME_BUFFER 60#define BOARD_POS 32 // Position of the board name...static char name_buffer[MAX_NAME_BUFFER];#endifgamestr game_select_string1;gamestr game_company,game_year,game_sound,game_strtype;gamestr pad_buf;int allocate_pens(int pens);void free_pens(int pens);void free_all_pens(void);void free_game_avail_list(void);/*raine_centre_dialog(): centre a dialog onscreen*/static int scale = 8;void raine_centre_dialog(DIALOG *dialog){   int min_x, min_y;   int max_x, max_y;   int dx, dy;   int i, new_scale;   /*   place window at (0,0)   */   dx = dialog[0].x;   dy = dialog[0].y;   for(i=0; dialog[i].proc; i++){        dialog[i].x -= dx;      dialog[i].y -= dy;   }   /*   scale window   */   new_scale = text_height(gui_main_font);   for(i=0; dialog[i].proc; i++){        dialog[i].x = (dialog[i].x * new_scale) / scale;      dialog[i].y = (dialog[i].y * new_scale) / scale;      dialog[i].w = (dialog[i].w * new_scale) / scale;      dialog[i].h = (dialog[i].h * new_scale) / scale;   }   /*   centre window   */   min_x = dialog[0].x;   min_y = dialog[0].y;   max_x = dialog[0].x + dialog[0].w;   max_y = dialog[0].y + dialog[0].h;   dx = (SCREEN_W - (max_x - min_x)) / 2 - min_x;   dy = (SCREEN_H - (max_y - min_y)) / 2 - min_y;   for(i=0; dialog[i].proc; i++){      dialog[i].x += dx;      dialog[i].y += dy;   }}static DATAFILE *font_data;static void setup_font() {  if(rgui_cfg.font_datafile[0])     font_data = load_datafile(rgui_cfg.font_datafile);   if (display_cfg.screen_x >= 640 && display_cfg.screen_y >= 480)     font_data = load_datafile("bigfont.dat");   else if(!rgui_cfg.font_datafile[0]) {     unload_datafile(font_data);     font_data = NULL;   }      if(font_data){     gui_main_font     = font_data[2].dat;     gui_fixed_font    = font_data[1].dat;     ingame_font       = font_data[0].dat;     font              = gui_main_font;   } else {     gui_main_font     = RaineData[font_gui_main].dat;     gui_fixed_font    = RaineData[font_gui_fixed].dat;     ingame_font       = RaineData[font_8x8_ingame].dat;     font              = gui_main_font;   }}/*centre_all_dialogs(): centre all raine dialogs*/static void centre_all_dialogs(void){   UINT32 i;      setup_font();      i = 0;         while(raine_dialog_list[i])      raine_centre_dialog( raine_dialog_list[i++] );   scale = text_height(gui_main_font);   MakeGUIBack();}// Unselect_Button():// Force a Button object to redraw itself unselected+unfocused// Otherwise, they don't get redrawn till after the button's action// (which looks ugly...).void Unselect_Button(DIALOG *d){   d->flags &= ~(D_SELECTED|D_GOTFOCUS);     scare_mouse();   x_raine_button_proc(MSG_DRAW,d,0);     unscare_mouse();   //dialog_oxygen();}UINT32 darken(UINT32 src){   UINT32 r,g,b;   r = (src >> 16) & 0xFF;   g = (src >>  8) & 0xFF;   b = (src >>  0) & 0xFF;   r = (r * 0x100) / 0x148;   g = (g * 0x100) / 0x148;   b = (b * 0x100) / 0x148;   return (r<<16) | (g<<8) | (b<<0);}int CGUI_COL_TEXT_1,CGUI_COL_TEXT_2,CGUI_COL_BLACK,  CGUI_BOX_COL_HIGH_2,CGUI_BOX_COL_HIGH_1,CGUI_BOX_COL_MIDDLE,  CGUI_BOX_COL_LOW_1,CGUI_BOX_COL_LOW_2,CGUI_COL_SELECT;void set_gui_palette(void){   gui_pal[GUI_COL_TEXT_1].r=(rgui_cfg.gui_col_text_1>>18)&0x3F;   gui_pal[GUI_COL_TEXT_1].g=(rgui_cfg.gui_col_text_1>>10)&0x3F;   gui_pal[GUI_COL_TEXT_1].b=(rgui_cfg.gui_col_text_1>>2)&0x3F;   SET_PAL(GUI_COL_TEXT_1);   gui_pal[GUI_COL_TEXT_2].r=(rgui_cfg.gui_col_text_2>>18)&0x3F;   gui_pal[GUI_COL_TEXT_2].g=(rgui_cfg.gui_col_text_2>>10)&0x3F;   gui_pal[GUI_COL_TEXT_2].b=(rgui_cfg.gui_col_text_2>>2)&0x3F;   SET_PAL(GUI_COL_TEXT_2);   gui_pal[GUI_COL_BLACK].r=(rgui_cfg.gui_col_black>>18)&0x3F;   gui_pal[GUI_COL_BLACK].g=(rgui_cfg.gui_col_black>>10)&0x3F;   gui_pal[GUI_COL_BLACK].b=(rgui_cfg.gui_col_black>>2)&0x3F;   SET_PAL(GUI_COL_BLACK);   gui_pal[GUI_COL_SELECT].r=(rgui_cfg.gui_col_select>>18)&0x3F;   gui_pal[GUI_COL_SELECT].g=(rgui_cfg.gui_col_select>>10)&0x3F;   gui_pal[GUI_COL_SELECT].b=(rgui_cfg.gui_col_select>>2)&0x3F;   SET_PAL(GUI_COL_SELECT);   gui_pal[GUI_BOX_COL_HIGH_2].r=(rgui_cfg.gui_box_col_high_2>>18)&0x3F;   gui_pal[GUI_BOX_COL_HIGH_2].g=(rgui_cfg.gui_box_col_high_2>>10)&0x3F;   gui_pal[GUI_BOX_COL_HIGH_2].b=(rgui_cfg.gui_box_col_high_2>>2)&0x3F;   SET_PAL(GUI_BOX_COL_HIGH_2);   gui_pal[GUI_BOX_COL_HIGH_1].r=(rgui_cfg.gui_box_col_high_1>>18)&0x3F;   gui_pal[GUI_BOX_COL_HIGH_1].g=(rgui_cfg.gui_box_col_high_1>>10)&0x3F;   gui_pal[GUI_BOX_COL_HIGH_1].b=(rgui_cfg.gui_box_col_high_1>>2)&0x3F;   SET_PAL(GUI_BOX_COL_HIGH_1);   gui_pal[GUI_BOX_COL_MIDDLE].r=(rgui_cfg.gui_box_col_middle>>18)&0x3F;   gui_pal[GUI_BOX_COL_MIDDLE].g=(rgui_cfg.gui_box_col_middle>>10)&0x3F;   gui_pal[GUI_BOX_COL_MIDDLE].b=(rgui_cfg.gui_box_col_middle>>2)&0x3F;   SET_PAL(GUI_BOX_COL_MIDDLE);   gui_pal[GUI_BOX_COL_LOW_1].r=(rgui_cfg.gui_box_col_low_1>>18)&0x3F;   gui_pal[GUI_BOX_COL_LOW_1].g=(rgui_cfg.gui_box_col_low_1>>10)&0x3F;   gui_pal[GUI_BOX_COL_LOW_1].b=(rgui_cfg.gui_box_col_low_1>>2)&0x3F;   SET_PAL(GUI_BOX_COL_LOW_1);   gui_pal[GUI_BOX_COL_LOW_2].r=(rgui_cfg.gui_box_col_low_2>>18)&0x3F;   gui_pal[GUI_BOX_COL_LOW_2].g=(rgui_cfg.gui_box_col_low_2>>10)&0x3F;   gui_pal[GUI_BOX_COL_LOW_2].b=(rgui_cfg.gui_box_col_low_2>>2)&0x3F;   SET_PAL(GUI_BOX_COL_LOW_2);   gui_pal[DGUI_COL_TEXT_1].r=(darken(rgui_cfg.gui_col_text_1)>>18)&0x3F;   gui_pal[DGUI_COL_TEXT_1].g=(darken(rgui_cfg.gui_col_text_1)>>10)&0x3F;   gui_pal[DGUI_COL_TEXT_1].b=(darken(rgui_cfg.gui_col_text_1)>>2)&0x3F;   gui_pal[DGUI_COL_TEXT_2].r=(darken(rgui_cfg.gui_col_text_2)>>18)&0x3F;   gui_pal[DGUI_COL_TEXT_2].g=(darken(rgui_cfg.gui_col_text_2)>>10)&0x3F;   gui_pal[DGUI_COL_TEXT_2].b=(darken(rgui_cfg.gui_col_text_2)>>2)&0x3F;   gui_pal[DGUI_BOX_COL_HIGH_2].r=(darken(rgui_cfg.gui_box_col_high_2)>>18)&0x3F;   gui_pal[DGUI_BOX_COL_HIGH_2].g=(darken(rgui_cfg.gui_box_col_high_2)>>10)&0x3F;   gui_pal[DGUI_BOX_COL_HIGH_2].b=(darken(rgui_cfg.gui_box_col_high_2)>>2)&0x3F;   gui_pal[DGUI_BOX_COL_HIGH_1].r=(darken(rgui_cfg.gui_box_col_high_1)>>18)&0x3F;   gui_pal[DGUI_BOX_COL_HIGH_1].g=(darken(rgui_cfg.gui_box_col_high_1)>>10)&0x3F;   gui_pal[DGUI_BOX_COL_HIGH_1].b=(darken(rgui_cfg.gui_box_col_high_1)>>2)&0x3F;   gui_pal[DGUI_BOX_COL_MIDDLE].r=(darken(rgui_cfg.gui_box_col_middle)>>18)&0x3F;   gui_pal[DGUI_BOX_COL_MIDDLE].g=(darken(rgui_cfg.gui_box_col_middle)>>10)&0x3F;   gui_pal[DGUI_BOX_COL_MIDDLE].b=(darken(rgui_cfg.gui_box_col_middle)>>2)&0x3F;   gui_pal[DGUI_BOX_COL_LOW_1].r=(darken(rgui_cfg.gui_box_col_low_1)>>18)&0x3F;   gui_pal[DGUI_BOX_COL_LOW_1].g=(darken(rgui_cfg.gui_box_col_low_1)>>10)&0x3F;   gui_pal[DGUI_BOX_COL_LOW_1].b=(darken(rgui_cfg.gui_box_col_low_1)>>2)&0x3F;   gui_pal[DGUI_BOX_COL_LOW_2].r=(darken(rgui_cfg.gui_box_col_low_2)>>18)&0x3F;   gui_pal[DGUI_BOX_COL_LOW_2].g=(darken(rgui_cfg.gui_box_col_low_2)>>10)&0x3F;   gui_pal[DGUI_BOX_COL_LOW_2].b=(darken(rgui_cfg.gui_box_col_low_2)>>2)&0x3F;}// FadeGUI():// Remaps screen image of gui to darker colours. Used to 'fade out'// Inactive gui areasvoid FadeGUI(void){   BITMAP *fade_backdrop;   UINT8 *BIT;   UINT32 ta,tb;   UINT8 convert[256];   if (display_cfg.bpp == 8) {          for(ta=0;ta<256;ta++){       convert[ta]=ta;     }     convert[GUI_COL_TEXT_1]      = DGUI_COL_TEXT_1;     convert[GUI_COL_TEXT_2]      = DGUI_COL_TEXT_2;     convert[GUI_COL_BLACK]       = GUI_COL_BLACK;     convert[GUI_COL_SELECT]      = DGUI_BOX_COL_MIDDLE;     convert[GUI_BOX_COL_HIGH_2]  = DGUI_BOX_COL_HIGH_2;     convert[GUI_BOX_COL_HIGH_1]  = DGUI_BOX_COL_HIGH_1;     convert[GUI_BOX_COL_MIDDLE]  = DGUI_BOX_COL_MIDDLE;     convert[GUI_BOX_COL_LOW_1]   = DGUI_BOX_COL_LOW_1;     convert[GUI_BOX_COL_LOW_2]   = DGUI_BOX_COL_LOW_2;      // This bitmap must be created in 8bpp because of the palette effects     fade_backdrop = create_bitmap_ex(8, display_cfg.screen_x,display_cfg.screen_y);       scare_mouse();     blit(screen,fade_backdrop,0,0,0,0,display_cfg.screen_x,display_cfg.screen_y);     for(tb=0;tb<(UINT32)display_cfg.screen_y;tb++){       BIT=fade_backdrop->line[tb];       for(ta=0;ta<(UINT32)display_cfg.screen_x;ta++){         BIT[ta]=convert[BIT[ta]];       }     }     blit(fade_backdrop,screen,0,0,0,0,display_cfg.screen_x,display_cfg.screen_y);       unscare_mouse();       destroy_bitmap(fade_backdrop);   }      //dialog_oxygen();}#ifndef RAINE_WIN32static DEF_INLINE void WaitVBlank(void){  while(inportb(0x3DA)&0x08);  while(!(inportb(0x3DA)&0x08));}static int Stretch256x240(int SType){   static UINT8 fwnesdata[] = {   0x4F,0x3F,0x40,0x92,0x46,0x10,0x0D,0x3E,   0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,   0xEA,0xAC,0xDF,0x20,0x00,0xE7,0x06,0xE3   };   int ta,ret;   if(display_cfg.triple_buffer)      ret = set_gfx_mode(SType,256,240,256,240*3);   else      ret = set_gfx_mode(SType,256,240,256,240);   if(!ret){   disable();   WaitVBlank();   //outportw(0x3C4,0x100);   outportb(0x3C2,0xE3);   //outportw(0x3C4,0x300);   outportw(0x3D4,((fwnesdata[0x11]&0x7F)<<8)+0x11);   for(ta=0;ta<24;ta++){      outportw(0x3D4,(fwnesdata[ta]<<8)+ta);   }   //inportb(0x3DA);   //outportb(0x3c0,0x31);   //outportb(0x3c0,0x3f);   inportb(0x3DA);   //outportb(0x3C0,0x11  | 0x20);   //outportb(0x3C0,0x40);   enable();   }   return ret;}// SetDarkForceMode():// Set a normal vesa mode (via allegro), then divide// the number of screen lines...static int SetDarkForceMode(int SType, int SX, int SY, int NewSY){   int ret,lines;   UINT8 scanline;   if(display_cfg.triple_buffer)      ret = set_gfx_mode(SType,SX,SY,SX,NewSY*3);   else      ret = set_gfx_mode(SType,SX,SY,SX,SY);   if(!ret){      lines=SY/NewSY;      if(lines<1)lines=1;      if(lines>4)lines=4;      outp(0x3D4,0x09);		// CRTC Register index 9      scanline=inp(0x3D5);	// get scanline height      scanline&=0x60;		// clear any existing bits      scanline|=(lines-1);	// set multiply bits      outp(0x3D5,scanline); 	// set new line height         }   return ret;}// Set320x256():// Set a normal mode-x mode (via allegro), then twiddle// the vga registers and the vtablestatic int Set320x256(int SType){   int n,ret;   UINT16 port;   UINT8 *q,reg,data;   static unsigned char gfx_320x256_data[] = {      194,3,0,227,212,3,0,95,212,3,1,79,212,3,2,80,212,3,3,130,212,3,4,84,212,3,5,154,212,3,6,35,212,      3,7,178,212,3,8,0,212,3,9,97,212,3,16,10,212,3,17,172,212,3,18,255,212,3,19,40,212,3,20,0,212,3,      21,7,212,3,22,26,212,3,23,227,196,3,1,1,196,3,4,6,206,3,5,64,206,3,6,5,192,3,16,65,192,3,19,      0,};   if(display_cfg.triple_buffer)      ret = set_gfx_mode(SType,320,480,320,256*3);   else      ret = set_gfx_mode(SType,320,480,320,256);   if(ret)      return ret;   disable();   WaitVBlank();   /* ready the vga registers */   outp(0x3d4,0x11);   data = inp(0x3d5) & 0x7f;   outp(0x3d4,0x11);   outp(0x3d5,data);   n = 25;   q = &gfx_320x256_data[0];   do {      port = *q++;      port |= ((*q++) << 8);      reg = *q++;      data = *q++;      switch(port)      {      case 0x3c0:         inp(0x3da);         /* reset read/write flip-flop */         outp(0x3c0, reg | 0x20);                                 /* ensure VGA output is enabled */         outp(0x3c0, data);         break;      case 0x3c2:      case 0x3c3:         outp(port, data);   /* directly to the port */			break;      case 0x3c4:      case 0x3ce:      case 0x3d4:      default:                   /* This is the default method: */         outp(port, reg);    /* index to port               */         outp(port+1, data); /* value to port+1             */			break;      }   } while(--n);   enable();   screen->h = 256;   set_clip(screen, 0,0,319,255);   return ret;}static int set_arcade_mode(int SType, int SX, int SY){   int ret=1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -