void savescreen(String fname) { #ifdef ALLEGRO PALETTE pal; get_palette(pal); save_bitmap(fname,screen,pal); #endif }
/* * IOCTL entry point -- This method is called to carry * all services of this interface. */ rtems_device_driver frame_buffer_control( rtems_device_major_number major, rtems_device_minor_number minor, void *arg ) { rtems_libio_ioctl_args_t *args = arg; printk( "FBVGA ioctl called, cmd=%x\n", args->command ); switch( args->command ) { case FBIOGET_FSCREENINFO: args->ioctl_return = get_fix_screen_info( ( struct fb_fix_screeninfo * ) args->buffer ); break; case FBIOGET_VSCREENINFO: args->ioctl_return = get_var_screen_info( ( struct fb_var_screeninfo * ) args->buffer ); break; case FBIOPUT_VSCREENINFO: /* not implemented yet*/ args->ioctl_return = -1; return RTEMS_UNSATISFIED; case FBIOGETCMAP: args->ioctl_return = get_palette( ( struct fb_cmap * ) args->buffer ); break; case FBIOPUTCMAP: args->ioctl_return = set_palette( ( struct fb_cmap * ) args->buffer ); break; default: args->ioctl_return = 0; break; } return RTEMS_SUCCESSFUL; }
void ss_saver() { PALETTE pal; get_palette(pal); acquire_screen(); save_pcx("ss.pcx", screen, pal); release_screen(); }
void draw_mouse_frame (ALLEGRO_BITMAP *bitmap, struct anim *m, enum vm vm) { if (m->invisible) return; struct frame f = m->f; palette pal = get_palette (vm); f.b = apply_palette (f.b, pal); if (hgc) f.b = apply_palette (f.b, hgc_palette); draw_frame (bitmap, &f); }
void TileRepository::exportBitmap(const char *filename, int tile_w, int tile_h, int tile_spacing, int tiles_in_row) { list<TileType*> tiles_to_save; map<const char*, TileType*, ltstr>::iterator i; list<TileType*>::iterator j; char tempTilename[256]; char tempFilename[256]; replace_extension(tempFilename, get_filename(filename), "", 256); if (!(tiles_in_row > 0 && tile_w > 0 && tile_h > 0)) { allegro_message("WARNING: tiles_in_row (%d), tile_w (%d) and tile_h (%d) must all be larger than 0.", tiles_in_row, tile_w, tile_h); return; } for (i = tileTypes.begin(); i != tileTypes.end(); i++) { TileType* tempTileType = (*i).second; replace_extension(tempTilename, tempTileType->getName(), "", 256); if (ustrcmp(tempFilename, tempTilename) == 0) { tiles_to_save.push_back(tempTileType); } } if (tiles_to_save.empty()) { allegro_message("WARNING: No tiles to save in %s.", filename); return; } BITMAP *tile_bitmap; PALETTE pal; tile_bitmap = create_bitmap ( tiles_in_row * tile_w, (tiles_to_save.size() / tiles_in_row + tiles_to_save.size() % tiles_in_row) * tile_h ); int x = 0; int y = 0; for (j = tiles_to_save.begin(); j != tiles_to_save.end(); j++) { blit((*j)->getBitmap(), tile_bitmap, 0, 0, x * tile_w, y * tile_h, tile_w, tile_h); x++; if (x == tiles_in_row) { y++; x = 0; } } get_palette(pal); save_bitmap(filename, tile_bitmap, pal); destroy_bitmap(tile_bitmap); }
void make_screenshot(BITMAP *bmp) { std::string filename; char buf[1024]; for (int c=0; c<10000; ++c) { sprintf(buf, "shot%04d.bmp", c); filename = redir(buf); if (!exists(filename.c_str())) { PALETTE pal; get_palette(pal); save_bitmap(filename.c_str(), bmp, pal); break; } } }
void PPU::flush_pixel_cache() { uint16 main = get_palette(0); uint16 sub = (regs.pseudo_hires || regs.bg_mode == 5 || regs.bg_mode == 6) ? main : regs.color_rgb; unsigned i = 255; do { pixel_cache[i].src_main = main; pixel_cache[i].src_sub = sub; pixel_cache[i].bg_main = BACK; pixel_cache[i].bg_sub = BACK; pixel_cache[i].ce_main = false; pixel_cache[i].ce_sub = false; pixel_cache[i].pri_main = 0; pixel_cache[i].pri_sub = 0; } while(i--); }
void main() { allegrosetup(scrwid,scrhei); makepalette(&greypalette); _farsetsel(screen->seg); PALETTE pal; get_palette(pal); randomise(0.456); for (int i=0;i<20;i++) { S s=S(V3d::randomvolume(1),0,0); S v=S(V3d(0,0,0),0,0); xs+s; xvs+v; } for (int rndloop=0;rndloop<100;rndloop++) { for (int i=0;i<xs.len;i++) { S *v=xvs.p2num(i); S *x=xs.p2num(i); domovement(v,x); } } do { rend->clear(crazy); for (int i=0;i<scrhei;i+=jump) { for (int j=0;j<scrhei;j+=jump) { fillsquare(i,j,jump,jump); } b->writetoscreen(); } for (int lkg=0;lkg<1;lkg++) for (int i=1;i<=xs.len;i++) { S *v=xvs.p2num(i); S *x=xs.p2num(i); domovement(v,x); } b->writefile(getnextfilename("bmp")); } while (!key[KEY_ESC]); }
bool Morph::run (Audio const& audio, VideoPtr const& src1, VideoPtr const& src2) { visual_return_val_if_fail (src1, FALSE); visual_return_val_if_fail (src2, FALSE); auto morph_plugin = m_impl->get_morph_plugin (); // If we're morphing using the timer, start the timer if (!m_impl->timer.is_active ()) { m_impl->timer.start (); } if (morph_plugin->palette) { morph_plugin->palette (m_impl->plugin, m_impl->progress, const_cast<Audio*> (&audio), m_impl->morphpal, src1.get (), src2.get ()); } else { auto const& src1_pal = src1->get_palette (); auto const& src2_pal = src2->get_palette (); //if (src1_pal && src2_pal) { m_impl->morphpal->blend (src1_pal, src2_pal, m_impl->progress); //} } morph_plugin->apply (m_impl->plugin, m_impl->progress, const_cast<Audio*> (&audio), m_impl->dest.get (), src1.get (), src2.get ()); m_impl->dest->set_palette (*get_palette ()); // Update morph progression double usec_elapsed = m_impl->timer.elapsed ().to_usecs (); double usec_morph = m_impl->morphtime.to_usecs (); m_impl->progress = std::min (std::max (usec_elapsed / usec_morph, 0.0), 1.0); return true; }
/* Check user interface keys */ void check_ui_keys(void) { if(check_key(KEY_TILDE)) { static const char *msg[] = {"EMU2413", "YM2413"}; if(snd.fm_which == SND_EMU2413) snd.fm_which = SND_YM2413; else snd.fm_which = SND_EMU2413; add_msg("Using %s FM sound emulator.", msg[snd.fm_which]); sound_init(); } /* Frame skip keys */ if(check_key(KEY_F1)) { frame_skip = 1; add_msg("Frame skip disabled"); }; if(check_key(KEY_F2)) { frame_skip = 2; add_msg("Frame skip set to 1"); }; if(check_key(KEY_F3)) { frame_skip = 3; add_msg("Frame skip set to 2"); }; if(check_key(KEY_F4)) { frame_skip = 4; add_msg("Frame skip set to 3"); }; /* State save/load keys */ if(check_key(KEY_F5)) { if(save_state()) add_msg("State saved to slot %d", state_slot); }; if(check_key(KEY_F6)) { state_slot = (state_slot + 1) % 10; add_msg("Slot %d", state_slot); }; if(check_key(KEY_F7)) { if(load_state()) add_msg("State loaded from slot %d", state_slot); }; /* Screen snapshot */ if(check_key(KEY_F8)) { char name[PATH_MAX]; PALETTE snap_pal; BITMAP *snap_bmp = create_bitmap_ex(option.video_depth, bitmap.viewport.w, bitmap.viewport.h); if(snap_bmp) { int i; /* Get current palette */ get_palette(snap_pal); /* Remove unused palette entries */ for(i = 0x20; i < 0xFE; i++) snap_pal[i].r = snap_pal[i].g = snap_pal[i].b = 0x00; /* Clip image */ blit(sms_bmp, snap_bmp, bitmap.viewport.x, bitmap.viewport.y, 0, 0, bitmap.viewport.w, bitmap.viewport.h); /* Generate file name */ sprintf(name, "snap%04d.pcx", snap_count); /* Remove unused bits */ if(option.video_depth == 8) { int x, y; for(y = 0; y < bitmap.viewport.h; y++) for(x = 0; x < bitmap.viewport.w; x++) putpixel(snap_bmp, x, y, getpixel(snap_bmp, bitmap.viewport.x + x, bitmap.viewport.y + y) & PIXEL_MASK); } /* Save snapshot in PCX format */ save_pcx(name, snap_bmp, snap_pal); /* Deallocate temporary bitmap */ destroy_bitmap(snap_bmp); /* Bump snapshot counter */ snap_count = (snap_count + 1) & 0xFFFF; /* Display results */ add_msg("Saved screen to %s", name); } } /* FPS meter toggle */ if(check_key(KEY_F9)) { option.fps ^= 1; add_msg("FPS meter %s", option.fps ? "on" : "off"); } /* Speed throttling */ if(check_key(KEY_F10)) { if(!option.sound) { option.throttle ^= 1; add_msg("Speed throttling %s", option.throttle ? "on" : "off"); } } /* Speed throttling */ if(check_key(KEY_F11)) { option.vsync ^= 1; add_msg("VSync %s", option.vsync ? "on" : "off"); } /* Exit keys */ if(key[KEY_ESC] || key[KEY_END]) running = 0; }
void handle_key(void){ if (NeedsPoll) poll_keyboard(); if (key[syskeys[0]] || key[KEY_ESC]) { do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[0]] || key[KEY_ESC]); key_done=1; } if (key[syskeys[1]]) { do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[1]]); mute_audio(); mute_voice(); abaut(); do { rest(5); if (NeedsPoll) poll_keyboard(); if (key[KEY_ALT] && key[KEY_ENTER]) { app_data.fullscreen = app_data.fullscreen ? 0 : 1; grmode(); abaut(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[KEY_ENTER]); } } while ((!key[syskeys[1]]) && (!key[KEY_ESC]) && (!key[syskeys[0]])); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[1]]); init_sound_stream(); } if (key[syskeys[5]]) { if (savestate(app_data.statefile)==0) { display_msg("Savefile saved.",5); } do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[5]]); } /* LOAD STATE */ if (key[syskeys[6]]) { int stateError; if ((stateError=loadstate(app_data.statefile))==0) { display_msg("Savefile loaded.",5); } else if (stateError>=199) { if (stateError==199) display_msg("Wrong ROM-File for Savefile.",5); else if (stateError==200+ROM_O2) display_msg("Wrong BIOS for Savefile: O2ROM needed.",5); else if (stateError==200+ROM_G7400) display_msg("Wrong BIOS for Savefile: G7400 ROM needed.",5); else if (stateError==200+ROM_C52) display_msg("Wrong BIOS for Savefile: C52 ROM needed.",5); else if (stateError==200+ROM_JOPAC) display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.",5); else display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.",5); } do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[6]]); } if (key[syskeys[2]]) key_debug=1; if (key[syskeys[3]]) { init_cpu(); init_roms(); init_vpp(); clearscr(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[3]]); } /* SET HIGHSCORE */ if (key[syskeys[7]]) { set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore); } if (key[syskeys[4]]) { BITMAP *bmp; PALETTE pal; char *p; static char name[1024]; static int scshot_counter = 0; if (strlen(app_data.scshot)>0){ if ((p=strchr(app_data.scshot,'@'))) { *p = 0; sprintf(name, "%s%02d%s", app_data.scshot, scshot_counter++, p+1); *p = '@'; } else { strcpy(name, app_data.scshot); } get_palette(pal); bmp = create_sub_bitmap(screen, 0, 0, SCREEN_W, SCREEN_H); save_bitmap(name, bmp, pal); destroy_bitmap(bmp); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[4]]); } } // switch joystick if (key[syskeys[8]]) { joyswitch = joyswitch ? 0 : 1; set_defjoykeys(0,joyswitch); set_defjoykeys(1,joyswitch ? 0 : 1); int tmp = app_data.stick[0]; app_data.stick[0] = app_data.stick[1]; app_data.stick[1] = tmp; do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[8]]); } if (key[KEY_ALT] && key[KEY_ENTER]) { app_data.fullscreen = app_data.fullscreen ? 0 : 1; grmode(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[KEY_ENTER]); } }
/** * \ingroup Main * * \brief Desenha uma rede no Allegro e imprime num arquivo de imagem. * * \details Esta funcao utiliza a biblioteca grafica Allegro para imprimir uma rede de Petri. * * \param[in] rede A variavel \a rede seria a rede de Petri. * * \param[in] fname A variavel \a fname representa o nome do arquivo que sera gerado. * * \retval void a funcao retorna nada. * */ void desenha_rede(petri_t *rede, const char *fname) { float ang, /* Angulacao antre cada elemento na imagem */ r_lugar, /* Raio da circunferencia que representa o lugar */ smaller, /* A menor das dimensoes da imagem */ x, /* Variavel geral para representar coordenada X */ y, /* Variavel geral para representar coordenada Y */ x1, /* Variavel geral para representar coordenada X */ y1, /* Variavel geral para representar coordenada Y */ x2, /* Variavel geral para representar coordenada X */ y2, /* Variavel geral para representar coordenada Y */ x3, /* Variavel geral para representar coordenada X */ y3, /* Variavel geral para representar coordenada Y */ co, /* Variavel geral para representar cosseno */ si; /* Variavel geral para representar seno */ unsigned i, q; lugar *a_l = rede->l; BITMAP *buff; PALETTE pal; flecha *a_tl = rede->tl, *a_lt = rede->lt; /* Inicializacao Allegro */ if(install_allegro(SYSTEM_NONE, &errno, atexit)!=0) exit(EXIT_FAILURE); set_color_depth(16); get_palette(pal); buff = create_bitmap(IMG_X,IMG_Y); smaller = (float)IMG_X; if(smaller > (float)IMG_Y) smaller = (float)IMG_Y; r_lugar = smaller/4.0*(M_PI/(M_PI+(float)rede->total_l)); if(buff == NULL) { printf("Could not create buffer!\n"); exit(EXIT_FAILURE); } /* Desenho propriamente dito */ if(rede->total_l > rede->total_t) ang = M_PI/rede->total_l; else ang = M_PI/rede->total_t; if(DEBUG == B || DEBUG == D) printf("Desenhando %u lugares e %u transicoes espacados entre si %.2fº...\n", rede->total_l, rede->total_t, ang*180.0/M_PI); /* Desenhando os lugares */ for(i=0;i<rede->total_l;i++) { a_l = buscarLugarPos(rede->l, i); q = 0; if(a_l != NULL) q = a_l->qtd; x = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos(2*i*ang); y = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin(2*i*ang); circle(buff, x, y, r_lugar, CORBRANCO); textprintf_ex(buff, font, x, y, CORVERDE, CORPRETO, "%u", q); if(DEBUG == B || DEBUG == D) printf("L%u(%u) (posicionada %.2fº)\n", i, q, ang*(2*i)*180.0/M_PI); textprintf_ex(buff, font, x, y - r_lugar, CORVERDE, CORPRETO, "L%u", i); } /* Desenhando as transicoes */ for(i=0;i<rede->total_t;i++) { x = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos((2*i+1)*ang); y = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin((2*i+1)*ang); line(buff, x, y+r_lugar, x, y-r_lugar, CORBRANCO); if(DEBUG == B || DEBUG == D) printf("T%u (posicionado %.2fº)\n", i, ang*(2*i+1)*180.0/M_PI); textprintf_ex(buff, font, x, y - r_lugar, CORVERDE, CORPRETO, "T%u", i); } /* Desenhando as flechas */ while(a_tl != NULL) { i = a_tl->de; x1 = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos((2*i+1)*ang); y1 = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin((2*i+1)*ang); i = a_tl->para; x = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos(2*i*ang); y = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin(2*i*ang); co = lcos(x1,y1,x,y); si = lsin(x1,y1,x,y); x -= r_lugar*co; y -= r_lugar*si; line(buff, x1, y1, x, y, CORBRANCO); textprintf_ex(buff, font, (x+x1)/2, (y+y1)/2, CORVERDE, CORPRETO, "%u", a_tl->tk); x2 = x - (r_lugar / 4) * (si + co); y2 = y + (r_lugar / 4) * (co - si); x3 = x + (r_lugar / 4) * (si - co); y3 = y - (r_lugar / 4) * (si + co); triangle(buff, x, y, x2, y2, x3, y3, CORBRANCO); a_tl = a_tl->prox; } while(a_lt != NULL) { i = a_lt->de; x1 = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos(2*i*ang); y1 = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin(2*i*ang); i = a_lt->para; x = IMG_X/2.0 + (IMG_X/2.0 - r_lugar)*cos((2*i+1)*ang); y = IMG_Y/2.0 + (IMG_Y/2.0 - r_lugar)*sin((2*i+1)*ang); co = lcos(x1,y1,x,y); si = lsin(x1,y1,x,y); x1 += r_lugar*co; y1 += r_lugar*si; line(buff, x1, y1, x, y, CORBRANCO); textprintf_ex(buff, font, (x+x1)/2, (y+y1)/2, CORVERDE, CORPRETO, "%u", a_lt->tk); x2 = x - (r_lugar / 4) * (si + co); y2 = y + (r_lugar / 4) * (co - si); x3 = x + (r_lugar / 4) * (si - co); y3 = y - (r_lugar / 4) * (si + co); triangle(buff, x, y, x2, y2, x3, y3, CORBRANCO); a_lt = a_lt->prox; } /* Salvando Imagem */ save_bitmap(fname, buff, pal); destroy_bitmap(buff); allegro_exit(); if(!GIF) printf("Imagem %s salva com sucesso!\n", fname); return; }
void main() { int scrwid=320; int scrhei=200; int indent=(scrwid-scrhei)/2; float cenx=0; float ceny=0; float wid=1.0; float hei=1.0; float left=cenx-wid; float right=cenx+wid; float top=ceny-hei; float bottom=ceny+hei; float front=-1.0; float back=1.0; float scale=2.0/(2.0*front); float crazy=0.1234567; int steps=1000; int jump=1; JBmp *b=new JBmp(scrwid,scrhei); allegrosetup(scrwid,scrhei); makepalette(&greypalette); _farsetsel(screen->seg); randomise(); Map2d<float> *map=new Map2d<float>(scrhei,scrhei); current=*new Quaternion(floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5)); do { current=current*Quaternion(0.99,0,0,0)+Quaternion(floatrnd(-.05,.05),floatrnd(-.05,.05),floatrnd(-.05,.05),floatrnd(-.05,.05)); float dslice=floatrnd(-.3,.3); current=*new Quaternion(floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5)); current=*new Quaternion(-0.488193901,0.572800587,0,0); for (int i=0;i<scrhei;i+=jump) { for (int j=0;j<scrhei;j+=jump) { // b->setpixelud(indent+i,j,255); // b->writetoscreen(); int col=0; V3d tmpnear=V3d(left+2.0*wid*i/(float)scrhei,top+2.0*hei*j/(float)scrhei,front); V3d tmpfar=V3d(tmpnear.x*2.0,tmpnear.y*2.0,back); tmpnear=V3d::rotate(tmpnear,V3d(0,1,0),rotation); tmpfar=V3d::rotate(tmpfar,V3d(0,1,0),rotation); tmpnear=V3d::rotate(tmpnear,V3d(1,0,0),elevation); tmpfar=V3d::rotate(tmpfar,V3d(1,0,0),elevation); Quaternion near=Quaternion(tmpnear.x,tmpnear.y,tmpnear.z,dslice); Quaternion far=Quaternion(tmpfar.x,tmpfar.y,tmpfar.z,dslice); map->pos[i][j]=crazy; Quaternion last=near-(far-near); for (int k=0;k<steps;k++) { float dk=(float)k/(float)steps; Quaternion next=near*(1.0-dk)+far*dk; if (julquat(next)==0) { Quaternion res=searchline(last,next); // col=255.0*(1.0-(res.c-front)/(forget-front)); map->pos[i][j]=res.c; break; } last=next; } if (i>=jump && j>=jump) { if (map->pos[i-jump][j-jump]==crazy || map->pos[i-jump][j]==crazy || map->pos[i][j-jump]==crazy) col=0; else { float diff=2.0*map->pos[i-jump][j-jump]-map->pos[i-jump][j]-map->pos[i][j-jump]; col=chop(128.0+diff*1600.0,0,255); } for (int x=0;x<jump;x++) { for (int y=0;y<jump;y++) { b->setpixel(indent+i+x,j+y,col); } } } if (key[KEY_SPACE]) exit(0); } b->writetoscreen(); } PALETTE pal; get_palette(pal); save_bitmap(getnextfilename("bmp"),screen,pal); } while (!key[KEY_SPACE]); allegro_exit(); }
/* switch_out_fullscreen: * Handles screen switched out. */ static void switch_out_fullscreen(void) { if (_color_depth == 8) get_palette(wddfull_saved_palette); }
void main() { allegrosetup(scrwid,scrhei); makepalette(&greypalette); _farsetsel(screen->seg); PALETTE pal; get_palette(pal); randomise(0.456); for (int i=0;i<20;i++) { float amp=0; S s=S(V3d::randomvolume(1),radfromamp(amp),0); S v=S(V3d(0,0,0),0,0); xs+s; xvs+v; } for (int rndloop=0;rndloop<100;rndloop++) { for (int i=0;i<20;i++) { S *v=xvs.p2num(i); S *x=xs.p2num(i); domovement(v,x); } } do { for (int i=scrhei/3;i<scrhei;i+=jump) { for (int j=0;j<scrhei;j+=jump) { // Shoot ray into image // V3d displace=Quaternion(cenx,ceny,0,0); V3d near=V3d((i-scrwid/2)*2.0/scrhei,(j-scrhei/2)*2.0/scrhei,-2); V3d far=V3d(near.x*2.0,near.y*2.0,2.0); rend->pos[i][j]=back; V3d next,last=near; bool lastin=(getpotentialfor(near)<lessthan); for (int k=1;k<steps;k++) { float dk=(float)k/(float)steps; next=near*(1.0-dk)+far*dk; if ((getpotentialfor(next)<lessthan)!=lastin) { rend->pos[i][j]=searchline(last,next,!lastin).z; break; } last=next; } render(i,j); if (key[KEY_SPACE]) exit(0); } b->writetoscreen(); } for (int i=1;i<=xs.len;i++) { S *v=xvs.p2num(i); S *x=xs.p2num(i); domovement(v,x); } b->writefile(getnextfilename("bmp")); } while (!key[KEY_ESC]); }
static unsigned char *fb_init_driver(unsigned char *param, unsigned char *ignore) { unsigned char *e; struct stat st; int rs; unsigned long ul; TTY = 0; EINTRLOOP(rs, ioctl(TTY,VT_GETMODE, &vt_omode)); if (rs == -1) { TTY = 1; EINTRLOOP(rs, ioctl(TTY,VT_GETMODE, &vt_omode)); if (rs == -1) { TTY = 0; } } kbd_set_raw = 1; fb_old_vd = NULL; fb_driver_param=NULL; if(param != NULL) fb_driver_param=stracpy(param); border_left = border_right = border_top = border_bottom = 0; if (!param) param=cast_uchar ""; if (*param) { if (*param < '0' || *param > '9') { bad_p: if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } return stracpy(cast_uchar "-mode syntax is left_border[,top_border[,right_border[,bottom_border]]]\n"); } ul = strtoul(cast_const_char param, (char **)(void *)¶m, 10); if (ul > MAXINT / 10) goto bad_p; border_left = (int)ul; if (*param == ',') param++; } else { border_left = 0; } if (*param) { if (*param < '0' || *param > '9') goto bad_p; ul = strtoul(cast_const_char param, (char **)(void *)¶m, 10); if (ul > MAXINT / 10) goto bad_p; border_top = (int)ul; if (*param == ',') param++; } else { border_top = border_left; } if (*param) { if (*param < '0' || *param > '9') goto bad_p; ul = strtoul(cast_const_char param, (char **)(void *)¶m, 10); if (ul > MAXINT / 10) goto bad_p; border_right = (int)ul; if (*param == ',') param++; } else { border_right = border_left; } if (*param) { if (*param < '0' || *param > '9') goto bad_p; ul = strtoul(cast_const_char param, (char **)(void *)¶m, 10); if (ul > MAXINT / 10) goto bad_p; border_bottom = (int)ul; if (*param == ',') param++; } else { border_bottom = border_top; } if (*param) goto bad_p; EINTRLOOP(rs, fstat(TTY, &st)); if (rs) { if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } return stracpy(cast_uchar "Cannon stat stdin.\n"); } fb_console = (int)(st.st_rdev & 0xff); fb_hide_cursor(); if ((e = fb_switch_init())) { if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return e; } EINTRLOOP(fb_handle, open("/dev/fb0", O_RDWR)); if (fb_handle==-1) { fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Cannot open /dev/fb0.\n"); } EINTRLOOP(rs, ioctl(fb_handle, FBIOGET_VSCREENINFO, &vi)); if (rs==-1) { EINTRLOOP(rs, close(fb_handle)); fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Cannot get FB VSCREENINFO.\n"); } /*oldmode=vi;*/ EINTRLOOP(rs, ioctl(fb_handle, FBIOGET_FSCREENINFO, &fi)); if (rs==-1) { EINTRLOOP(rs, close(fb_handle)); fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Cannot get FB FSCREENINFO.\n"); } fb_xsize=vi.xres; fb_ysize=vi.yres; fb_bits_pp=vi.bits_per_pixel; if (fb_bits_pp == 16 && vi.green.length == 5) fb_bits_pp = 15; if (fb_xsize <= border_left + border_right) border_left = border_right = 0; fb_xsize -= border_left + border_right; if (fb_ysize <= border_top + border_bottom) border_top = border_bottom = 0; fb_ysize -= border_top + border_bottom; fb_driver.x=fb_xsize; fb_driver.y=fb_ysize; switch(fb_bits_pp) { case 4: fb_pixelsize=1; fb_palette_colors=16; break; case 8: fb_pixelsize=1; fb_palette_colors=256; break; case 15: case 16: fb_pixelsize=2; fb_palette_colors=64; break; case 24: fb_palette_colors=256; fb_pixelsize=3; break; case 32: fb_palette_colors=256; fb_pixelsize=4; fb_bits_pp=24; break; default: EINTRLOOP(rs, close(fb_handle)); fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Unknown bit depth"); } fb_colors=1<<fb_bits_pp; /* we must pan before setting palette */ fb_pan_display(); have_cmap = 0; if (fi.visual==FB_VISUAL_PSEUDOCOLOR && fb_colors <= 0x1000000) /* set palette */ { have_cmap=1; fb_palette_colors=fb_colors; alloc_palette(&old_palette); get_palette(&old_palette); alloc_palette(&global_pal); generate_palette(&global_pal); set_palette(&global_pal); } if (fi.visual==FB_VISUAL_DIRECTCOLOR) /* set pseudo palette */ { have_cmap=2; alloc_palette(&old_palette); get_palette(&old_palette); alloc_palette(&global_pal); generate_palette(&global_pal); set_palette(&global_pal); } fb_linesize=fi.line_length; fb_mem_size=fi.smem_len; if (init_virtual_devices(&fb_driver, NUMBER_OF_DEVICES)){ fb_shutdown_palette(); EINTRLOOP(rs, close(fb_handle)); fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Allocation of virtual devices failed.\n"); } fb_kbd = handle_svgalib_keyboard(fb_key_in); /* Mikulas: nechodi to na sparcu */ if (fb_mem_size < (unsigned)((border_top + fb_ysize + border_bottom) * fb_linesize)) { fb_shutdown_palette(); svgalib_free_trm(fb_kbd); shutdown_virtual_devices(); EINTRLOOP(rs, close(fb_handle)); fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Nonlinear mapping of graphics memory not supported.\n"); } if (vi.nonstd) { fb_shutdown_palette(); svgalib_free_trm(fb_kbd); shutdown_virtual_devices(); EINTRLOOP(rs, close(fb_handle)); fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Non-standard pixel format.\n"); } fb_driver.flags |= GD_DONT_USE_SCROLL; #ifdef USE_FB_ACCEL need_accel_sync = 0; EINTRLOOP(rs, ioctl(fb_handle, FBIO_ACCEL_SUPPORT)); if (rs < 0) { accel_flags = 0; /*debug("accel not supported");*/ } else { accel_flags = rs; /*debug("accel supported, flags %x", accel_flags);*/ } if (fb_bits_pp != 8) accel_flags &= ~(FB_ACCEL_FILLRECT_SUPPORTED | FB_ACCEL_FILLRECT_ACCELERATED); if (accel_flags & FB_ACCEL_COPYAREA_ACCELERATED) fb_driver.flags &= ~GD_DONT_USE_SCROLL; #endif /* * Some framebuffer implementations (for example Mach64) on Sparc64 hate * partial framebuffer mappings. * * For others, we can save virtual memory space by doing a partial mmap. */ fb_mapped_size = (border_top + fb_ysize + border_bottom) * fb_linesize; retry1: if ((fb_mem=mmap(0,fb_mapped_size,PROT_READ|PROT_WRITE,MAP_SHARED,fb_handle,0))==MAP_FAILED) { if (errno == EINTR) goto retry1; fb_mapped_size = fb_mem_size; retry2: if ((fb_mem=mmap(0,fb_mapped_size,PROT_READ|PROT_WRITE,MAP_SHARED,fb_handle,0))==MAP_FAILED) { if (errno == EINTR) goto retry2; fb_shutdown_palette(); svgalib_free_trm(fb_kbd); shutdown_virtual_devices(); EINTRLOOP(rs, close(fb_handle)); fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Cannot mmap graphics memory.\n"); } } fb_vmem = fb_mem + border_left * fb_pixelsize + border_top * fb_linesize; fb_driver.depth=fb_pixelsize&7; fb_driver.depth|=(fb_bits_pp&31)<<3; if (htonl(0x12345678) == 0x12345678) { /* Big endian */ if (fb_driver.depth == 130 || fb_driver.depth == 122) fb_driver.depth |= 1 << 8; else if (fb_driver.depth == 196) fb_driver.depth |= 1 << 9; } fb_driver.get_color=get_color_fn(fb_driver.depth); if (!fb_driver.get_color) { fb_shutdown_palette(); svgalib_free_trm(fb_kbd); shutdown_virtual_devices(); EINTRLOOP(rs, close(fb_handle)); fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Unknown bit format.\n"); } install_signal_handler(SIGINT, (void (*)(void *))fb_ctrl_c, fb_kbd, 0); /* mouse */ mouse_buffer=mem_alloc(fb_pixelsize*arrow_area); background_buffer=mem_alloc(fb_pixelsize*arrow_area); new_background_buffer=mem_alloc(fb_pixelsize*arrow_area); background_x=mouse_x=fb_xsize>>1; background_y=mouse_y=fb_ysize>>1; mouse_black=fb_driver.get_color(0); mouse_white=fb_driver.get_color(0xffffff); mouse_graphics_device=fb_driver.init_device(); virtual_devices[0] = NULL; global_mouse_hidden=1; last_mouse_buttons = B_MOVE; if (handle_fb_mouse()) { fb_driver.shutdown_device(mouse_graphics_device); mem_free(mouse_buffer); mem_free(background_buffer); mem_free(new_background_buffer); fb_shutdown_palette(); svgalib_free_trm(fb_kbd); shutdown_virtual_devices(); EINTRLOOP(rs, close(fb_handle)); fb_switch_shutdown(); if(fb_driver_param) { mem_free(fb_driver_param); fb_driver_param=NULL; } fb_show_cursor(); return stracpy(cast_uchar "Cannot open GPM mouse.\n"); } /* hide cursor */ if (border_left | border_top | border_right | border_bottom) fb_clear_videoram(); show_mouse(); END_GR return NULL; }
/* save_pcx: * Writes a bitmap into a PCX file, using the specified palette (this * should be an array of at least 256 RGB structures). */ int save_pcx (FILE* f, MYBITMAP *bmp, RGB *pal) { FILE *f; PALETTE tmppal; int c; int x, y; int runcount; int depth, planes; char runchar; char ch; if (!pal) { get_palette(tmppal); pal = tmppal; } f = fp_fopen(filename, F_WRITE); if (!f) return *allegro_errno; depth = bitmap_color_depth(bmp); if (depth == 8) planes = 1; else planes = 3; fp_putc(10, f); /* manufacturer */ fp_putc(5, f); /* version */ fp_putc(1, f); /* run length encoding */ fp_putc(8, f); /* 8 bits per pixel */ fp_iputw(0, f); /* xmin */ fp_iputw(0, f); /* ymin */ fp_iputw(bmp->w-1, f); /* xmax */ fp_iputw(bmp->h-1, f); /* ymax */ fp_iputw(320, f); /* HDpi */ fp_iputw(200, f); /* VDpi */ for (c=0; c<16; c++) { fp_putc(_rgb_scale_6[pal[c].r], f); fp_putc(_rgb_scale_6[pal[c].g], f); fp_putc(_rgb_scale_6[pal[c].b], f); } fp_putc(0, f); /* reserved */ fp_putc(planes, f); /* one or three color planes */ fp_iputw(bmp->w, f); /* number of bytes per scanline */ fp_iputw(1, f); /* color palette */ fp_iputw(bmp->w, f); /* hscreen size */ fp_iputw(bmp->h, f); /* vscreen size */ for (c=0; c<54; c++) /* filler */ fp_putc(0, f); for (y=0; y<bmp->h; y++) { /* for each scanline... */ runcount = 0; runchar = 0; for (x=0; x<bmp->w*planes; x++) { /* for each pixel... */ if (depth == 8) { ch = getpixel(bmp, x, y); } else { if (x<bmp->w) { c = getpixel(bmp, x, y); ch = getr_depth(depth, c); } else if (x<bmp->w*2) { c = getpixel(bmp, x-bmp->w, y); ch = getg_depth(depth, c); } else { c = getpixel(bmp, x-bmp->w*2, y); ch = getb_depth(depth, c); } } if (runcount==0) { runcount = 1; runchar = ch; } else { if ((ch != runchar) || (runcount >= 0x3f)) { if ((runcount > 1) || ((runchar & 0xC0) == 0xC0)) fp_putc(0xC0 | runcount, f); fp_putc(runchar,f); runcount = 1; runchar = ch; } else runcount++; } } if ((runcount > 1) || ((runchar & 0xC0) == 0xC0)) fp_putc(0xC0 | runcount, f); fp_putc(runchar,f); } if (depth == 8) { /* 256 color palette */ fp_putc(12, f); for (c=0; c<256; c++) { fp_putc(_rgb_scale_6[pal[c].r], f); fp_putc(_rgb_scale_6[pal[c].g], f); fp_putc(_rgb_scale_6[pal[c].b], f); } } fp_fclose(f); return *allegro_errno; }
int menu_save_config(int type) { struct narray conf; arrayinit(&conf, sizeof(char *)); if (type & SAVE_CONFIG_TYPE_GEOMETRY) { menu_save_config_sub(MenuConfigGeometry, &conf); } if (type & SAVE_CONFIG_TYPE_CHILD_GEOMETRY) { menu_save_config_sub(MenuConfigChildGeometry, &conf); } if (type & SAVE_CONFIG_TYPE_VIEWER) { menu_save_config_sub(MenuConfigViewer, &conf); } if (type & SAVE_CONFIG_TYPE_EXTERNAL_VIEWER) { menu_save_config_sub(MenuConfigExtView, &conf); } if (type & SAVE_CONFIG_TYPE_TOGGLE_VIEW) { menu_save_config_sub(MenuConfigToggleView, &conf); } if (type & SAVE_CONFIG_TYPE_OTHERS) { #if ! GTK_CHECK_VERSION(3, 4, 0) get_palette(); #endif menu_save_config_sub(MenuConfigOthers, &conf); } if (type & SAVE_CONFIG_TYPE_EXTERNAL_DRIVER) { menu_save_config_sub(MenuConfigDriver, &conf); } if (type & SAVE_CONFIG_TYPE_ADDIN_SCRIPT) { menu_save_config_sub(MenuConfigScript, &conf); } if (type & SAVE_CONFIG_TYPE_MISC) { menu_save_config_sub(MenuConfigMisc, &conf); } replaceconfig(MGTKCONF, &conf); arraydel2(&conf); arrayinit(&conf, sizeof(char *)); if (type & SAVE_CONFIG_TYPE_EXTERNAL_DRIVER) { if (Menulocal.extprinterroot == NULL) { add_str_to_array(&conf, "ext_driver"); } } if (type & SAVE_CONFIG_TYPE_ADDIN_SCRIPT) { if (Menulocal.scriptroot == NULL) { add_str_to_array(&conf, "script"); } } removeconfig(MGTKCONF, &conf); arraydel2(&conf); return 0; }
void play_intro(void) { #define COL(index,red,green,blue) \ if ((index>=min) && (index<=max)) { \ pal[index].r = (red); \ pal[index].g = (green); \ pal[index].b = (blue); \ } #define FADE(speed) \ fade_from(source, pal, speed); \ get_palette(source) #define NORMAL() \ min = 0; \ max = PAL_SIZE-1 BITMAP *bg = (BITMAP *)datafile[MYLOGO_BMP].dat; PALETTE source, pal; int n, n2; int min, max; /* play the introduction theme */ qtetris_music(MUSIC_INTRO, FALSE); n = 0; NORMAL(); set_palette(black_palette); get_palette(source); get_palette(pal); /* DAC *********************************/ clear(virtual); blit(bg, virtual, 0, 0, QTETRIS_SCREEN_W/2 - bg->w/2, QTETRIS_SCREEN_H/2 - bg->h/2, bg->w, bg->h); qtetris_blit(virtual); FADE(1); /* David A. Capello */ /* fg */ min = 1; max = 28; for (n2=0, n=min; n<=max+2; n2=n, n+=2) { COL(n2, 0, 0, 0); COL(n, 32, 32, 63); COL(n+1, 63, 63, 63); FADE(32); } /* bg */ min = 32; max = 45; for (n=max; n>=min-4; n--) { NORMAL(); for (n2=1; n2<=28; n2+=2) { COL(n2+1, 63-(-63*(n-45)/(45-32+4)), 63-(-63*(n-45)/(45-32+4)), 63-(-63*(n-45)/(45-32+4))); COL(n2, -63*(n-45)/(45-32+4), 0, 0); } min = 32; max = 45; COL(n+4, 63, 63, 63); COL(n+2, 63, 0, 0); COL(n, 63, 63, 0); FADE(64); } /* Present */ NORMAL(); COL(253, 63, 63, 63); COL(254, 32, 32, 32); COL(255, 16, 16, 16); FADE(4); /* fin de la primer etapa **************/ fade_out(2); /* QUEEN LOGO **************************/ fade_out(2); clear(virtual); blit(datafile[QUEENLOG_BMP].dat, virtual, 0, 0, QTETRIS_SCREEN_W/2-((BITMAP *)datafile[QUEENLOG_BMP].dat)->w/2, QTETRIS_SCREEN_H/2-((BITMAP *)datafile[QUEENLOG_BMP].dat)->h/2, ((BITMAP *)datafile[QUEENLOG_BMP].dat)->w, ((BITMAP *)datafile[QUEENLOG_BMP].dat)->h); qtetris_blit(virtual); fade_in(datafile[PALETTE_BMP].dat, 1); get_palette(pal); get_palette(source); FADE(2); fade_out(2); /* TETRIS ******************************/ set_palette(black_palette); get_palette(source); get_palette(pal); NORMAL(); for (n=0; n<PAL_SIZE; n++) { COL(n, 63, 63, 63); } FADE(2); /* mainscreen */ clear(virtual); drawing_mode(DRAW_MODE_COPY_PATTERN, datafile[TETRISBG_BMP].dat, 0, 0); rectfill(virtual, 0, 0, QTETRIS_SCREEN_W, QTETRIS_SCREEN_H, -1); color_map = shadow_map; drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); draw_trans_sprite(virtual, datafile[TETRIS_BMP].dat, QTETRIS_SCREEN_W/2 - ((BITMAP *)datafile[TETRIS_BMP].dat)->w/2 + 6, QTETRIS_SCREEN_H/2 - ((BITMAP *)datafile[TETRIS_BMP].dat)->h/2 + 12); solid_mode(); draw_sprite(virtual, datafile[TETRIS_BMP].dat, QTETRIS_SCREEN_W/2 - ((BITMAP *)datafile[TETRIS_BMP].dat)->w/2, QTETRIS_SCREEN_H/2 - ((BITMAP *)datafile[TETRIS_BMP].dat)->h/2); qtetris_blit(virtual); for (n=15; n<112; n++) { COL(n, 0, 0, 0); } FADE(2); FADE(2); fade_from(pal, datafile[PALETTE_BMP].dat, 2); }
void Actor::run (Audio const& audio) { visual_return_if_fail (m_impl->video); auto actor_plugin = m_impl->get_actor_plugin (); if (!actor_plugin) { visual_log (VISUAL_LOG_ERROR, "The given actor does not reference any actor plugin"); return; } auto plugin = get_plugin (); /* Songinfo handling */ if (!visual_songinfo_compare (&m_impl->songcompare, actor_plugin->songinfo) || m_impl->songcompare.get_elapsed () != actor_plugin->songinfo->get_elapsed ()) { actor_plugin->songinfo->mark (); visual_event_queue_add (visual_plugin_get_event_queue (plugin), visual_event_new_newsong (actor_plugin->songinfo)); visual_songinfo_copy (&m_impl->songcompare, actor_plugin->songinfo); } // Get plugin to process all events visual_plugin_events_pump (m_impl->plugin); auto const& video = m_impl->video; auto const& to_convert = m_impl->to_convert; auto const& to_scale = m_impl->to_scale; if (video->get_depth () != VISUAL_VIDEO_DEPTH_GL) { auto palette = get_palette (); if (to_convert) { // Have depth conversion // Setup any palette if (palette) { to_convert->set_palette (*palette); } // Render first actor_plugin->render (m_impl->plugin, to_convert.get (), const_cast<Audio*> (&audio)); if (to_scale) { // Convert depth, then scale to_scale->convert_depth (to_convert); video->scale (to_scale, VISUAL_VIDEO_SCALE_NEAREST); } else { // Convert depth only video->convert_depth (to_convert); } } else { // No depth conversion if (to_scale) { // Setup any palette if (palette) { to_scale->set_palette (*palette); } // Render, then scale actor_plugin->render (m_impl->plugin, to_scale.get (), const_cast<Audio*> (&audio)); video->scale (to_scale, VISUAL_VIDEO_SCALE_NEAREST); } else { // Setup any palette if (palette) { video->set_palette (*palette); } // Render directly to video target actor_plugin->render (m_impl->plugin, video.get (), const_cast<Audio*> (&audio)); } } } else { // Render directly to video target (OpenGL) actor_plugin->render (m_impl->plugin, video.get (), const_cast<Audio*> (&audio)); } }
/* what a pointless way to spend my Sunday afternoon :-) */ static int worms() { #define MAX_SIZE 65536 int *xpos = malloc(sizeof(int)*MAX_SIZE); int *ypos = malloc(sizeof(int)*MAX_SIZE); int head, tail, dir, dead, quit, score, counter; int tx, ty, x, y, i, c1, c2, c3; again: head = 0; tail = 0; dir = 0; dead = FALSE; quit = FALSE; score = 0; counter = 0; tx = -100; ty = -100; show_mouse(NULL); if (bitmap_color_depth(screen) <= 8) { PALETTE pal; get_palette(pal); pal[0].r = 0; pal[0].g = 0; pal[0].b = 0; pal[1].r = 31; pal[1].g = 31; pal[1].b = 31; pal[254].r = 31; pal[254].g = 31; pal[254].b = 31; pal[255].r = 63; pal[255].g = 63; pal[255].b = 63; set_palette(pal); c1 = 0; c2 = 1; c3 = 255; } else { c1 = gui_fg_color; c2 = gui_mg_color; c3 = gui_bg_color; } clear_to_color(screen, c1); xor_mode(TRUE); xpos[0] = SCREEN_W/2; ypos[0] = SCREEN_H/2; putpixel(screen, xpos[0], ypos[0], c3); while ((!dead) && (!quit)) { x = xpos[head]; y = ypos[head]; switch (dir) { case 0: x++; break; case 1: y++; break; case 2: x--; break; case 3: y--; break; } if (x >= SCREEN_W) x -= SCREEN_W; else if (x < 0) x += SCREEN_W; if (y >= SCREEN_H) y -= SCREEN_H; else if (y < 0) y += SCREEN_H; head++; if (head >= MAX_SIZE) head = 0; xpos[head] = x; ypos[head] = y; counter++; if (counter & 15) { putpixel(screen, xpos[tail], ypos[tail], c3); tail++; if (tail >= MAX_SIZE) tail = 0; } i = tail; while (i != head) { if ((x == xpos[i]) && (y == ypos[i])) { dead = TRUE; break; } i++; if (i >= MAX_SIZE) i = 0; } if (!(counter % (1+(score+2)/3))) vsync(); putpixel(screen, x, y, c3); if ((tx < 0) || (ty < 0)) { do { tx = 16+random()%(SCREEN_W-32); ty = 16+random()%(SCREEN_H-32); } while ((ABS(x-tx)+ABS(y-ty)) < 64); circle(screen, tx, ty, 8, c2); circle(screen, tx, ty, 5, c2); circle(screen, tx, ty, 2, c2); } if ((ABS(x-tx)+ABS(y-ty)) < 9) { circle(screen, tx, ty, 8, c2); circle(screen, tx, ty, 5, c2); circle(screen, tx, ty, 2, c2); tx = -100; ty = -100; score++; } text_mode(c1); textprintf(screen, font, 0, 0, c2, "Score: %d", score); if (keypressed()) { switch (readkey()>>8) { case KEY_RIGHT: dir = 0; break; case KEY_DOWN: dir = 1; break; case KEY_LEFT: dir = 2; break; case KEY_UP: dir = 3; break; case KEY_ESC: quit = TRUE; break; } } } xor_mode(FALSE); clear_to_color(screen, gui_fg_color); set_palette(datedit_current_palette); do { } while ((key[KEY_ESC]) || (key[KEY_RIGHT]) || (key[KEY_LEFT]) || (key[KEY_UP]) || (key[KEY_DOWN])); clear_keybuf(); show_mouse(screen); if (dead) { char buf[64]; sprintf(buf, "Score: %d", score); if (alert(buf, NULL, NULL, "Play", "Quit", 'p', 'q') == 1) goto again; } free(xpos); free(ypos); return D_REDRAW; }
/*! \brief Play sample effect * * Play an effect... if possible/necessary. If the effect to * be played is the 'bad-move' effect, than do something visually * so that even if sound is off you know you did something bad :) * PH added explode effect. * * \param efc Effect to play (index in sfx[]) * \param panning Left/right pan - see Allegro's play_sample() */ void play_effect (int efc, int panning) { int a, s, xo = 1, yo = 1; static const int bx[8] = { -1, 0, 1, 0, -1, 0, 1, 0 }; static const int by[8] = { -1, 0, 1, 0, 1, 0, -1, 0 }; static const int sc[] = { 1, 2, 3, 5, 3, 3, 3, 2, 1 }; SAMPLE *samp; PALETTE whiteout, old; /* Patch provided by mattrope: */ /* sfx array is empty if sound is not initialized */ if (is_sound != 0) samp = (SAMPLE *) sfx[efc]->dat; else samp = NULL; /* PH not strictly needed but I added it */ switch (efc) { default: if (samp) play_sample (samp, gsvol, panning, 1000, 0); break; case SND_BAD: blit (double_buffer, fx_buffer, 0, 0, 0, 0, 352, 280); if (samp) play_sample (samp, gsvol, panning, 1000, 0); clear_bitmap (double_buffer); blit (fx_buffer, double_buffer, xofs, yofs, xofs, yofs, 320, 240); if (in_combat == 0) { xo = xofs; yo = yofs; } /* blit (fx_buffer, double_buffer, xo, yo, xo, yo, 320, 240); */ for (a = 0; a < 8; a++) { blit2screen (xo + bx[a], yo + by[a]); kq_wait (10); } blit (fx_buffer, double_buffer, 0, 0, 0, 0, 352, 280); break; case SND_EXPLODE: blit (double_buffer, fx_buffer, 0, 0, 0, 0, 352, 280); clear_bitmap (double_buffer); get_palette (old); for (a = 0; a < 256; ++a) { s = (old[a].r + old[a].g + old[a].b) > 40 ? 0 : 63; whiteout[a].r = whiteout[a].g = whiteout[a].b = s; } blit (fx_buffer, double_buffer, xofs, yofs, xofs, yofs, 320, 240); if (samp) { play_sample (samp, gsvol, panning, 1000, 0); } for (s = 0; s < (int) (sizeof (sc) / sizeof (*sc)); ++s) { if (s == 1) set_palette (whiteout); if (s == 6) set_palette (old); for (a = 0; a < 8; a++) { blit2screen (xofs + bx[a] * sc[s], yofs + by[a] * sc[s]); kq_wait (10); } } blit (fx_buffer, double_buffer, 0, 0, 0, 0, 352, 280); break; } }