void cave_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh) { int pri; int layers_ctrl = -1; int glob_flipx = READ_WORD(&cave_videoregs[0]) & 0x8000; int glob_flipy = READ_WORD(&cave_videoregs[2]) & 0x8000; tilemap_set_flip(ALL_TILEMAPS, (glob_flipx ? TILEMAP_FLIPX : 0) | (glob_flipy ? TILEMAP_FLIPY : 0) ); tilemap_set_enable( tilemap_0, READ_WORD(&cave_vctrl_0[4]) & 1 ); tilemap_set_scrollx(tilemap_0, 0, READ_WORD(&cave_vctrl_0[0]) ); tilemap_set_scrolly(tilemap_0, 0, READ_WORD(&cave_vctrl_0[2]) ); if (tilemap_1) { tilemap_set_enable( tilemap_1, READ_WORD(&cave_vctrl_1[4]) & 1 ); tilemap_set_scrollx(tilemap_1, 0, READ_WORD(&cave_vctrl_1[0]) ); tilemap_set_scrolly(tilemap_1, 0, READ_WORD(&cave_vctrl_1[2]) ); } if (tilemap_2) { tilemap_set_enable( tilemap_2, READ_WORD(&cave_vctrl_2[4]) & 1 ); tilemap_set_scrollx(tilemap_2, 0, READ_WORD(&cave_vctrl_2[0]) ); tilemap_set_scrolly(tilemap_2, 0, READ_WORD(&cave_vctrl_2[2]) ); } tilemap_update(ALL_TILEMAPS); palette_init_used_colors(); get_sprite_info(); sprite_update(); if (palette_recalc()) tilemap_mark_all_pixels_dirty(ALL_TILEMAPS); tilemap_render(ALL_TILEMAPS); /* Clear the background if at least one of layer 0's tile priorities is lacking */ if ((layers_ctrl & 0xf) != 0xf) osd_clearbitmap(Machine->scrbitmap); /* Pen 0 of layer 0's tiles (any priority) goes below anything else */ for ( pri = 0; pri < 4; pri++ ) if ((layers_ctrl&(1<<(pri+0)))&&tilemap_0) tilemap_draw(bitmap, tilemap_0, TILEMAP_IGNORE_TRANSPARENCY | pri); /* Draw the rest with transparency */ for ( pri = 0; pri < 4; pri++ ) { if ((layers_ctrl&(1<<(pri+12)))) sprite_draw(sprite_list, pri); if ((layers_ctrl&(1<<(pri+0)))&&tilemap_0) tilemap_draw(bitmap, tilemap_0, pri); if ((layers_ctrl&(1<<(pri+4)))&&tilemap_1) tilemap_draw(bitmap, tilemap_1, pri); if ((layers_ctrl&(1<<(pri+8)))&&tilemap_2) tilemap_draw(bitmap, tilemap_2, pri); } }
int updatescreen(void) { /* update sound */ sound_update(); if (osd_skip_this_frame() == 0) { profiler_mark(PROFILER_VIDEO); if (need_to_clear_bitmap) { osd_clearbitmap(real_scrbitmap); need_to_clear_bitmap = 0; } draw_screen(bitmap_dirty); /* update screen */ bitmap_dirty = 0; profiler_mark(PROFILER_END); } /* the user interface must be called between vh_update() and osd_update_video_and_audio(), */ /* to allow it to overlay things on the game display. We must call it even */ /* if the frame is skipped, to keep a consistent timing. */ if (handle_user_interface(real_scrbitmap)) /* quit if the user asked to */ return 1; update_video_and_audio(); if (drv->vh_eof_callback) (*drv->vh_eof_callback)(); return 0; }
struct osd_bitmap *osd_alloc_bitmap(int width,int height,int depth) { struct osd_bitmap *bitmap; if ((bitmap = (struct osd_bitmap *)malloc(sizeof(struct osd_bitmap))) != 0) { int i,rowlen,rdwidth; unsigned char *bm; if (depth != 8 && depth != 16) depth = 8; bitmap->depth = depth; bitmap->width = width; bitmap->height = height; rdwidth = (width + 7) & ~7; /* round width to a quadword */ if (depth == 16) rowlen = 2 * (rdwidth + 2 * safety) * sizeof(unsigned char); else rowlen = (rdwidth + 2 * safety) * sizeof(unsigned char); if ((bm = (unsigned char*)malloc((height + 2 * safety) * rowlen)) == 0) { free(bitmap); return 0; } /* clear ALL bitmap, including safety area, to avoid garbage on right */ /* side of screen is width is not a multiple of 4 */ memset(bm,0,(height + 2 * safety) * rowlen); if ((bitmap->line = (unsigned char**)malloc((height + 2 * safety) * sizeof(unsigned char *))) == 0) { free(bm); free(bitmap); return 0; } for (i = 0;i < height + 2 * safety;i++) { if (depth == 16) bitmap->line[i] = &bm[i * rowlen + 2*safety]; else bitmap->line[i] = &bm[i * rowlen + safety]; } bitmap->line += safety; bitmap->_private = bm; osd_clearbitmap(bitmap); } mybitmap = bitmap; return bitmap; }
void relief_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh) { int i; #if DEBUG_VIDEO debug(); #endif /* update the palette */ if (update_palette()) { memset(atarigen_pf_dirty, 1, atarigen_playfieldram_size / 2); memset(atarigen_pf2_dirty, 1, atarigen_playfield2ram_size / 2); } /* set up the all-transparent overrender palette */ for (i = 0; i < 16; i++) atarigen_overrender_colortable[i] = palette_transparent_pen; /* render the playfield */ memset(atarigen_pf_visit, 0, 64*64); #if DEBUG_VIDEO if (show_colors == 2) osd_clearbitmap(bitmap); else #endif atarigen_pf_process(pf_render_callback, bitmap, &Machine->drv->visible_area); /* render the playfield */ memset(atarigen_pf2_visit, 0, 64*64); #if DEBUG_VIDEO if (show_colors != 1) #endif atarigen_pf2_process(pf2_render_callback, bitmap, &Machine->drv->visible_area); /* render the motion objects */ atarigen_mo_process(mo_render_callback, bitmap); /* update onscreen messages */ atarigen_update_messages(); }
/* Update the display. */ void osd_update_video_and_audio(struct osd_bitmap *bitmap) { static const int waittable[FRAMESKIP_LEVELS][FRAMESKIP_LEVELS] = { { 1,1,1,1,1,1,1,1,1,1,1,1 }, { 2,1,1,1,1,1,1,1,1,1,1,0 }, { 2,1,1,1,1,0,2,1,1,1,1,0 }, { 2,1,1,0,2,1,1,0,2,1,1,0 }, { 2,1,0,2,1,0,2,1,0,2,1,0 }, { 2,0,2,1,0,2,0,2,1,0,2,0 }, { 2,0,2,0,2,0,2,0,2,0,2,0 }, { 2,0,2,0,0,3,0,2,0,0,3,0 }, { 3,0,0,3,0,0,3,0,0,3,0,0 }, { 4,0,0,0,4,0,0,0,4,0,0,0 }, { 6,0,0,0,0,0,6,0,0,0,0,0 }, {12,0,0,0,0,0,0,0,0,0,0,0 } }; int i; static int showfps,showfpstemp; TICKER curr; static TICKER prev_measure=0,this_frame_base,prev; static int speed = 100; static int vups,vfcount; int have_to_clear_bitmap = 0; if (prev_measure==0) { /* first time through, initialize timer */ prev_measure = ticker() - FRAMESKIP_LEVELS * TICKS_PER_SEC/video_fps; } if (frameskip_counter == 0) this_frame_base = prev_measure + FRAMESKIP_LEVELS * TICKS_PER_SEC/video_fps; /* update audio */ msdos_update_audio(); if (osd_skip_this_frame() == 0) { if (showfpstemp) { showfpstemp--; if (showfps == 0 && showfpstemp == 0) { have_to_clear_bitmap = 1; } } if (input_ui_pressed(IPT_UI_SHOW_FPS)) { if (showfpstemp) { showfpstemp = 0; have_to_clear_bitmap = 1; } else { showfps ^= 1; if (showfps == 0) { have_to_clear_bitmap = 1; } } } /* now wait until it's time to update the screen */ if (throttle) { profiler_mark(PROFILER_IDLE); if (video_sync) { static TICKER last; do { vsync(); curr = ticker(); } while (TICKS_PER_SEC / (curr - last) > video_fps * 11 /10); last = curr; } else { TICKER target; /* wait for video sync but use normal throttling */ if (wait_vsync) vsync(); curr = ticker(); target = this_frame_base + frameskip_counter * TICKS_PER_SEC/video_fps; if ((curr < target) && (target-curr<TICKS_PER_SEC)) { do { #ifdef WIZ spend_cycles(1024); // WIZ #endif curr = ticker(); } while ((curr < target) && (target-curr<TICKS_PER_SEC)); } } profiler_mark(PROFILER_END); } else curr = ticker(); if (frameskip_counter == 0) { int divdr; divdr = video_fps * (curr - prev_measure) / (100 * FRAMESKIP_LEVELS); if (divdr==0) divdr=1; speed = (TICKS_PER_SEC + divdr/2) / divdr; prev_measure = curr; } prev = curr; vfcount += waittable[frameskip][frameskip_counter]; if (vfcount >= video_fps) { extern int vector_updates; /* avgdvg_go_w()'s per Mame frame, should be 1 */ vfcount = 0; vups = vector_updates; vector_updates = 0; } if (showfps || showfpstemp) { int fps; char buf[30]; int divdr; divdr = 100 * FRAMESKIP_LEVELS; fps = (video_fps * (FRAMESKIP_LEVELS - frameskip) * speed + (divdr / 2)) / divdr; sprintf(buf,"%s%2d%4d%%%4d/%d fps",autoframeskip?"auto":"fskp",frameskip,speed,fps,(int)(video_fps+0.5)); ui_text(bitmap,buf,Machine->uiwidth-strlen(buf)*Machine->uifontwidth,0); if (vector_game) { sprintf(buf," %d vector updates",vups); ui_text(bitmap,buf,Machine->uiwidth-strlen(buf)*Machine->uifontwidth,Machine->uifontheight); } } if (bitmap->depth == 8) { if (dirty_bright) { dirty_bright = 0; for (i = 0;i < 256;i++) { float rate = brightness * brightness_paused_adjust * pow(i / 255.0, 1 / osd_gamma_correction) / 100; bright_lookup[i] = 255 * rate + 0.5; } } if (dirtypalette) { dirtypalette = 0; for (i = 0;i < screen_colors;i++) { if (dirtycolor[i]) { unsigned char r,g,b; dirtycolor[i] = 0; r = current_palette[3*i+0]; g = current_palette[3*i+1]; b = current_palette[3*i+2]; if (i != Machine->uifont->colortable[1]) /* don't adjust the user interface text */ { r = bright_lookup[r]; g = bright_lookup[g]; b = bright_lookup[b]; } wiz_video_color8(i,r,g,b); } } wiz_video_setpalette(); } } else { if (dirty_bright) { dirty_bright = 0; for (i = 0;i < 256;i++) { float rate = brightness * brightness_paused_adjust * pow(i / 255.0, 1 / osd_gamma_correction) / 100; bright_lookup[i] = 255 * rate + 0.5; } } if (dirtypalette) { if (use_dirty) init_dirty(1); /* have to redraw the whole screen */ dirtypalette = 0; for (i = 0;i < screen_colors;i++) { if (dirtycolor[i]) { int r,g,b; dirtycolor[i] = 0; r = current_palette[3*i+0]; g = current_palette[3*i+1]; b = current_palette[3*i+2]; if (i != Machine->uifont->colortable[1]) /* don't adjust the user interface text */ { r = bright_lookup[r]; g = bright_lookup[g]; b = bright_lookup[b]; } palette_16bit_lookup[i] = makecol(r,g,b); } } } } /* copy the bitmap to screen memory */ profiler_mark(PROFILER_BLIT); update_screen(bitmap); profiler_mark(PROFILER_END); if (have_to_clear_bitmap) osd_clearbitmap(bitmap); if (use_dirty) { if (!vector_game) swap_dirty(); init_dirty(0); } if (have_to_clear_bitmap) osd_clearbitmap(bitmap); if (throttle && autoframeskip && frameskip_counter == 0) { static int frameskipadjust; int adjspeed; /* adjust speed to video refresh rate if vsync is on */ adjspeed = speed * video_fps / vsync_frame_rate; if (adjspeed >= 92) { frameskipadjust++; if (frameskipadjust >= 3) { frameskipadjust = 0; if (frameskip > 0) frameskip--; } } else { if (adjspeed < 80) frameskipadjust -= (90 - adjspeed) / 5; else { /* don't push frameskip too far if we are close to 100% speed */ if (frameskip < 8) frameskipadjust--; } while (frameskipadjust <= -2) { frameskipadjust += 2; #ifdef WIZ if (frameskip < 7) frameskip++; #else if (frameskip < FRAMESKIP_LEVELS-1) frameskip++; #endif } } } } /* Check for PGUP, PGDN and pan screen */ pan_display(); if (input_ui_pressed(IPT_UI_FRAMESKIP_INC)) { if (autoframeskip) { autoframeskip = 0; frameskip = 0; } else { if (frameskip == FRAMESKIP_LEVELS-1) { frameskip = 0; autoframeskip = 1; } else frameskip++; } if (showfps == 0) showfpstemp = 2*video_fps; } if (input_ui_pressed(IPT_UI_FRAMESKIP_DEC)) { if (autoframeskip) { autoframeskip = 0; frameskip = FRAMESKIP_LEVELS-1; } else { if (frameskip == 0) autoframeskip = 1; else frameskip--; } if (showfps == 0) showfpstemp = 2*video_fps; } if (input_ui_pressed(IPT_UI_THROTTLE)) { throttle ^= 1; } frameskip_counter = (frameskip_counter + 1) % FRAMESKIP_LEVELS; }