--- uae/src/custom.c 2018/04/24 16:42:15 1.1.1.4 +++ uae/src/custom.c 2018/04/24 16:44:56 1.1.1.6 @@ -38,6 +38,9 @@ #include "picasso96.h" #include "drawing.h" +static unsigned int n_consecutive_skipped = 0; +static unsigned int total_skipped = 0; + #define SPRITE_COLLISIONS /* Mouse and joystick emulation */ @@ -89,8 +92,8 @@ static int spron[8]; static uaecptr sprpt[8]; static int sprxpos[8], sprvstart[8], sprvstop[8]; -static uae_u32 bpl1dat,bpl2dat,bpl3dat,bpl4dat,bpl5dat,bpl6dat,bpl7dat,bpl8dat; -static uae_s16 bpl1mod,bpl2mod; +static uae_u32 bpl1dat, bpl2dat, bpl3dat, bpl4dat, bpl5dat, bpl6dat, bpl7dat, bpl8dat; +static uae_s16 bpl1mod, bpl2mod; static uaecptr bplpt[8]; #ifndef SMART_UPDATE @@ -100,7 +103,7 @@ static char *real_bplpt[8]; /*static int blitcount[256]; blitter debug */ static struct color_entry current_colors; -static unsigned int bplcon0,bplcon1,bplcon2,bplcon3,bplcon4; +static unsigned int bplcon0, bplcon1, bplcon2, bplcon3, bplcon4; static int nr_planes_from_bplcon0, corrected_nr_planes_from_bplcon0; static unsigned int diwstrt, diwstop, diwhigh; static int diwhigh_written; @@ -109,7 +112,7 @@ static unsigned int sprdata[8], sprdatb[ static int sprarmed[8], sprite_last_drawn_at[8]; static int last_sprite_point, nr_armed; static uae_u32 dskpt; -static uae_u16 dsklen,dsksync; +static uae_u16 dsklen, dsksync; static int dsklength; /* The display and data fetch windows */ @@ -119,8 +122,8 @@ enum diw_states DIW_waiting_start, DIW_waiting_stop }; -static int plffirstline,plflastline,plfstrt,plfstop,plflinelen; -int diwfirstword,diwlastword; +static int plffirstline, plflastline, plfstrt, plfstop, plflinelen; +int diwfirstword, diwlastword; static enum diw_states diwstate, hdiwstate; /* Sprite collisions */ @@ -157,7 +160,7 @@ int dskdmaen; /* used in cia.c */ */ /* Used also by bebox.cpp */ -unsigned long int msecs = 0, frametime = 0, timeframes = 0; +unsigned long int msecs = 0, frametime = 0, lastframetime = 0, timeframes = 0; static unsigned long int seconds_base; int bogusframe; @@ -204,12 +207,13 @@ static int color_src_match, color_dest_m * have to be remembered. */ static int decided_bpl1mod, decided_bpl2mod, decided_nr_planes, decided_hires; -char line_changed[2 * (maxvpos+1)]; +static char thisline_changed; + #ifdef SMART_UPDATE -#define MARK_LINE_CHANGED(l) do { line_changed[l] = 1; } while (0) +#define MARK_LINE_CHANGED do { thisline_changed = 1; } while (0) #else -#define MARK_LINE_CHANGED(l) do { } while (0) +#define MARK_LINE_CHANGED do { ; } while (0) #endif static struct decision thisline_decision; @@ -252,8 +256,10 @@ void check_prefs_changed_custom (void) { currprefs.framerate = changed_prefs.framerate; /* Not really the right place... */ - if (currprefs.fake_joystick != changed_prefs.fake_joystick) { - currprefs.fake_joystick = changed_prefs.fake_joystick; + if (currprefs.jport0 != changed_prefs.jport0 + || currprefs.jport1 != changed_prefs.jport1) { + currprefs.jport0 = changed_prefs.jport0; + currprefs.jport1 = changed_prefs.jport1; joystick_setting_changed (); } currprefs.immediate_blits = changed_prefs.immediate_blits; @@ -263,11 +269,10 @@ void check_prefs_changed_custom (void) static __inline__ void setclr (uae_u16 *p, uae_u16 val) { - if (val & 0x8000) { + if (val & 0x8000) *p |= val & 0x7FFF; - } else { + else *p &= ~val; - } } __inline__ int current_hpos (void) @@ -286,7 +291,7 @@ static __inline__ uae_u8 *pfield_xlatept return chipmem_bank.xlateaddr (plpt); } -static __inline__ void docols(struct color_entry *colentry) +static __inline__ void docols (struct color_entry *colentry) { #if AGA_CHIPSET == 0 int i; @@ -341,13 +346,11 @@ static void remember_ctable (void) color_src_match = oldctable; color_dest_match = remembered_color_entry; } - if (changed) { - line_changed[next_lineno] = 1; - } + thisline_changed |= changed; } else { /* We know the result of the comparison */ if (color_compare_result) - line_changed[next_lineno] = 1; + thisline_changed = 1; } } @@ -370,7 +373,7 @@ static void decide_diw (int hpos) * some programs change them after DDF start but before DIW start. */ thisline_decision.bplcon1 = bplcon1; if (thisline_decision.diwfirstword != line_decisions[next_lineno].diwfirstword) - MARK_LINE_CHANGED (next_lineno); + MARK_LINE_CHANGED; thisline_decision.diwlastword = -1; } if (hdiwstate == DIW_waiting_stop && thisline_decision.diwlastword == -1 @@ -379,7 +382,7 @@ static void decide_diw (int hpos) thisline_decision.diwlastword = diwlastword; hdiwstate = DIW_waiting_start; if (thisline_decision.diwlastword != line_decisions[next_lineno].diwlastword) - MARK_LINE_CHANGED (next_lineno); + MARK_LINE_CHANGED; } } @@ -414,7 +417,7 @@ static __inline__ void decide_as_playfie #endif ) #endif /* SMART_UPDATE */ - line_changed[next_lineno] = 1; + thisline_changed = 1; } /* Called when we already decided whether the line is playfield or border, @@ -485,7 +488,7 @@ static __inline__ void post_decide_line { if (thisline_decision.which == 1 && hpos < thisline_decision.plfstrt + thisline_decision.plflinelen - && ((bplcon0 & 0x7000) == 0 || !dmaen (DMA_BITPLANE))) + && (GET_PLANES (bplcon0) == 0 || !dmaen (DMA_BITPLANE))) { /* This is getting gross... */ thisline_decision.plflinelen = hpos - thisline_decision.plfstrt; @@ -498,7 +501,7 @@ static __inline__ void post_decide_line } if (diwstate == DIW_waiting_start - || (bplcon0 & 0x7000) == 0 + || GET_PLANES (bplcon0) == 0 || !dmaen (DMA_BITPLANE) || hpos >= thisline_decision.plfstrt + thisline_decision.plflinelen) return; @@ -510,10 +513,10 @@ static __inline__ void post_decide_line decided_hires = (bplcon0 & 0x8000) == 0x8000; init_broken_program (); decided_nr_planes = nr_planes_from_bplcon0; - thisline_decision.bplcon0 &= 0xFFF; - thisline_decision.bplcon0 |= bplcon0 & 0xF000; + thisline_decision.bplcon0 &= 0xFEF; + thisline_decision.bplcon0 |= bplcon0 & 0xF010; adjust_broken_program (hpos); - MARK_LINE_CHANGED (next_lineno); /* Play safe. */ + MARK_LINE_CHANGED; /* Play safe. */ return; } @@ -532,10 +535,10 @@ static __inline__ void post_decide_line init_broken_program (); decided_nr_planes = nr_planes_from_bplcon0; - thisline_decision.bplcon0 &= 0xFFF; - thisline_decision.bplcon0 |= bplcon0 & 0xF000; + thisline_decision.bplcon0 &= 0xFEF; + thisline_decision.bplcon0 |= bplcon0 & 0xF010; - MARK_LINE_CHANGED (next_lineno); /* Play safe. */ + MARK_LINE_CHANGED; /* Play safe. */ decide_as_playfield (plfstrt, plflinelen); adjust_broken_program (hpos); } @@ -642,7 +645,7 @@ static void record_color_change (int hpo if (regno == 0 && thisline_decision.color0 == 0xFFFFFFFFul && thisline_decision.diwfirstword < 0) { thisline_decision.color0 = current_colors.color_regs[0]; if (line_decisions[next_lineno].color0 != value) - line_changed[next_lineno] = 1; + thisline_changed = 1; } /* Anything else gets recorded in the color_changes table. */ #ifdef OS_WITHOUT_MEMORY_MANAGEMENT @@ -726,11 +729,11 @@ static void decide_plane (int hpos) real_ptr = pfield_xlateptr(0, 0); #ifdef SMART_UPDATE #if 1 - if (line_changed[next_lineno]) + if (thisline_changed) memcpy (dataptr, real_ptr, bytecount); else #endif - line_changed[next_lineno] |= memcmpy (dataptr, real_ptr, bytecount); + thisline_changed |= memcmpy (dataptr, real_ptr, bytecount); #else real_bplpt[i] = real_ptr; #endif @@ -746,8 +749,8 @@ static void decide_plane (int hpos) if (real_ptr == NULL) real_ptr = pfield_xlateptr(0, 0); #ifdef SMART_UPDATE - if (!line_changed[next_lineno]) - line_changed[next_lineno] |= memcmpy (dataptr, real_ptr, bytecount); + if (!thisline_changed) + thisline_changed |= memcmpy (dataptr, real_ptr, bytecount); else memcpy (dataptr, real_ptr, bytecount); #else @@ -924,17 +927,17 @@ static void finish_decisions (void) if (hdiwstate == DIW_waiting_stop) { thisline_decision.diwlastword = max_diwlastword; if (thisline_decision.diwlastword != line_decisions[next_lineno].diwlastword) - MARK_LINE_CHANGED (next_lineno); + MARK_LINE_CHANGED; } if (line_decisions[next_lineno].which != thisline_decision.which) - line_changed[next_lineno] = 1; + thisline_changed = 1; decide_plane (hpos); dip = curr_drawinfo + next_lineno; dip_old = prev_drawinfo + next_lineno; dp = line_decisions + next_lineno; - changed = line_changed[next_lineno]; + changed = thisline_changed; if (thisline_decision.which == 1) { record_diw_line (diwfirstword, diwlastword); @@ -979,7 +982,7 @@ static void finish_decisions (void) changed = 1; if (changed) { - line_changed[next_lineno] = 1; + thisline_changed = 1; *dp = thisline_decision; } else /* The only one that may differ: */ @@ -1002,12 +1005,12 @@ static void reset_decisions (void) if (hdiwstate == DIW_waiting_stop) { thisline_decision.diwfirstword = PIXEL_XPOS (DISPLAY_LEFT_SHIFT/2); if (thisline_decision.diwfirstword != line_decisions[next_lineno].diwfirstword) - MARK_LINE_CHANGED (next_lineno); + MARK_LINE_CHANGED; } thisline_decision.ctable = -1; thisline_decision.color0 = 0xFFFFFFFFul; - line_changed[next_lineno] = 0; + thisline_changed = 0; curr_drawinfo[next_lineno].first_color_change = next_color_change; curr_drawinfo[next_lineno].first_delay_change = next_delay_change; curr_drawinfo[next_lineno].first_sprite_draw = next_sprite_draw; @@ -1468,8 +1471,14 @@ static void BPLCON0 (int hpos, uae_u16 v return; decide_line (hpos); bplcon0 = v; - nr_planes_from_bplcon0 = (bplcon0 >> 12) & 7; - corrected_nr_planes_from_bplcon0 = ((bplcon0 >> 12) & 7) << (bplcon0 & 0x8000 ? 1 : 0); + nr_planes_from_bplcon0 = GET_PLANES (v); +#if AGA_CHIPSET != 0 + /* It's not clear how the copper timings are affected by the number + * of bitplanes on AGA machines */ + corrected_nr_planes_from_bplcon0 = 4; +#else + corrected_nr_planes_from_bplcon0 = nr_planes_from_bplcon0 << (bplcon0 & 0x8000 ? 1 : 0); +#endif post_decide_line (hpos); } static __inline__ void BPLCON1 (int hpos, uae_u16 v) @@ -1524,6 +1533,8 @@ static __inline__ void BPL3DAT (uae_u16 static __inline__ void BPL4DAT (uae_u16 v) { bpl4dat = v; } static __inline__ void BPL5DAT (uae_u16 v) { bpl5dat = v; } static __inline__ void BPL6DAT (uae_u16 v) { bpl6dat = v; } +static __inline__ void BPL7DAT (uae_u16 v) { bpl7dat = v; } +static __inline__ void BPL8DAT (uae_u16 v) { bpl8dat = v; } static void DIWSTRT (int hpos, uae_u16 v) { @@ -1557,7 +1568,7 @@ static void DIWHIGH (int hpos, uae_u16 v static void DDFSTRT (int hpos, uae_u16 v) { - v &= 0xFF; + v &= AGA_CHIPSET ? 0x1FF : 0xFF; if (ddfstrt == v) return; decide_line (hpos); @@ -1566,7 +1577,7 @@ static void DDFSTRT (int hpos, uae_u16 v } static void DDFSTOP (int hpos, uae_u16 v) { - v &= 0xFF; + v &= AGA_CHIPSET ? 0x1FF : 0xFF; if (ddfstop == v) return; decide_line (hpos); @@ -1649,7 +1660,7 @@ static void BLTSIZH (uae_u16 v) if (!blt_info.vblitsize) blt_info.vblitsize = 32768; if (!blt_info.hblitsize) blt_info.hblitsize = 0x800; bltstate = BLT_init; - do_blitter(); + do_blitter (); } static __inline__ void SPRxCTL_1 (uae_u16 v, int num) @@ -1738,9 +1749,9 @@ static void COLOR (int hpos, uae_u16 v, r = (v & 0xF00) >> 8; g = (v & 0xF0) >> 4; b = (v & 0xF) >> 0; - cr = color_regs[colreg] >> 16; - cg = (color_regs[colreg] >> 8) & 0xFF; - cb = color_regs[colreg] & 0xFF; + cr = current_colors.color_regs[colreg] >> 16; + cg = (current_colors.color_regs[colreg] >> 8) & 0xFF; + cb = current_colors.color_regs[colreg] & 0xFF; if (bplcon3 & 0x200) { cr &= 0xF0; cr |= r; @@ -1752,10 +1763,14 @@ static void COLOR (int hpos, uae_u16 v, cb = b + (b << 4); } cval = (cr << 16) | (cg << 8) | cb; - if (cval == color_regs[colreg]) + if (cval == current_colors.color_regs[colreg]) return; - color_regs[colreg] = cval; - pfield_may_need_update(1); + + /* Call this with the old table still intact. */ + record_color_change (hpos, colreg, v); + remembered_color_entry = -1; + current_colors.color_regs[colreg] = cval; +/* current_colors.acolors[colreg] = xcolors[v];*/ } #else { @@ -1840,18 +1855,18 @@ static uae_u16 POTGOR (void) uae_u16 v = (potgo_value | (potgo_value << 1)) & 0xAA00; v |= v >> 1; - if (JSEM_ISMOUSE (0, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (0, &currprefs)) { if (buttonstate[2]) v &= 0xFBFF; if (buttonstate[1]) v &= 0xFEFF; - } else if (JSEM_ISJOY0 (0, currprefs.fake_joystick) || JSEM_ISJOY1 (0, currprefs.fake_joystick)) { + } else if (JSEM_ISJOY0 (0, &currprefs) || JSEM_ISJOY1 (0, &currprefs)) { if (joy0button & 2) v &= 0xfbff; if (joy0button & 4) v &= 0xfeff; } - if (JSEM_ISJOY0 (1, currprefs.fake_joystick) || JSEM_ISJOY1 (1, currprefs.fake_joystick)) { + if (JSEM_ISJOY0 (1, &currprefs) || JSEM_ISJOY1 (1, &currprefs)) { if (joy1button & 2) v &= 0xbfff; if (joy1button & 4) v &= 0xefff; } @@ -1862,7 +1877,7 @@ static uae_u16 POTGOR (void) static uae_u16 POT0DAT (void) { static uae_u16 cnt = 0; - if (JSEM_ISMOUSE (0, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (0, &currprefs)) { if (buttonstate[2]) cnt = ((cnt + 1) & 0xFF) | (cnt & 0xFF00); if (buttonstate[1]) @@ -1873,7 +1888,7 @@ static uae_u16 POT0DAT (void) } static uae_u16 JOY0DAT (void) { - if (JSEM_ISMOUSE (0, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (0, &currprefs)) { do_mouse_hack (); return ((uae_u8)mouse_x) + ((uae_u16)mouse_y << 8); } @@ -1881,7 +1896,7 @@ static uae_u16 JOY0DAT (void) } static uae_u16 JOY1DAT (void) { - if (JSEM_ISMOUSE (1, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (1, &currprefs)) { do_mouse_hack (); return ((uae_u8)mouse_x) + ((uae_u16)mouse_y << 8); } @@ -1889,7 +1904,7 @@ static uae_u16 JOY1DAT (void) } static void JOYTEST (uae_u16 v) { - if (JSEM_ISMOUSE (0, currprefs.fake_joystick)) { + if (JSEM_ISMOUSE (0, &currprefs)) { mouse_x = v & 0xFC; mouse_y = (v >> 8) & 0xFC; } @@ -1938,6 +1953,10 @@ static __inline__ int copper_cant_read ( if (hpos >= ((maxhpos - 2) & ~1)) return 1; +#if AGA_CHIPSET != 0 + /* FIXME */ + return 0; +#else if (! copper_in_playfield (diw, hpos)) return 0; @@ -1947,6 +1966,7 @@ static __inline__ int copper_cant_read ( abort (); #endif return t; +#endif } static void update_copper_1 (int until_hpos) @@ -1992,7 +2012,7 @@ static void update_copper_1 (int until_h if (cop_state.do_move) { cop_state.do_move = 0; - if (cop_state.i1 < (copcon & 2 ? 0x40u : 0x80u)) { + if (cop_state.i1 < (copcon & 2 ? (AGA_CHIPSET ? 0 : 0x40u) : 0x80u)) { cop_state.state = COP_stop; break; } @@ -2184,11 +2204,11 @@ static void prepare_copper_1 (void) if (cst.do_move) { cst.do_move = 0; - if (cst.i1 < (copcon & 2 ? 0x40u : 0x80u)) { + if (cst.i1 < (copcon & 2 ? (AGA_CHIPSET ? 0 : 0x40u) : 0x80u)) { cst.state = COP_stop; eventtab[ev_copper].active = 0; return; - } else if (dangerous_reg (cst.i1)) { + } else if (dangerous_reg (cst.i1)) { eventtab[ev_copper].active = 1; eventtab[ev_copper].oldcycles = cycles; eventtab[ev_copper].evtime = cycles + cst.hpos - current_hpos () + (cst.vpos - cop_state.vpos) * maxhpos; @@ -2589,8 +2609,26 @@ static void vsync_handler (void) newtime = (tv.tv_sec-seconds_base) * 1000 + tv.tv_usec / 1000; if (!bogusframe) { - frametime += newtime - msecs; + lastframetime = newtime - msecs; + +#if 0 /* This doesn't appear to work too well yet... later. */ + if (n_consecutive_skipped > currprefs.sound_pri_cutoff + || lastframetime < currprefs.sound_pri_time) + { + n_consecutive_skipped = 0; + clear_inhibit_frame (IHF_SOUNDADJUST); + } else { + n_consecutive_skipped++; + set_inhibit_frame (IHF_SOUNDADJUST); + total_skipped++; + } +#endif + + frametime += lastframetime; timeframes++; + + if ((timeframes & 127) == 0) + gui_fps (1000 * timeframes / frametime); } msecs = newtime; bogusframe = 0; @@ -2608,7 +2646,7 @@ static void hsync_handler (void) finish_decisions (); do_modulos (current_hpos ()); - hsync_record_line_state (next_lineno, nextline_how); + hsync_record_line_state (next_lineno, nextline_how, thisline_changed); eventtab[ev_hsync].evtime += cycles - eventtab[ev_hsync].oldcycles; eventtab[ev_hsync].oldcycles = cycles; @@ -2656,7 +2694,7 @@ static void hsync_handler (void) nextline_how = nln_normal; if (currprefs.gfx_linedbl) { lineno *= 2; - nextline_how = nln_doubled; + nextline_how = currprefs.gfx_linedbl == 1 ? nln_doubled : nln_nblack; if (bplcon0 & 4) { if (!lof) { lineno++; @@ -2772,12 +2810,14 @@ void customreset (void) void dumpcustom (void) { - fprintf (stderr, "DMACON: %x INTENA: %x INTREQ: %x VPOS: %x HPOS: %x\n", DMACONR(), - (unsigned int)intena, (unsigned int)intreq, (unsigned int)vpos, (unsigned int)current_hpos()); - fprintf (stderr, "COP1LC: %08lx, COP2LC: %08lx\n", (unsigned long)cop1lc, (unsigned long)cop2lc); + write_log ("DMACON: %x INTENA: %x INTREQ: %x VPOS: %x HPOS: %x\n", DMACONR(), + (unsigned int)intena, (unsigned int)intreq, (unsigned int)vpos, (unsigned int)current_hpos()); + write_log ("COP1LC: %08lx, COP2LC: %08lx\n", (unsigned long)cop1lc, (unsigned long)cop2lc); if (timeframes) { - fprintf (stderr, "Average frame time: %d ms [frames: %d time: %d]\n", - frametime/timeframes, timeframes, frametime); + write_log ("Average frame time: %d ms [frames: %d time: %d]\n", + frametime / timeframes, timeframes, frametime); + if (total_skipped) + write_log ("Skipped frames: %d\n", total_skipped); } dump_audio_bench (); /*for (i=0; i<256; i++) if (blitcount[i]) fprintf (stderr, "minterm %x = %d\n",i,blitcount[i]); blitter debug */ @@ -2999,6 +3039,10 @@ void REGPARAM2 custom_wput_1 (int hpos, case 0x0F2: BPLPTL (hpos, value, 4); break; case 0x0F4: BPLPTH (hpos, value, 5); break; case 0x0F6: BPLPTL (hpos, value, 5); break; + case 0x0F8: BPLPTH (hpos, value, 6); break; + case 0x0FA: BPLPTL (hpos, value, 6); break; + case 0x0FC: BPLPTH (hpos, value, 7); break; + case 0x0FE: BPLPTL (hpos, value, 7); break; case 0x100: BPLCON0 (hpos, value); break; case 0x102: BPLCON1 (hpos, value); break; @@ -3014,6 +3058,8 @@ void REGPARAM2 custom_wput_1 (int hpos, case 0x116: BPL4DAT (value); break; case 0x118: BPL5DAT (value); break; case 0x11A: BPL6DAT (value); break; + case 0x11C: BPL7DAT (value); break; + case 0x11E: BPL8DAT (value); break; case 0x180: case 0x182: case 0x184: case 0x186: case 0x188: case 0x18A: case 0x18C: case 0x18E: case 0x190: case 0x192: case 0x194: case 0x196: @@ -3059,7 +3105,7 @@ void REGPARAM2 custom_wput_1 (int hpos, #endif #if AGA_CHIPSET == 1 case 0x10C: BPLCON4 (hpos, value); break; - case 0x1FC: fmode = value; break; + case 0x1FC: fmode = value; calcdiw (); break; #endif } }